public class RelativePath extends java.lang.Object implements java.lang.Iterable<RelativePath>
Constructor and Description |
---|
RelativePath()
Create a new empty RelativePath using the default separator.
|
RelativePath(char separator,
java.util.List<java.lang.String> elts)
Create a new RelativePath using the given path elements and the separator.
|
RelativePath(char separator,
java.lang.String... elements)
Create a new RelativePath using the given path elements and the separator.
|
RelativePath(RelativePath... paths)
Create a new RelativePath by appending the provided
paths . |
RelativePath(java.lang.String... elements)
Create a new RelativePath using the given path elements and the default separator.
|
RelativePath(java.lang.String path)
Create a new RelativePath using the path and the default separator.
|
Modifier and Type | Method and Description |
---|---|
boolean |
endsWith(RelativePath other)
Tests if this RelativePath ends with the given RelativePath.
|
boolean |
endsWith(java.lang.String other)
Tests if this RelativePath ends with the given RelativePath.
|
boolean |
equals(java.lang.Object obj) |
java.lang.String |
getAbsolutePath()
Return a
String representation of this RelativePath interpreted as an absolute path. |
RelativePath |
getFileName()
Get the file name, or
null if the RelativePath is empty. |
java.lang.String |
getFileNameAsString()
Get the file name as a
String , or null if the RelativePath is empty. |
RelativePath |
getName(int index)
Get a name element of this RelativePath.
|
int |
getNameCount()
Get the number of name elements in the RelativePath.
|
RelativePath |
getParent()
Get the parent RelativePath, or
null if this RelativePath does not have a parent. |
java.lang.String |
getRelativePath()
Return a
String representation of this RelativePath interpreted as a relative path. |
char |
getSeparator()
Get the separator.
|
int |
hashCode() |
boolean |
isEmpty()
Is this RelativePath empty ?
|
java.util.Iterator<RelativePath> |
iterator()
Create an
Iterator that returns all possible sub RelativePaths of this RelativePath, in order of increasing length. |
RelativePath |
normalize()
Normalize this RelativePath by removing as many redundant path elements as possible.
|
RelativePath |
relativize(RelativePath other)
Create a relative RelativePath between the given RelativePath and this RelativePath.
|
RelativePath |
resolve(RelativePath other)
Resolve a RelativePath against this RelativePath.
|
RelativePath |
resolve(java.lang.String other)
Resolve a String containing a RelativePath against this path.
|
RelativePath |
resolveSibling(RelativePath other)
Resolves the given RelativePath to this paths parent RelativePath, thereby creating a sibling to this RelativePath.
|
boolean |
startsWith(RelativePath other)
Tests if this RelativePath starts with the given RelativePath.
|
boolean |
startsWith(java.lang.String other)
Tests if this RelativePath starts with the given RelativePath.
|
RelativePath |
subpath(int beginIndex,
int endIndex)
Returns a RelativePath that is a subsequence of the name elements of this path.
|
java.lang.String |
toString() |
public RelativePath()
public RelativePath(java.lang.String path)
path
is null
or an empty String, the resulting RelativePath is empty.
If path
contains the separator it will be split into multiple elements.path
- the path to use.public RelativePath(java.lang.String... elements)
elements
is null
or an empty String array, the resulting RelativePath is empty.
Any elements that are null
or an empty String will be ignored.
Any elements that contain the separator will be split into multiple elements.elements
- the path elements to use.public RelativePath(RelativePath... paths)
paths
.
If the paths
is null
the resulting RelativePath is empty.paths
- the path elements to use.public RelativePath(char separator, java.lang.String... elements)
elements
is null
or an empty String array, the resulting RelativePath is empty.
Otherwise, each of the elements will be parsed individually, splitting them into elements wherever a separator is
encountered. Elements that are null
or contain an empty String are ignored.elements
- the path elements to use.separator
- the separator to use.public RelativePath(char separator, java.util.List<java.lang.String> elts)
elements
is null
or an empty String array, the resulting RelativePath is empty.
Otherwise, each of the elements will be parsed individually, splitting them into elements wherever a separator is
encountered. Elements that are null
or contain an empty String are ignored.elts
- the path elements to use.separator
- the separator to use.public RelativePath getFileName()
null
if the RelativePath is empty.
The file name is the last element of the RelativePath.null
.public java.lang.String getFileNameAsString()
String
, or null
if the RelativePath is empty.
The file name is the last element of the RelativePath.null
.public char getSeparator()
public RelativePath getParent()
null
if this RelativePath does not have a parent.public int getNameCount()
public RelativePath getName(int index)
index
- the index of the elementjava.lang.IndexOutOfBoundsException
- If the index is negative or greater or equal to the number of elements in the path.public RelativePath subpath(int beginIndex, int endIndex)
beginIndex
- the index of the first element, inclusiveendIndex
- the index of the last element, exclusivejava.lang.IllegalArgumentException
- If beginIndex is larger than or equal to the endIndex.java.lang.ArrayIndexOutOfBoundsException
- If beginIndex < 0 or beginIndex > elements.lengthpublic boolean startsWith(RelativePath other)
true
if this RelativePath starts with the name elements in the given RelativePath. If the
given RelativePath has more name elements than this path then false is returned.other
- the RelativePath to compare to.public boolean endsWith(RelativePath other)
true
if this RelativePath end with the name elements in the given RelativePath. If the
given RelativePath has more name elements than this RelativePath then false is returned.other
- the RelativePath to compare to.public boolean startsWith(java.lang.String other)
other
into a RelativePath
using RelativePath(String)
and then uses
startsWith(RelativePath)
to compare the result to this RelativePath.other
- the path to test.other
.public boolean endsWith(java.lang.String other)
other
into a RelativePath
using RelativePath(String)
and then uses
endsWith(RelativePath)
to compare the result to this path.other
- the path to test.other
.public RelativePath resolve(RelativePath other)
other
RelativePath.other
- the RelativePath to concatenate with.public RelativePath resolve(java.lang.String other)
other
into a RelativePath
using RelativePath(String)
and then uses
resolve(RelativePath)
to resolve the result against this path.other
- the String to concatenate with.public boolean isEmpty()
public RelativePath resolveSibling(RelativePath other)
other
will be returned, unless other is null
in which case an
empty RelativePath is returned.
If this RelativePath is not empty, but other
is null
or empty, the parent of this RelativePath
will be returned.
If neither this RelativePath and other are empty, getParent.resolve(other)
will be returned.other
- the RelativePath to resolve as sibling.java.lang.IllegalArgumentException
- If the RelativePath can not be resolved as a sibling to this RelativePath.public RelativePath relativize(RelativePath other)
other
.other
- the RelativePath to relativize.java.lang.IllegalArgumentException
- If the path can not be relativized to this path.public java.util.Iterator<RelativePath> iterator()
Iterator
that returns all possible sub RelativePaths of this RelativePath, in order of increasing length.
For example, for the RelativePath "/a/b/c/d" the iterator returns "/a", "/a/b", "/a/b/c", "/a/b/c/d".iterator
in interface java.lang.Iterable<RelativePath>
public java.lang.String getRelativePath()
String
representation of this RelativePath interpreted as a relative path.
A relative path does not start with a separator.public java.lang.String getAbsolutePath()
String
representation of this RelativePath interpreted as an absolute path.
An absolute path starts with a separator.public RelativePath normalize()
"."
(indicating the current directory) and ".."
(indicating the
parent directory).
Note that the resulting normalized path does may still contain ".."
elements which are not redundant.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object