qflib 0.98.1

de.qfs.lib.tree
Interface TreeAdapter

All Known Subinterfaces:
MutableTreeAdapter
All Known Implementing Classes:
IndexBasedTreeAdapter

public interface TreeAdapter

With the help of this interface the methods of the TreeUtil class can be applied to every kind of tree structure without the need to change anything in the implementation of the structure itself (provided that the basic tree functionality is there).

A TreeAdapter can also be used to get different structural views of the same tree hierachy. An Example would be a DOM TreeAdapter that hides all non-Element nodes.

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

Method Summary
 int getChildCount(java.lang.Object parent)
          Get the number of children of a node.
 java.lang.Object getChildNode(java.lang.Object parent, int index)
          Get a child of a node.
 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.
 int getIndexOfChildNode(java.lang.Object parent, java.lang.Object child)
          Get the index of a child in a node's list of children.
 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 getParentNode(java.lang.Object child)
          Get the parent 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 isLeaf(java.lang.Object node)
          Query whether a node is a leaf.
 boolean isLinkBased()
          Query whether the TreeAdapter implementation supports link based child access efficiently.
 

Method Detail

getParentNode

public java.lang.Object getParentNode(java.lang.Object child)
Get the parent of a node.
Parameters:
child - The node to query for the parent.
Returns:
The parent of the node.

isLeaf

public boolean isLeaf(java.lang.Object node)
Query whether a node is a leaf.
Parameters:
node - The node to query.
Returns:
True if the node is a leaf.

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.

Returns:
True if index based access is efficient, false if it is inefficient.

getChildCount

public int getChildCount(java.lang.Object parent)
Get the number of children of a node.
Parameters:
parent - The node to query.
Returns:
The number of children of the node.

getChildNode

public java.lang.Object getChildNode(java.lang.Object parent,
                                     int index)
                              throws java.lang.IndexOutOfBoundsException
Get a child of a node.
Parameters:
parent - The node to query.
index - The index of the child.
Returns:
The child at the index.
Throws:
java.lang.IndexOutOfBoundsException - If the index is invalid.

getIndexOfChildNode

public int getIndexOfChildNode(java.lang.Object parent,
                               java.lang.Object child)
Get the index of a child in a node's list of children.
Parameters:
parent - The node to query.
child - The child to look for.
Returns:
The index of the child or -1 if it is not a child of this node.

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.

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.
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.
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.
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.
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.

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.
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