public class TreePath extends Object implements Serializable
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
.Modifier | Constructor and Description |
---|---|
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 . |
Modifier and Type | Method and Description |
---|---|
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.
|
public TreePath(Object[] path)
path
- the elements in the path (null
not permitted).IllegalArgumentException
- if path
is null
.public TreePath(Object element)
element
- the element (null
not permitted).IllegalArgumentException
- if element
is
null
.protected TreePath(TreePath path, Object element)
element
to
the path
.path
- a tree path.element
- a path element.protected TreePath(Object[] path, int length)
length
elements
from the given array.path
- the path elements.length
- the path length.protected TreePath()
public int hashCode()
hashCode
in class Object
Object.equals(Object)
,
System.identityHashCode(Object)
public boolean equals(Object object)
equals
in class Object
object
- the object (null
permitted).true
if obj
is equal to this tree path,
and false
otherwise.Object.hashCode()
public String toString()
toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)
public Object[] getPath()
public Object getLastPathComponent()
public int getPathCount()
public Object getPathComponent(int position)
position
- the element position (0 < N - 1
, where
N
is the number of elements in the path).IllegalArgumentException
- if position
is outside the
valid range.public boolean isDescendant(TreePath path)
true
if path
is a descendant of this
path, and false
otherwise. If path
is
null
, this method returns false
.path
- the path to check (null
permitted).true
if path
is a descendant of this
path, and false
otherwisepublic TreePath pathByAddingChild(Object element)
element
- the element.public TreePath getParentPath()
null
.null
if this path has only one
element.