Serializable
, CharSequence
, Comparable<RelativePath>
public class RelativePath extends Object implements Serializable, Comparable<RelativePath>, CharSequence
Represents a relative path from some base directory to a file. Used in file copying to represent both a source and target file path when copying files.
RelativePath
instances are immutable.
Modifier and Type | Field | Description |
---|---|---|
static RelativePath |
EMPTY_ROOT |
Constructor | Description |
---|---|
RelativePath(boolean endsWithFile,
String... segments) |
Creates a
RelativePath . |
Modifier and Type | Method | Description |
---|---|---|
RelativePath |
append(boolean endsWithFile,
String... segments) |
Appends the given names to the end of this path.
|
RelativePath |
append(RelativePath other) |
Appends the given path to the end of this path.
|
char |
charAt(int index) |
|
int |
compareTo(RelativePath o) |
|
boolean |
equals(Object o) |
|
File |
getFile(File baseDir) |
|
String |
getLastName() |
|
RelativePath |
getParent() |
Returns the parent of this path.
|
String |
getPathString() |
|
String[] |
getSegments() |
|
int |
hashCode() |
|
boolean |
isFile() |
|
int |
length() |
|
static RelativePath |
parse(boolean isFile,
String path) |
|
static RelativePath |
parse(boolean isFile,
RelativePath parent,
String path) |
|
RelativePath |
plus(RelativePath other) |
Appends the given path to the end of this path.
|
RelativePath |
prepend(String... segments) |
Prepends the given names to the start of this path.
|
RelativePath |
replaceLastName(String name) |
Returns a copy of this path, with the last name replaced with the given name.
|
ListIterator<String> |
segmentIterator() |
|
CharSequence |
subSequence(int start,
int end) |
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
chars, codePoints
public static final RelativePath EMPTY_ROOT
public RelativePath(boolean endsWithFile, String... segments)
RelativePath
.endsWithFile
- - if true, the path ends with a file, otherwise a directorypublic String[] getSegments()
public ListIterator<String> segmentIterator()
public boolean isFile()
public String getPathString()
public int length()
length
in interface CharSequence
public char charAt(int index)
charAt
in interface CharSequence
public CharSequence subSequence(int start, int end)
subSequence
in interface CharSequence
public String getLastName()
public String toString()
toString
in interface CharSequence
toString
in class Object
public RelativePath getParent()
public static RelativePath parse(boolean isFile, String path)
public static RelativePath parse(boolean isFile, @Nullable RelativePath parent, String path)
public RelativePath replaceLastName(String name)
Returns a copy of this path, with the last name replaced with the given name.
name
- The name.public RelativePath append(RelativePath other)
Appends the given path to the end of this path.
other
- The path to appendpublic RelativePath plus(RelativePath other)
Appends the given path to the end of this path.
other
- The path to appendpublic RelativePath append(boolean endsWithFile, String... segments)
segments
- The names to append.endsWithFile
- when true, the new path refers to a file.public RelativePath prepend(String... segments)
segments
- The names to prependpublic int compareTo(RelativePath o)
compareTo
in interface Comparable<RelativePath>