javax.swing.tree
Class TreePath

java.lang.Object
  extended by javax.swing.tree.TreePath
All Implemented Interfaces:
Serializable

public class TreePath
extends Object
implements Serializable

A TreePath represents a sequence of tree elements that form a path starting from the root of a tree. A tree element can be represented by any Object.

See Also:
Serialized Form

Constructor Summary
protected TreePath()
          Default constructor.
  TreePath(Object element)
          Creates a new path from a single element.
  TreePath(Object[] path)
          Creates a path from the list of objects representing tree elements.
protected TreePath(Object[] path, int length)
          Creates a new tree path using the first length elements from the given array.
protected TreePath(TreePath path, Object element)
          Creates a new tree path by adding the specified element to the path.
 
Method Summary
 boolean equals(Object object)
          Tests this path for equality with an arbitrary object.
 Object getLastPathComponent()
          Returns the last object in the path.
 TreePath getParentPath()
          Returns the parent path, which is a path containing all the same elements as this path, except for the last one.
 Object[] getPath()
          Returns an array containing the path elements.
 Object getPathComponent(int position)
          Returns the element at the specified position in the path.
 int getPathCount()
          Returns the number of elements in the path.
 int hashCode()
          Returns a hashcode for the path.
 boolean isDescendant(TreePath path)
          Returns true if path is a descendant of this path, and false otherwise.
 TreePath pathByAddingChild(Object element)
          Creates a new path that is equivalent to this path plus the specified element.
 String toString()
          Returns a string representation of this path.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TreePath

public TreePath(Object[] path)
Creates a path from the list of objects representing tree elements. The incoming array is copied so that subsequent changes do not affect this tree path.

Parameters:
path - the elements in the path (null not permitted).
Throws:
IllegalArgumentException - if path is null.

TreePath

public TreePath(Object element)
Creates a new path from a single element.

Parameters:
element - the element (null not permitted).
Throws:
IllegalArgumentException - if element is null.

TreePath

protected TreePath(TreePath path,
                   Object element)
Creates a new tree path by adding the specified element to the path.

Parameters:
path - a tree path.
element - a path element.

TreePath

protected TreePath(Object[] path,
                   int length)
Creates a new tree path using the first length elements from the given array.

Parameters:
path - the path elements.
length - the path length.

TreePath

protected TreePath()
Default constructor.

Method Detail

hashCode

public int hashCode()
Returns a hashcode for the path.

Overrides:
hashCode in class Object
Returns:
A hashcode.
See Also:
Object.equals(Object), System.identityHashCode(Object)

equals

public boolean equals(Object object)
Tests this path for equality with an arbitrary object. An object is considered equal to this path if and only if:

Overrides:
equals in class Object
Parameters:
object - the object (null permitted).
Returns:
true if obj is equal to this tree path, and false otherwise.
See Also:
Object.hashCode()

toString

public String toString()
Returns a string representation of this path.

Overrides:
toString in class Object
Returns:
A string representation of this path.
See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)

getPath

public Object[] getPath()
Returns an array containing the path elements.

Returns:
An array containing the path elements.

getLastPathComponent

public Object getLastPathComponent()
Returns the last object in the path.

Returns:
The last object in the path.

getPathCount

public int getPathCount()
Returns the number of elements in the path.

Returns:
The number of elements in the path.

getPathComponent

public Object getPathComponent(int position)
Returns the element at the specified position in the path.

Parameters:
position - the element position (0 < N - 1, where N is the number of elements in the path).
Returns:
The element at the specified position.
Throws:
IllegalArgumentException - if position is outside the valid range.

isDescendant

public boolean isDescendant(TreePath path)
Returns true if path is a descendant of this path, and false otherwise. If path is null, this method returns false.

Parameters:
path - the path to check (null permitted).
Returns:
true if path is a descendant of this path, and false otherwise

pathByAddingChild

public TreePath pathByAddingChild(Object element)
Creates a new path that is equivalent to this path plus the specified element.

Parameters:
element - the element.
Returns:
A tree path.

getParentPath

public TreePath getParentPath()
Returns the parent path, which is a path containing all the same elements as this path, except for the last one. If this path contains only one element, the method returns null.

Returns:
The parent path, or null if this path has only one element.