org.jboss.dna.graph.property.basic
Class ChildPath

java.lang.Object
  extended by org.jboss.dna.graph.property.basic.AbstractPath
      extended by org.jboss.dna.graph.property.basic.ChildPath
All Implemented Interfaces:
Serializable, Comparable<Path>, Iterable<Path.Segment>, Path

public class ChildPath
extends AbstractPath

Implementation of a Path that has the information for the last segment but that points to another Path for the parent information.

Author:
Randall Hauch
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.dna.graph.property.Path
Path.Segment
 
Field Summary
 
Fields inherited from class org.jboss.dna.graph.property.basic.AbstractPath
SELF_PATH
 
Fields inherited from interface org.jboss.dna.graph.property.Path
DEFAULT_DECODER, DEFAULT_ENCODER, DEFAULT_INDEX, DELIMITER, DELIMITER_STR, JSR283_DECODER, JSR283_ENCODER, NO_OP_DECODER, NO_OP_ENCODER, PARENT, PARENT_NAME, PARENT_SEGMENT, SELF, SELF_NAME, SELF_SEGMENT, URL_DECODER, URL_ENCODER
 
Constructor Summary
ChildPath(Path parent, Path.Segment child)
           
 
Method Summary
 Path getAncestor(int degree)
          Return the path to the ancestor of the supplied degree.
 Path.Segment getLastSegment()
          Get the last segment in this path.
 Path getParent()
          Return the path to the parent, or this path if it is the root. This is an efficient operation that does not require copying any data.
 Path.Segment getSegment(int index)
          Get the segment at the supplied index.
 List<Path.Segment> getSegmentsList()
          Get an unmodifiable list of the path segments.
 boolean hasSameAncestor(Path that)
          Determine whether this path and the supplied path have the same immediate ancestor. In other words, this method determines whether the node represented by this path is a sibling of the node represented by the supplied path.
 boolean isAbsolute()
          Return whether this path is an absolute path.
 boolean isAtOrBelow(Path other)
          Determine whether this path is the same as to or a decendant of the supplied path. This method is equivalent to (but may be more efficient than) calling isSame(other) || isAncestor(other).
 boolean isDecendantOf(Path ancestor)
          Determine whether this path is an decendant of the supplied path. A path is considered a decendant of another path if the the decendant path starts exactly with the entire ancestor path but contains at least one additional segment.
 boolean isNormalized()
          Return whether this path is normalized and contains no "." segments and as few ".." segments as possible.
 boolean isRoot()
          Return whether this path represents the root path.
 Iterator<Path.Segment> iterator()
          
 int size()
          Return the number of segments in this path.
 Path subpath(int beginIndex, int endIndex)
          Return a new path consisting of the segments between the beginIndex index (inclusive) and the endIndex index (exclusive).
 
Methods inherited from class org.jboss.dna.graph.property.basic.AbstractPath
compareTo, equals, getCanonicalPath, getCommonAncestor, getNormalizedPath, getSegmentsArray, getString, getString, getString, getString, getString, hashCode, isAncestorOf, isAtOrAbove, isSameAs, pathsFromRoot, relativeTo, resolve, resolveAgainst, subpath, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChildPath

public ChildPath(Path parent,
                 Path.Segment child)
Method Detail

getAncestor

public Path getAncestor(int degree)
Return the path to the ancestor of the supplied degree. An ancestor of degree x is the path that is x levels up along the path. For example, degree = 0 returns this path, while degree = 1 returns the parent of this path, degree = 2 returns the grandparent of this path, and so on. Note that the result may be unexpected if this path is not normalized, as a non-normalized path contains ".." and "." segments.

Returns:
the ancestor of the supplied degree
See Also:
Path.getAncestor(int)

getLastSegment

public Path.Segment getLastSegment()
Get the last segment in this path.

Specified by:
getLastSegment in interface Path
Overrides:
getLastSegment in class AbstractPath
Returns:
the last segment, or null if the path is empty
See Also:
Path.getLastSegment()

