javax.swing.tree

Class TreePath

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

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.
TreePath(Object[] path, int length)
Creates a new tree path using the first length elements from the given array.
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, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

TreePath

protected TreePath()
Default constructor.

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

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

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

Method Details

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:
  • the object is not null;
  • the object is an instanceof TreePath;
  • the object contains the same elements in the same order as this TreePath;
Overrides:
equals in interface Object
Parameters:
object - the object (null permitted).
Returns:
true if obj is equal to this tree path, and false otherwise.

getLastPathComponent

public Object getLastPathComponent()
Returns the last object in the path.
Returns:
The last object in the 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.

getPath

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

getPathComponent

public Object getPathComponent(int position)
Returns the element at the specified position in the path.
Parameters:
position - the element position (0 &lt 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.

getPathCount

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

hashCode

public int hashCode()
Returns a hashcode for the path.
Overrides:
hashCode in interface Object
Returns:
A hashcode.

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.

toString

public String toString()
Returns a string representation of this path.
Overrides:
toString in interface Object
Returns:
A string representation of this path.

TreePath.java -- Copyright (C) 2002, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.