qflib 0.98.1

de.qfs.lib.tree
Class IndexBasedTreeAdapter

java.lang.Object
  |
  +--de.qfs.lib.tree.IndexBasedTreeAdapter
All Implemented Interfaces:
TreeAdapter
Direct Known Subclasses:
AWTTreeAdapter, OptionGroupTreeAdapter, TreeOptionGroup.Tree

public abstract class IndexBasedTreeAdapter
extends java.lang.Object
implements TreeAdapter

This abstract base class for an index based TreeAdapter implements the link and enumeration based methods in terms of the index based ones, so it leaves only the bare minimum to be implemented.

Since:
0.98.1
Version:
$Revision: 1.2 $
Author:
Gregor Schmid

Inner Class Summary
protected  class IndexBasedTreeAdapter.ChildEnumeration
          Helper class that enumerates the children of a node.
 
Constructor Summary
IndexBasedTreeAdapter()
           
 
Method Summary
 java.util.Enumeration getChildren(java.lang.Object parent)
          Get an Enumeration for the children of a node.
 java.lang.Object getFirstChildNode(java.lang.Object parent)
          Get the first child of a node.
 java.lang.Object getLastChildNode(java.lang.Object parent)
          Get the last child of a node.
 java.lang.Object getNextSibling(java.lang.Object node)
          Get the next sibling of a node.
 java.lang.Object getPreviousSibling(java.lang.Object node)
          Get the previous sibling of a node.
 boolean isEnumerationBased()
          Query whether the TreeAdapter implementation supports enumeration based child access efficiently.
 boolean isIndexBased()
          Query whether the TreeAdapter implementation supports index based child access efficiently.
 boolean isLinkBased()
          Query whether the TreeAdapter implementation supports link based child access efficiently.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.qfs.lib.tree.TreeAdapter
getChildCount, getChildNode, getIndexOfChildNode, getParentNode, isLeaf
 

Constructor Detail

IndexBasedTreeAdapter

public IndexBasedTreeAdapter()
Method Detail

isIndexBased

public boolean isIndexBased()
Query whether the TreeAdapter implementation supports index based child access efficiently.

If the list of children of a node is implemented as a linked list for example, index based access is very inefficient, while an array based implementation should retrun true. The index based methods getChildCount, getChildNode and getIndexOfChildNode have to be implemented in any case.

Specified by:
isIndexBased in interface TreeAdapter
Returns:
True if index based access is efficient, false if it is inefficient.

isLinkBased

public boolean isLinkBased()
Query whether the TreeAdapter implementation supports link based child access efficiently.

If the list of children of a node is implemented as a linked list for example, link based access is very efficient, while an array based implementation should retrun false. The link based methods getFirstChildNode, getLastChildNode, getNextSibling and getPreviousSibling have to be implemented in any case.

Specified by:
isLinkBased in interface TreeAdapter
Returns:
True if link based access is efficient, false if it is inefficient.

getFirstChildNode

public java.lang.Object getFirstChildNode(java.lang.Object parent)
Get the first child of a node.
Specified by:
getFirstChildNode in interface TreeAdapter
Parameters:
parent - The node whose child to get.
Returns:
The first child of the parent or null if it doesn't have any children.

getLastChildNode

public java.lang.Object getLastChildNode(java.lang.Object parent)
Get the last child of a node.
Specified by:
getLastChildNode in interface TreeAdapter
Parameters:
parent - The node whose child to get.
Returns:
The last child of the parent or null if it doesn't have any children.

getPreviousSibling

public java.lang.Object getPreviousSibling(java.lang.Object node)
Get the previous sibling of a node.
Specified by:
getPreviousSibling in interface TreeAdapter
Parameters:
node - The node whose sibling to get.
Returns:
The previous sibling or null if the node doesn't have a parent or is the parent's first child.

getNextSibling

public java.lang.Object getNextSibling(java.lang.Object node)
Get the next sibling of a node.
Specified by:
getNextSibling in interface TreeAdapter
Parameters:
node - The node whose sibling to get.
Returns:
The next sibling or null if the node doesn't have a parent or is the parent's last child.

isEnumerationBased

public boolean isEnumerationBased()
Query whether the TreeAdapter implementation supports enumeration based child access efficiently.

This method should return true only if Enumeration based child access if more efficient than index or linked based access.

Specified by:
isEnumerationBased in interface TreeAdapter
Returns:
True if Enumeration based access is efficient, false if it is inefficient.

getChildren

public java.util.Enumeration getChildren(java.lang.Object parent)
Get an Enumeration for the children of a node. An implementation is free to always return null unless isEnumerationBased returns true.
Specified by:
getChildren in interface TreeAdapter
Parameters:
parent - The node whose children to get.
Returns:
An Enumeration for the children or null, if the node doesn't have any or Enumeration based access is not supported.

qflib 0.98.1