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

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

@Immutable
public class RootPath
extends AbstractPath

Optimized implementation of Path that serves as the root path.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.dna.graph.property.Path
Path.Segment
 
Field Summary
static Path INSTANCE
           
 
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
 
Method Summary
 int compareTo(Path other)
          
 boolean endsWith(Name nameOfLastSegment)
          Determine if the path's Path.getLastSegment() has the supplied name and no SNS index.
 boolean endsWith(Name nameOfLastSegment, int snsIndex)
          Determine if the path's Path.getLastSegment() has the supplied name and SNS index.
 boolean equals(Object obj)
          
 Path getAncestor(int degree)
          Return the path to the ancestor of the supplied degree.
 Path getCanonicalPath()
          Get the canonical form of this path.
 Path getCommonAncestor(Path that)
          Find the lowest common ancestor of this path and the supplied path.
 Path.Segment getLastSegment()
          Get the last segment in this path.
 Path getNormalizedPath()
          Get a normalized path with as many ".." segments and all "." resolved.
 Path getParent()
          Return the path to the parent, or this path if it is the root.
 Path.Segment getSegment(int index)
          Get the segment at the supplied index.
 Path.Segment[] getSegmentsArray()
          Obtain a copy of the segments in this path.
 List<Path.Segment> getSegmentsList()
          Get an unmodifiable list of the path segments.
 String getString()
          Get the string form of the object.
 String getString(NamespaceRegistry namespaceRegistry)
          Get the string form of the object, using the supplied namespace registry to convert any namespace URIs to prefixes.
 String getString(NamespaceRegistry namespaceRegistry, TextEncoder encoder)
          Get the encoded string form of the object, using the supplied namespace registry to convert the any namespace URIs to prefixes.
 String getString(NamespaceRegistry namespaceRegistry, TextEncoder encoder, TextEncoder delimiterEncoder)
          Get the encoded string form of the object, using the supplied namespace registry to convert the names' namespace URIs to prefixes and the supplied encoder to encode characters, and using the second delimiter to encode (or convert) the delimiter used between the namespace prefix and the local part of any names.
 String getString(TextEncoder encoder)
          Get the encoded string form of the object, using the supplied encoder to encode characters.
 boolean hasSameAncestor(Path that)
          Determine whether this path and the supplied path have the same immediate ancestor.
 boolean isAbsolute()
          Return whether this path is an absolute path.
 boolean isAncestorOf(Path decendant)
          Determine whether this path is an ancestor of the supplied path.
 boolean isAtOrAbove(Path other)
          Determine whether this path is the same as to or a ancestor of the supplied path.
 boolean isAtOrBelow(Path other)
          Determine whether this path is the same as to or a decendant of the supplied path.
 boolean isDecendantOf(Path ancestor)
          Determine whether this path is an decendant of the supplied path.
 boolean isNormalized()
          Return whether this path is normalized and contains no unnecessary "." segments and as few ".." segments as possible.
 boolean isRoot()
          Return whether this path represents the root path.
 boolean isSameAs(Path other)
          Determine whether this path represents the same as the supplied path.
 Iterator<Path.Segment> iterator()
          
 Iterator<Path> pathsFromRoot()
          Return an iterator that walks the paths from the root path down to this path.
 Path relativeToRoot()
          Obtain a path that is relative to the root node.
 Path resolve(Path relativePath)
          Get the absolute path by resolving the supplied relative (non-absolute) path against this absolute path.
 int size()
          Return the number of segments in this path.
 Path subpath(int beginIndex)
          Return a new path consisting of the segments starting at beginIndex index (inclusive).
 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
hashCode, relativeTo, resolveAgainst, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INSTANCE

public static final Path INSTANCE
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)

getCanonicalPath

public Path getCanonicalPath()
Get the canonical form of this path. A canonical path has is absolute and Path.isNormalized().

Specified by:
getCanonicalPath in interface Path
Overrides:
getCanonicalPath in class AbstractPath
Returns:
the canonical path, or this object if it is already in its canonical form
See Also:
Path.getCanonicalPath()

getCommonAncestor

public Path getCommonAncestor(Path that)
Find the lowest common ancestor of this path and the supplied path.

Specified by:
getCommonAncestor in interface Path
Overrides:
getCommonAncestor in class AbstractPath
Parameters:
that - the other path
Returns:
the lowest common ancestor, which may be the root path if there is no other.
See Also:
Path.getCommonAncestor(org.jboss.dna.graph.property.Path)

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

endsWith

public boolean endsWith(Name nameOfLastSegment)
Determine if the path's Path.getLastSegment() has the supplied name and no SNS index.

Specified by:
endsWith in interface Path
Overrides:
endsWith in class AbstractPath
Parameters:
nameOfLastSegment - the name
Returns:
return true if the supplied name is the name in the path's last segment (and there is no SNS index), or false otherwise
See Also:
AbstractPath.endsWith(org.jboss.dna.graph.property.Name)

endsWith

public boolean endsWith(Name nameOfLastSegment,
                        int snsIndex)
Determine if the path's Path.getLastSegment() has the supplied name and SNS index.

Specified by:
endsWith in interface Path
Overrides:
endsWith in class AbstractPath
Parameters:
nameOfLastSegment - the name
snsIndex - the SNS index
Returns:
return true if the path's last segment has the supplied name and SNS, or false otherwise
See Also:
AbstractPath.endsWith(org.jboss.dna.graph.property.Name, int)

getNormalizedPath

public Path getNormalizedPath()
Get a normalized path with as many ".." segments and all "." resolved. The relative path ".", however, will return itself as the normalized path, since it cannot be resolved any further.

Specified by:
getNormalizedPath in interface Path
Overrides:
getNormalizedPath in class AbstractPath
Returns:
the normalized path, or this object if this path is already normalized
See Also:
Path.getNormalizedPath()

relativeToRoot

public Path relativeToRoot()
Obtain a path that is relative to the root node. This is equivalent to calling Path.relativeTo(Path) with the root path.

Specified by:
relativeToRoot in interface Path
Overrides:
relativeToRoot in class AbstractPath
Returns:
the relative path from the root node; never null
See Also:
AbstractPath.relativeToRoot()

resolve

public Path resolve(Path relativePath)
Get the absolute path by resolving the supplied relative (non-absolute) path against this absolute path.

Specified by:
resolve in interface Path
Overrides:
resolve in class AbstractPath
Parameters:
relativePath - the relative path that is to be resolved against this path
Returns:
the absolute and normalized path resolved from this path and the supplied absolute path
See Also:
AbstractPath.resolve(org.jboss.dna.graph.property.Path)

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)

getSegmentsArray

public Path.Segment[] getSegmentsArray()
Obtain a copy of the segments in this path. None of the segments are encoded.

Specified by:
getSegmentsArray in interface Path
Overrides:
getSegmentsArray in class AbstractPath
Returns:
the array of segments as a copy
See Also:
Path.getSegmentsArray()

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

getString

public String getString()
Get the string form of the object. A default encoder is used to encode characters.

Specified by:
getString in interface Readable
Overrides:
getString in class AbstractPath
Returns:
the encoded string
See Also:
Readable.getString()

getString

public String getString(TextEncoder encoder)
Get the encoded string form of the object, using the supplied encoder to encode characters.

Specified by:
getString in interface Readable
Overrides:
getString in class AbstractPath
Parameters:
encoder - the encoder to use, or null if the default encoder should be used
Returns:
the encoded string
See Also:
Readable.getString(org.jboss.dna.common.text.TextEncoder)

getString

public String getString(NamespaceRegistry namespaceRegistry)
Get the string form of the object, using the supplied namespace registry to convert any namespace URIs to prefixes. A default encoder is used to encode characters.

Specified by:
getString in interface Readable
Overrides:
getString in class AbstractPath
Parameters:
namespaceRegistry - the namespace registry that should be used to obtain the prefix for any namespace URIs
Returns:
the encoded string
See Also:
Readable.getString(org.jboss.dna.graph.property.NamespaceRegistry)

getString

public String getString(NamespaceRegistry namespaceRegistry,
                        TextEncoder encoder)
Get the encoded string form of the object, using the supplied namespace registry to convert the any namespace URIs to prefixes.

Specified by:
getString in interface Readable
Overrides:
getString in class AbstractPath
Parameters:
namespaceRegistry - the namespace registry that should be used to obtain the prefix for the namespace URIs
encoder - the encoder to use, or null if the default encoder should be used
Returns:
the encoded string
See Also:
Readable.getString(org.jboss.dna.graph.property.NamespaceRegistry, org.jboss.dna.common.text.TextEncoder)

getString

public String getString(NamespaceRegistry namespaceRegistry,
                        TextEncoder encoder,
                        TextEncoder delimiterEncoder)
Get the encoded string form of the object, using the supplied namespace registry to convert the names' namespace URIs to prefixes and the supplied encoder to encode characters, and using the second delimiter to encode (or convert) the delimiter used between the namespace prefix and the local part of any names.

Specified by:
getString in interface Readable
Overrides:
getString in class AbstractPath
Parameters:
namespaceRegistry - the namespace registry that should be used to obtain the prefix for the namespace URIs in the segment names
encoder - the encoder to use for encoding the local part and namespace prefix of any names, or null if the default encoder should be used
delimiterEncoder - the encoder to use for encoding the delimiter between the local part and namespace prefix of any names, or null if the standard delimiter should be used
Returns:
the encoded string
See Also:
Readable.getString(org.jboss.dna.graph.property.NamespaceRegistry, org.jboss.dna.common.text.TextEncoder, org.jboss.dna.common.text.TextEncoder)

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

isAncestorOf

public boolean isAncestorOf(Path decendant)
Determine whether this path is an ancestor of the supplied path. A path is considered an ancestor of another path if the the ancestor path appears in its entirety at the beginning of the decendant path, and where the decendant path contains at least one additional segment.

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

isAtOrAbove

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

Specified by:
isAtOrAbove in interface Path
Overrides:
isAtOrAbove 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 an ancestor of the other path, or false otherwise
See Also:
Path.isAtOrAbove(org.jboss.dna.graph.property.Path)

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 unnecessary "." 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()

isSameAs

public boolean isSameAs(Path other)
Determine whether this path represents the same as the supplied path. This is equivalent to calling this.compareTo(other) == 0 .

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

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

pathsFromRoot

public Iterator<Path> pathsFromRoot()
Return an iterator that walks the paths from the root path down to this path. This method always returns at least one path (the root returns an iterator containing itself).

Specified by:
pathsFromRoot in interface Path
Overrides:
pathsFromRoot in class AbstractPath
Returns:
the path iterator; never null
See Also:
Path.pathsFromRoot()

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)
Return a new path consisting of the segments starting at beginIndex index (inclusive). This is equivalent to calling path.subpath(beginIndex,path.size()-1).

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

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)

compareTo

public int compareTo(Path other)

Specified by:
compareTo in interface Comparable<Path>
Overrides:
compareTo in class AbstractPath
See Also:
Comparable.compareTo(java.lang.Object)

equals

public boolean equals(Object obj)

Overrides:
equals in class AbstractPath
See Also:
Object.equals(java.lang.Object)


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