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

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

@Immutable
public abstract class AbstractPath
extends Object
implements Path

An abstract foundation for different Path implementations. This class does not manage any of the Path's state, but it does provide implementations for most of the methods based upon a few abstract methods. For example, any implementaton that requires the path's segments are written to use the iterator(), since that is likely more efficient for the majority of implementations.

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 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
AbstractPath()
           
 
Method Summary
 int compareTo(Path that)
          
 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 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.
 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.
 int hashCode()
          
 boolean hasSameAncestor(Path that)
          Determine whether this path and the supplied path have the same immediate ancestor.
 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 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 relativeTo(Path startingPath)
          Get a relative path from the supplied path 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.
 Path resolveAgainst(Path absolutePath)
          Get the absolute path by resolving this relative (non-absolute) path against the supplied absolute 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).
 String toString()
          
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jboss.dna.graph.property.Path
getAncestor, getSegmentsList, isAbsolute, isNormalized, isRoot, size
 

Field Detail

SELF_PATH

public static final Path SELF_PATH
Constructor Detail

AbstractPath

public AbstractPath()
Method Detail

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
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
Parameters:
that - the other path
Returns:
the lowest common ancestor, which may be the root path if there is no other.

getLastSegment

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

Specified by:
getLastSegment in interface Path
Returns:
the last segment, or null if the path is empty

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
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:
Path.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
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:
Path.endsWith(org.jboss.dna.graph.property.Name, int)

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
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
Parameters:
index - the index
Returns:
the segment

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
Returns:
the array of segments as a copy

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
Returns:
the normalized path, or this object if this path is already normalized

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
Returns:
the encoded string
See Also:
Readable.getString(TextEncoder)

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
Parameters:
encoder - the encoder to use, or null if the default encoder should be used
Returns:
the encoded string
See Also:
Readable.getString()

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
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(NamespaceRegistry,TextEncoder)

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

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
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
Parameters:
that - the other path
Returns:
true if this path and the supplied path have the same immediate ancestor.

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

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

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

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

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
Parameters:
other - the other path to compare with this path; may be null
Returns:
true if the paths are equivalent, or false otherwise

iterator

public Iterator<Path.Segment> iterator()

Specified by:
iterator in interface Iterable<Path.Segment>
Specified by:
iterator in interface Path

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
Returns:
the path iterator; never null
See Also:
Path.pathsFromRoot()

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
Returns:
the relative path from the root node; never null
See Also:
Path.relativeToRoot()

relativeTo

public Path relativeTo(Path startingPath)
Get a relative path from the supplied path to this path.

Specified by:
relativeTo in interface Path
Parameters:
startingPath - the path specifying the starting point for the new relative path; may not be null
Returns:
the relative path

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

resolveAgainst

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

Specified by:
resolveAgainst in interface Path
Parameters:
absolutePath - the absolute path to which this relative path should be resolve
Returns:
the absolute path resolved from this path and the supplied absolute path

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
Parameters:
beginIndex - the beginning index, inclusive.
Returns:
the specified subpath

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
Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified subpath

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

compareTo

public int compareTo(Path that)

Specified by:
compareTo in interface Comparable<Path>

toString

public String toString()

Overrides:
toString in class Object


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