org.quattor.pan.utils
Class Path

java.lang.Object
  extended by org.quattor.pan.utils.Path
All Implemented Interfaces:
java.lang.Comparable<Path>

public class Path
extends java.lang.Object
implements java.lang.Comparable<Path>

This immutable class represents a pan path. The paths can be either absolute or relative. The individual path terms are validated when the Path is created; an EvaluationException will be thrown if there is a syntax error.

Author:
loomis

Nested Class Summary
static class Path.PathType
          An enumeration containing the three different types of paths.
 
Constructor Summary
Path(Path root, Term[] terms)
          Constructor which will create a new Path from the concatenation of two existing paths.
Path(java.lang.String path)
          Constructor of a path from a String.
 
Method Summary
 int compareTo(Path o)
          The default ordering for paths is such that it will produce a post-traversal ordering.
 boolean equals(java.lang.Object obj)
          Determine if two paths are equal.
 java.lang.String getAuthority()
          Return the authority for this path or null if it doesn't exist.
 Path.PathType getPathType()
          Get the type of this path.
 Term[] getTerms()
          Get the list of terms in this path.
 Path.PathType getType()
          Return the type (EXTERNAL, ABSOLUTE, or RELATIVE) for this path.
 int hashCode()
          This must be defined so that Paths can be used properly in Maps.
 boolean isAbsolute()
          A convenience method which returns a boolean indicating whether the Path is absolute or not.
 boolean isExternal()
          A convenience method which returns a boolean indicating whether the Path is external or not.
 boolean isRelative()
          A convenience method which returns a boolean indicating whether the Path is relative or not.
static Path resolve(Path prefix, Path relative)
           
 java.util.List<java.lang.String> toList()
          This method returns the Path as an unmodifiable list of the terms comprising the Path.
 java.lang.String toString()
          Convert this path to a string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Path

public Path(java.lang.String path)
     throws SyntaxException
Constructor of a path from a String. If the path does not have the correct syntax, an EvaluationException will be thrown.

Throws:
SyntaxException

Path

public Path(Path root,
            Term[] terms)
     throws SyntaxException
Constructor which will create a new Path from the concatenation of two existing paths. The first argument cannot be an external path. The second argument may be null.

Throws:
SyntaxException
Method Detail

toList

public java.util.List<java.lang.String> toList()
This method returns the Path as an unmodifiable list of the terms comprising the Path.


getTerms

public Term[] getTerms()
Get the list of terms in this path. The returned list will implement the RandomAccess interface, so fast random access to individual element can be assumed.


resolve

public static Path resolve(Path prefix,
                           Path relative)
                    throws SyntaxException
Throws:
SyntaxException

getType

public Path.PathType getType()
Return the type (EXTERNAL, ABSOLUTE, or RELATIVE) for this path.


getAuthority

public java.lang.String getAuthority()
Return the authority for this path or null if it doesn't exist.


isAbsolute

public boolean isAbsolute()
A convenience method which returns a boolean indicating whether the Path is absolute or not.


isRelative

public boolean isRelative()
A convenience method which returns a boolean indicating whether the Path is relative or not.


isExternal

public boolean isExternal()
A convenience method which returns a boolean indicating whether the Path is external or not.


getPathType

public Path.PathType getPathType()
Get the type of this path.

Returns:
the type of this path

equals

public boolean equals(java.lang.Object obj)
Determine if two paths are equal.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
This must be defined so that Paths can be used properly in Maps.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Convert this path to a string.

Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(Path o)
The default ordering for paths is such that it will produce a post-traversal ordering. All relative paths will be before absolute paths which are before external paths.

Specified by:
compareTo in interface java.lang.Comparable<Path>


Copyright © 2011 Quattor. All Rights Reserved.