|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.meshcms.util.Path
An abstract representation of a file path. The root of the path is undefined, and the path can be relative (i.e. can start with '..'). Example of paths are:
Path
can be created from any object. When you call a
constructor, the path is initialized as empty, then the objects passed to
the constructor are added to it.
When all objects have been added, the path is simplified by removing
redundant elements. For example, "home/user/../otheruser"
is reduced to "home/otheruser".
After the constructor returns, the
Path
object is immutable. When you call a method to modify
it (like one of the add()
methods), it returns a new
Path
that is the result of the requested operation.
The objects are added as follows:
Path
, its elements are added;String
, it is split in tokens (divided by
slashes or backslashes) and these tokens are added as elements;Collection
, any member of the
Collection
is added as a separate object;String
s, any member of the array is
added as a separate String
(to be tokenized);toString()
method is
called and the returned String
is tokenized and added.
Field Summary | |
protected java.lang.String[] |
elements
|
protected java.lang.String |
pathName
|
static Path |
ROOT
|
Constructor Summary | |
Path()
Creates an empty path. |
|
Path(java.lang.Object o)
Creates a path and adds an object to it. |
|
Path(java.lang.Object o1,
java.lang.Object o2)
Creates a path and adds two objects to it. |
|
Path(java.lang.Object o1,
java.lang.Object o2,
java.lang.Object o3)
Creates a path and adds three objects to it. |
Method Summary | |
Path |
add(java.lang.Object o)
Adds an object to the current path. |
Path |
add(java.lang.Object o1,
java.lang.Object o2)
Adds two objects to the current path. |
protected void |
addObjectToList(java.util.List list,
java.lang.Object o)
|
protected java.lang.Object |
clone()
|
static Path |
commonPart(Path p1,
Path p2)
Returns the common part between the two Paths. |
int |
compareTo(java.lang.Object o)
Compares this path to a new Path built by calling
new Path(o) |
int |
compareTo(Path other)
Compares two paths. |
boolean |
equals(java.lang.Object o)
Checks the two paths for equality. |
java.lang.String |
getAsLink()
Returns this path object encoded As a link: if the path is not empty, adds a slash at the beginning. |
Path |
getCommonPath(Path other)
Returns the common part between the two Paths (between this path
and the other path). |
java.lang.String |
getElementAt(int index)
Returns the element at the given index. |
int |
getElementCount()
Returns the number of elements of the current path. |
java.lang.String[] |
getElements()
Returns a copy of the elements array. |
java.io.File |
getFile(java.io.File parent)
Returns a File object relative to the given file. |
java.lang.String |
getLastElement()
Returns the last element of the current path (usually the file name). |
Path |
getParent()
Return the parent of the current path. |
Path |
getPartial(int count)
Returns a parent of the current path, whose element count is equal to the passed value. |
Path |
getRelativeTo(java.lang.Object root)
Returns the current path as relative to the given root. |
int |
hashCode()
Returns the hash code of the String that representes this path. |
boolean |
isChildOf(Path parent)
Checks if this path is a child of the parent path. |
boolean |
isContainedIn(Path root)
Checkes if the current path is contained in another path. |
boolean |
isRelative()
Cheks if this path is relative (when the first element of this path is "..") |
boolean |
isRoot()
Returns true if this path is a ROOT path (when the path is empty) |
Path |
replace(int index,
java.lang.String element)
|
Path |
successor()
Returns the successor of this Path , as defined in the Javadoc
of java.util.TreeMap.subMap(...) |
java.lang.String |
toString()
Returns the String representation of the current path. |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.lang.String pathName
protected java.lang.String[] elements
public static final Path ROOT
Constructor Detail |
public Path()
public Path(java.lang.Object o)
o
- the Object to be added to this new pathpublic Path(java.lang.Object o1, java.lang.Object o2)
o1
- the Object 1 to be addedo2
- the Object 2 to be addedpublic Path(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)
o1
- the Object 1 to be addedo2
- the Object 2 to be addedo3
- the Object 3 to be addedMethod Detail |
protected void addObjectToList(java.util.List list, java.lang.Object o)
public Path add(java.lang.Object o)
o
- the Object to be added to the current path
Path
which is the combination of the current
path and the added objectpublic Path add(java.lang.Object o1, java.lang.Object o2)
o1
- Object 1 to addo2
- Object 2 to add
Path
which is the combination of the current
path and the added objectspublic Path getParent()
Path
with one element whose value is "..").
public Path getPartial(int count)
count
- the count
public Path getCommonPath(Path other)
this
path
and the other
path).
other
- the second path
public boolean isRelative()
true
when the first element of the current path is
"..".public boolean isRoot()
true
if the path is empty.public boolean isChildOf(Path parent)
this
path is a child of the parent
path.
parent
- the parent path
true
if the path current path is contained in the
given path directly. Example:
Path myPath = new Path("home/user/myfile.txt"); myPath.isChildOf(new Path("nohome")); // returns false myPath.isChildOf(new Path("home")); // returns false myPath.isChildOf(new Path("home/user")); // returns true
public boolean isContainedIn(Path root)
root
- the othr path where to check if the current path is contained.
true
if the current path is contained in the
given path (at any depth). Example:
Path myPath = new Path("home/user/myfile.txt"); myPath.isContainedIn(new Path("nohome")); // returns false myPath.isContainedIn(new Path("home")); // returns true myPath.isContainedIn(new Path("home/user")); // returns true
public Path getRelativeTo(java.lang.Object root)
Path myPath = new Path("home/user/myfile.txt"); myPath.getRelativeTo(new Path("home")); // returns "user/myfile.txt"
root
- the root to relate this path to.
public java.io.File getFile(java.io.File parent)
File
object relative to the given file.
parent
- the parent file as a relative base
public int getElementCount()
new Path().getElementCount(); // returns 0 new Path("home/user").getElementCount(); // returns 2 new Path("../user").getElementCount(); // returns 2
public java.lang.String getElementAt(int index)
ArrayIndexOutOfBoundsException
might be thrown.
index
- the index for the searched element.
index
public java.lang.String getLastElement()
String
is returned.
public java.lang.String toString()
String
representation of the current path. The
separator between elements is always a slash, regardless of the platform.
public java.lang.String getAsLink()
public int compareTo(java.lang.Object o)
Path
built by calling
new Path(o)
compareTo
in interface java.lang.Comparable
public int compareTo(Path other)
path1.compareTo(path2)
is different from
path1.toString().compareTo(path2.toString())
, since this
method compares the single elements of the paths.
other
- the path to compare to this path
public int hashCode()
String
that representes this path.
public boolean equals(java.lang.Object o)
public static Path commonPart(Path p1, Path p2)
p1
- the Path 1p2
- the Path 2
p1
and p2
public Path successor()
Path
, as defined in the Javadoc
of java.util.TreeMap.subMap(...)
. This is useful when you need
to use that method to get a closed range submap (or headmap, or
tailmap) of Path
s.
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
java.lang.CloneNotSupportedException
public Path replace(int index, java.lang.String element)
public java.lang.String[] getElements()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |