bibliothek.util
Class Path

java.lang.Object
  extended by bibliothek.util.Path

public final class Path
extends Object

A path is a description of the position of some resource. A path consists of segments where a segment can be any kind of string (preferably a segment is a valid java-identifier). A path can be converted into a string, the segments will be encoded when doing that.

Author:
Benjamin Sigg

Field Summary
static Path TYPE_BOOLEAN_PATH
          standard path for Boolean
static Path TYPE_INT_PATH
          standard path for Integer
static Path TYPE_KEYSTROKE_PATH
          standard path for KeyStroke, can use KeyStrokeValidator as information
static Path TYPE_LABEL
          standard path for a label, a label is not shown in an enabled editor
static Path TYPE_MODIFIER_MASK_PATH
          standard path for ModifierMask
static Path TYPE_STRING_CHOICE_PATH
          standard path for a choice using a String as value and a Choice as information
static Path TYPE_STRING_PATH
          standard path for String
 
Constructor Summary
Path()
          Creates a new root path.
Path(String... segments)
          Creates a new path with the given segments.
Path(String path)
          Creates a new path.
 
Method Summary
 Path append(Path path)
          Creates a new path which is a combination of this and path.
 Path append(String segments)
          Creates a new path appending segments to this path.
static String decodeSegment(String segment)
          The opposite of encodeSegment(String).
static String encodeSegment(String segment)
          Puts an escape character before any illegal character of segment, thus creating a valid segment.
 boolean equals(Object obj)
           
 String getLastSegment()
          Gets the last segment of this path or null if this is the root path.
 Path getParent()
          Returns the parent of this path.
 String getSegment(int index)
          Gets the index'th segment of this path.
 int getSegmentCount()
          Gets the number of segments of this path.
 int hashCode()
           
static boolean isValidPath(String path)
          Tells whether path is a valid path or not
 boolean startsWith(Path path)
          Tells whether the first segments of this Path matches the segments of path.
 Path subPath(int offset, int length)
          Creates a new path that is a subset of this path.
 String toString()
           
 Path uniqueAppend(Path path)
          Creates a new path which is not only a combination of this and path, but is also unique in the way that x+y.z would not yield the same as x.y+z.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_INT_PATH

public static final Path TYPE_INT_PATH
standard path for Integer


TYPE_STRING_PATH

public static final Path TYPE_STRING_PATH
standard path for String


TYPE_BOOLEAN_PATH

public static final Path TYPE_BOOLEAN_PATH
standard path for Boolean


TYPE_KEYSTROKE_PATH

public static final Path TYPE_KEYSTROKE_PATH
standard path for KeyStroke, can use KeyStrokeValidator as information


TYPE_MODIFIER_MASK_PATH

public static final Path TYPE_MODIFIER_MASK_PATH
standard path for ModifierMask


TYPE_STRING_CHOICE_PATH

public static final Path TYPE_STRING_CHOICE_PATH
standard path for a choice using a String as value and a Choice as information


TYPE_LABEL

public static final Path TYPE_LABEL
standard path for a label, a label is not shown in an enabled editor

Constructor Detail

Path

public Path(String... segments)
Creates a new path with the given segments.

Parameters:
segments - the path

Path

public Path()
Creates a new root path.


Path

public Path(String path)
Creates a new path.

Parameters:
path - the dot-separated segments of this path, each segment must be a valid Java-identifier. Note that no segment should start with "_". Clients may use encodeSegment(String) to use any character within a single segment.
Method Detail

encodeSegment

public static String encodeSegment(String segment)
Puts an escape character before any illegal character of segment, thus creating a valid segment.

Parameters:
segment - the segment to encode
Returns:
the valid segment

decodeSegment

public static String decodeSegment(String segment)
The opposite of encodeSegment(String).

Parameters:
segment - some segment with escape characters
Returns:
the original form of the segment

isValidPath

public static boolean isValidPath(String path)
Tells whether path is a valid path or not

Parameters:
path - the path to test
Returns:
true if the segment is valid

getSegmentCount

public int getSegmentCount()
Gets the number of segments of this path.

Returns:
the number of segments

getSegment

public String getSegment(int index)
Gets the index'th segment of this path.

Parameters:
index - the location of the segment
Returns:
the segment

getLastSegment

public String getLastSegment()
Gets the last segment of this path or null if this is the root path.

Returns:
the last segment or null

subPath

public Path subPath(int offset,
                    int length)
Creates a new path that is a subset of this path.

Parameters:
offset - the begin of the new path
length - the length of the new path, at least 1
Returns:
the new path

append

public Path append(Path path)
Creates a new path which is a combination of this and path.

Parameters:
path - the path to add
Returns:
the new path

uniqueAppend

public Path uniqueAppend(Path path)
Creates a new path which is not only a combination of this and path, but is also unique in the way that x+y.z would not yield the same as x.y+z. This implies also that (x+y)+z would result in another path than x+(y+z). Note that the result of this method differs from append(Path). Note also that the new path has a different prefix than this.

Parameters:
path - the additional path
Returns:
the new path

append

public Path append(String segments)
Creates a new path appending segments to this path.

Parameters:
segments - the additional segments
Returns:
the new path

getParent

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

Returns:
the parent or null if this is the root

startsWith

public boolean startsWith(Path path)
Tells whether the first segments of this Path matches the segments of path.

Parameters:
path - some other path
Returns:
true if this path is either equal to path or if this path starts with path

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object