Package org.gradle.api.file
Class RelativePath
- java.lang.Object
-
- org.gradle.api.file.RelativePath
-
- All Implemented Interfaces:
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.
RelativePathinstances are immutable.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static RelativePathEMPTY_ROOT
-
Constructor Summary
Constructors Constructor Description RelativePath(boolean endsWithFile, String... segments)Creates aRelativePath.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RelativePathappend(boolean endsWithFile, String... segments)Appends the given names to the end of this path.RelativePathappend(RelativePath other)Appends the given path to the end of this path.charcharAt(int index)intcompareTo(RelativePath o)booleanequals(Object o)FilegetFile(File baseDir)StringgetLastName()RelativePathgetParent()Returns the parent of this path.StringgetPathString()String[]getSegments()inthashCode()booleanisFile()intlength()static RelativePathparse(boolean isFile, String path)static RelativePathparse(boolean isFile, RelativePath parent, String path)RelativePathplus(RelativePath other)Appends the given path to the end of this path.RelativePathprepend(String... segments)Prepends the given names to the start of this path.RelativePathreplaceLastName(String name)Returns a copy of this path, with the last name replaced with the given name.ListIterator<String>segmentIterator()CharSequencesubSequence(int start, int end)StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
-
-
-
Field Detail
-
EMPTY_ROOT
public static final RelativePath EMPTY_ROOT
-
-
Constructor Detail
-
RelativePath
public RelativePath(boolean endsWithFile, String... segments)Creates aRelativePath.- Parameters:
endsWithFile- - if true, the path ends with a file, otherwise a directory
-
-
Method Detail
-
getSegments
public String[] getSegments()
-
segmentIterator
public ListIterator<String> segmentIterator()
-
isFile
public boolean isFile()
-
getPathString
public String getPathString()
-
length
public int length()
- Specified by:
lengthin interfaceCharSequence
-
charAt
public char charAt(int index)
- Specified by:
charAtin interfaceCharSequence
-
subSequence
public CharSequence subSequence(int start, int end)
- Specified by:
subSequencein interfaceCharSequence
-
getLastName
public String getLastName()
-
toString
public String toString()
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
getParent
public RelativePath getParent()
Returns the parent of this path.- Returns:
- The parent of this path, or null if this is the root path.
-
parse
public static RelativePath parse(boolean isFile, String path)
-
parse
public static RelativePath parse(boolean isFile, RelativePath parent, String path)
-
replaceLastName
public RelativePath replaceLastName(String name)
Returns a copy of this path, with the last name replaced with the given name.
- Parameters:
name- The name.- Returns:
- The path.
-
append
public RelativePath append(RelativePath other)
Appends the given path to the end of this path.
- Parameters:
other- The path to append- Returns:
- The new path
-
plus
public RelativePath plus(RelativePath other)
Appends the given path to the end of this path.
- Parameters:
other- The path to append- Returns:
- The new path
-
append
public RelativePath append(boolean endsWithFile, String... segments)
Appends the given names to the end of this path.- Parameters:
segments- The names to append.endsWithFile- when true, the new path refers to a file.- Returns:
- The new path.
-
prepend
public RelativePath prepend(String... segments)
Prepends the given names to the start of this path.- Parameters:
segments- The names to prepend- Returns:
- The new path.
-
compareTo
public int compareTo(RelativePath o)
- Specified by:
compareToin interfaceComparable<RelativePath>
-
-