getParent

public Path getParent()
Return the path to the parent, or this path if it is the root. This is an efficient operation that does not require copying any data.

Specified by:
getParent in interface Path
Overrides:
getParent in class AbstractPath
Returns:
the parent path, or this null if it is already the root
See Also:
Path.getParent()

getSegment

public Path.Segment getSegment(int index)
Get the segment at the supplied index.

Specified by:
getSegment in interface Path
Overrides:
getSegment in class AbstractPath
Parameters:
index - the index
Returns:
the segment
See Also:
Path.getSegment(int)

getSegmentsList

public List<Path.Segment> getSegmentsList()
Get an unmodifiable list of the path segments.

Returns:
the unmodifiable list of path segments; never null
See Also:
Path.getSegmentsList()

hasSameAncestor

public boolean hasSameAncestor(Path that)
Determine whether this path and the supplied path have the same immediate ancestor. In other words, this method determines whether the node represented by this path is a sibling of the node represented by the supplied path.

Specified by:
hasSameAncestor in interface Path
Overrides:
hasSameAncestor in class AbstractPath
Parameters:
that - the other path
Returns:
true if this path and the supplied path have the same immediate ancestor.
See Also:
Path.hasSameAncestor(org.jboss.dna.graph.property.Path)

isAbsolute

public boolean isAbsolute()
Return whether this path is an absolute path. A path is either relative or absolute. An absolute path starts with a "/".

Returns:
true if the path is absolute, or false otherwise
See Also:
Path.isAbsolute()

isAtOrBelow

public boolean isAtOrBelow(Path other)
Determine whether this path is the same as to or a decendant of the supplied path. This method is equivalent to (but may be more efficient than) calling isSame(other) || isAncestor(other).

Specified by:
isAtOrBelow in interface Path
Overrides:
isAtOrBelow in class AbstractPath
Parameters:
other - the other path to compare with this path; may be null
Returns:
true if the paths are equivalent or if this path is considered a decendant of the other path, or false otherwise
See Also:
Path.isAtOrBelow(org.jboss.dna.graph.property.Path)

isDecendantOf

public boolean isDecendantOf(Path ancestor)
Determine whether this path is an decendant of the supplied path. A path is considered a decendant of another path if the the decendant path starts exactly with the entire ancestor path but contains at least one additional segment.

Specified by:
isDecendantOf in interface Path
Overrides:
isDecendantOf in class AbstractPath
Parameters:
ancestor - the path that may be the ancestor; may be null
Returns:
true if this path is an decendant of the supplied path, or false otherwise
See Also:
Path.isDecendantOf(org.jboss.dna.graph.property.Path)

isNormalized

public boolean isNormalized()
Return whether this path is normalized and contains no "." segments and as few ".." segments as possible. For example, the path "../a" is normalized, while "/a/b/c/../d" is not normalized.

Returns:
true if this path is normalized, or false otherwise
See Also:
Path.isNormalized()

isRoot

public boolean isRoot()
Return whether this path represents the root path.

Returns:
true if this path is the root path, or false otherwise
See Also:
Path.isRoot()

iterator

public Iterator<Path.Segment> iterator()

Specified by:
iterator in interface Iterable<Path.Segment>
Specified by:
iterator in interface Path
Overrides:
iterator in class AbstractPath
See Also:
Path.iterator()

size

public int size()
Return the number of segments in this path.

Returns:
the number of path segments
See Also:
Path.size()

subpath

public Path subpath(int beginIndex,
                    int endIndex)
Return a new path consisting of the segments between the beginIndex index (inclusive) and the endIndex index (exclusive).

Specified by:
subpath in interface Path
Overrides:
subpath in class AbstractPath
Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified subpath
See Also:
Path.subpath(int, int)


Copyright © 2008-Present JBoss a division of Red Hat. All Rights Reserved.