|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fhg.igd.util.CanonicalPath
public final class CanonicalPath
Represents a canonical path. A canonical path consists of a sequence of path elements, and can contain wildcards. This class provides methods to create canonical paths from strings, and to do various comparisons on canonical paths.
Wildcards are used when one canonical path is tested for implication by another. The rules are as follows:
FilePermission
.
Implication
Field Summary | |
---|---|
private boolean |
absolute_
Indicates that the path is absolute. |
static CanonicalPath |
ALL
A global wildcard path that matches all other paths (with the exception of the root path). |
private String[] |
path_
The array of path elements. |
private char |
separator_
The separator char. |
Constructor Summary | |
---|---|
private |
CanonicalPath()
Creates an unitialized instance. |
|
CanonicalPath(CanonicalPath parent,
CanonicalPath child)
Creates a new path which is the concatenation of the given paths. |
|
CanonicalPath(CanonicalPath parent,
String child)
Creates a new path which is the concatenation of the given paths. |
|
CanonicalPath(char separator)
Creates a zero-length path with the given separator. |
|
CanonicalPath(String path,
char separator)
Creates an instance from the given string with the given separator char. |
Method Summary | |
---|---|
Object |
clone()
Clones this instance. |
CanonicalPath |
commonParent(CanonicalPath path)
Creates the prefix path common to this canonical path and the given one. |
int |
compareTo(Object o)
Returns a number smaller than zero, zero, or greater than zero as the given path is smaller, than, equal to, or greater than the given path. |
String |
elementAt(int index)
Returns the path element at the given index. |
boolean |
equals(Object o)
Compares this canonical path with the given object. |
int |
hashCode()
Returns the has code of this object. |
CanonicalPath |
head(int length)
Returns a new path instance with the first
len path elements of this one. |
boolean |
implies(Object o)
Tests if this path implies the given one. |
boolean |
impliesAll()
Returns true if this paths implies any other
path but the root path. |
boolean |
isAbsolute()
Returns true if this path is absolute. |
boolean |
isPrefixOf(CanonicalPath that)
Checks is this path is a prefix of the given one. |
boolean |
isTruePrefixOf(CanonicalPath that)
Checks is this path is a true prefix of the given one. |
boolean |
isWildcard()
Returns true if this path contains
wildcard elements such as an asterisk or a minus. |
int |
length()
Returns the length of the path in elements. |
protected String[] |
sanitize(String[] tmp)
Sanitizes the given string by removing references to local and parent directories ('.', '..') from it as well as elements with length 0. |
CanonicalPath |
tail(int offset)
Returns a new path instance with all path elements of this one starting from the given index. |
protected String[] |
tokenize(String path,
char separator)
Transforms the given string into an array of strings by slicing it up at the boundaries determined by means of the separator char. |
String |
toString()
Returns the path as a string. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final CanonicalPath ALL
private String[] path_
private boolean absolute_
private char separator_
Constructor Detail |
---|
private CanonicalPath()
public CanonicalPath(char separator)
separator
- The separator char.public CanonicalPath(String path, char separator)
path
- The string representation of the path.separator
- The separater char.
NullPointerException
- if path
is null
.
IllegalArgumentException
- if the given path
has zero length.public CanonicalPath(CanonicalPath parent, CanonicalPath child)
parent
.
parent
- The parent path.child
- The child path.
NullPointerException
- if one of the given
paths is null
.public CanonicalPath(CanonicalPath parent, String child)
parent
, and the child is transformed with the
parent's separator char. If the child stands for an
absolute path then this constructor behaves as if
CanonicalPath(child, c)
had been called
with c
being the separator char of
parent
.
parent
- The parent path.child
- The child path.
NullPointerException
- if one of the given
paths is null
.Method Detail |
---|
protected String[] tokenize(String path, char separator)
path
- The path to tokenize.separator
- The separator char.
protected String[] sanitize(String[] tmp)
tmp
- The input array of path elements.
IllegalArgumentException
- if the given path
refers to a directory above the start of the path,
e.g. "foo/..".public boolean isAbsolute()
true
if this path is absolute.
true
if this path is absolute.public boolean isWildcard()
true
if this path contains
wildcard elements such as an asterisk or a minus.
true
if this path is a
wildcard.public boolean impliesAll()
true
if this paths implies any other
path but the root path. This methods verifies if this path
consists of the single path element "-", which
matches all other path elements recursively.
true
if this path implies all other
paths.public int length()
public String elementAt(int index)
index
.
ArrayIndexOutOfBoundsException
- if the
given index is out of range.public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public boolean implies(Object o)
implies
in interface Implication
o
- The object to test against.
true
if this path implies the
given one.public String toString()
toString
in class Object
public CanonicalPath tail(int offset)
index
is zero, in
that case this
will be returned).
ArrayIndexOutOfBoundsException
- if the
tail's length would be zero or negative.public CanonicalPath head(int length)
len
path elements of this one. If this
path is absolute/relative then the resulting path
will also be absolute/relative.
IllegalArgumentException
- if the given length
is less than 0 or exceeds the length of this path.public boolean isPrefixOf(CanonicalPath that)
that
- The CanonicalPath
to compare with.
true
if this path is a prefix
of the given one, and false
otherwise.public boolean isTruePrefixOf(CanonicalPath that)
that
- The CanonicalPath
to compare with.
true
if this path is a prefix
of the given one, and false
otherwise.public CanonicalPath commonParent(CanonicalPath path)
If both paths do not have a common prefix then the root path is returned. The separater equals the one of this path. In all other cases, the longest prefix common to this path and the given one is returned as a path. If this path is relative/absolute then the returned path is also relative/absolute.
path
- The path whose common prefix with this path
shall be returned.
IllegalArgumentException
- if this path is
absolute/relative and the given path is relative/absolute.public Object clone()
clone
in class Object
public int compareTo(Object o)
compareTo
in interface Comparable
o
- The object to compare to.
ClassCastException
- if the given object is not
of class CanonicalPath
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |