org.beanfabrics
Class Path

java.lang.Object
  extended by org.beanfabrics.Path
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<java.lang.String>

public class Path
extends java.lang.Object
implements java.lang.Iterable<java.lang.String>, java.io.Serializable

Immutable representation of a path inside a presentation object model.

See Also:
Serialized Form

Field Summary
static java.lang.String PATH_SEPARATOR
           
static char PATH_SEPARATOR_CHAR
           
static java.lang.String THIS_PATH_ELEMENT
           
 
Constructor Summary
Path()
          Creates a new identity ("this") path.
Path(java.lang.String pathStr)
          Creates a new path from the given path string.
 
Method Summary
static Path concat(Path... paths)
          Concatenates the given path objects to a new path.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this path.
 java.lang.String getElement(int index)
          Returns the element at the specified index.
 java.util.Collection<java.lang.String> getElements()
          Returns a collection of this path's elements.
 java.lang.String getLastElement()
          Returns the last element of this path or null if there are no elements.
 Path getParent()
          Returns the path to the parent node of this path.
 java.lang.String getPathString()
          Returns the canonical String representation of this path.
static java.lang.String getPathString(Path path)
          Returns the canonical path string of the given path object, or null if the path object is null.
 Path getSubPath(int fromPosition)
          Returns a new path that is a subpath of this path.
 Path getSubPath(int fromPosition, int length)
          Returns a new path that is a subpath of this path.
 int hashCode()
          Returns the hash code of this path.
 java.util.Iterator<java.lang.String> iterator()
          Returns an iterator over this path's elements.
 int length()
          Returns the length of this path.
static Path parse(java.lang.String pathStr)
          Returns a Path object that represents a path defined by the given path string, or null if the path string is null.
static java.lang.String toPathString(java.util.List<java.lang.String> listOfStrings)
          Concatenates the given strings to a path string delimited by dot '.'
static java.lang.String toPathString(java.lang.String[] strings)
          Concatenates the given strings to a path string delimited by dot '.'
 java.lang.String toString()
          Returns the canonical String representation of this path.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

THIS_PATH_ELEMENT

public static final java.lang.String THIS_PATH_ELEMENT
See Also:
Constant Field Values

PATH_SEPARATOR

public static final java.lang.String PATH_SEPARATOR
See Also:
Constant Field Values

PATH_SEPARATOR_CHAR

public static final char PATH_SEPARATOR_CHAR
See Also:
Constant Field Values
Constructor Detail

Path

public Path()
Creates a new identity ("this") path.


Path

public Path(java.lang.String pathStr)
     throws java.lang.IllegalArgumentException
Creates a new path from the given path string.

Parameters:
pathStr - a string of path elements delimited by the dot "." character.
Throws:
java.lang.IllegalArgumentException
Method Detail

getParent

public Path getParent()
Returns the path to the parent node of this path.

Returns:
the path to the parent node of this path

getSubPath

public Path getSubPath(int fromPosition)
                throws java.lang.IllegalArgumentException
Returns a new path that is a subpath of this path. The subpath begins with the element at the specified fromPosition and extends to the end of this path.

Parameters:
fromPosition - returned path's first character's position in this path
Returns:
a new path that is a subpath of this path
Throws:
java.lang.IllegalArgumentException

getSubPath

public Path getSubPath(int fromPosition,
                       int length)
                throws java.lang.IllegalArgumentException
Returns a new path that is a subpath of this path. The subpath begins at the specified fromPosition and the length of the subpath is length.

Parameters:
fromPosition - returned path's first character's position in this path
length - returned path's number of characters
Returns:
a new path that is a subpath of this path
Throws:
java.lang.IllegalArgumentException - thrown if length < 0 or fromPosition + length > length

length

public int length()
Returns the length of this path. The length is the distance from the root node to the target node. Therefor the length of the identity ("this") path is 0.

Returns:
the length of this path

iterator

public java.util.Iterator<java.lang.String> iterator()
Returns an iterator over this path's elements.

Specified by:
iterator in interface java.lang.Iterable<java.lang.String>

getElements

public java.util.Collection<java.lang.String> getElements()
Returns a collection of this path's elements.

Returns:
a collection of this path's elements

getElement

public java.lang.String getElement(int index)
Returns the element at the specified index.

Parameters:
index -
Returns:

getLastElement

public java.lang.String getLastElement()
Returns the last element of this path or null if there are no elements.

Returns:
the last element of this path or null if there are no elements

toString

public java.lang.String toString()
Returns the canonical String representation of this path.

Overrides:
toString in class java.lang.Object
Returns:
the canonical String representation of this path

getPathString

public java.lang.String getPathString()
Returns the canonical String representation of this path.

Returns:
the canonical String representation of this path

hashCode

public int hashCode()
Returns the hash code of this path.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this path.

Overrides:
equals in class java.lang.Object
Returns:
true if the obj argument is a Path and has the equal elements as this path

parse

public static Path parse(java.lang.String pathStr)
Returns a Path object that represents a path defined by the given path string, or null if the path string is null.

Returns:
a Path object that represents a path defined by the given path string

getPathString

public static java.lang.String getPathString(Path path)
Returns the canonical path string of the given path object, or null if the path object is null.

Parameters:
path -
Returns:
the canonical path string of the given path object

concat

public static Path concat(Path... paths)
Concatenates the given path objects to a new path.

Parameters:
paths -
Returns:
the concatenated path

toPathString

public static java.lang.String toPathString(java.util.List<java.lang.String> listOfStrings)
Concatenates the given strings to a path string delimited by dot '.' characters.

Parameters:
listOfStrings -
Returns:
the concatenated strings delimited by dot characters

toPathString

public static java.lang.String toPathString(java.lang.String[] strings)
Concatenates the given strings to a path string delimited by dot '.' characters.

Parameters:
strings -
Returns:
the concatenated strings delimited by dot characters