An instance consists of a root and given path names under that root. If the root is null
then the path
is relative. The root can be one of the following format:
- Simple
"/"
character as a String. Matching the Unix root drive semantics. - A root string in a drive format similar to Windows semantics. The drive name can have multiple characters, and
ends with the colon
':'
character. The drive letters are lowercase and in the range of'a' - 'z'
. E.g.:"c:"
,"drive:"
.
When a path is constructed, the root name is always normalized to a lowercase format.
When parsing paths, they can contain the "."
and ".."
path names which represent the
current and the parent paths accordingly. Absolute paths cannot escape their root name using the ".."
path name. The paths are normalized during their construction.
Relative paths can contain only the special ".."
name at the start of it. Intermediate ".."
names are normalized during resolution.
Absolute paths will not contains any of the above special path names.
"."
names are never present in any path as they are omitted during construction.
All methods in this class work in a case-sensitive manner unless indicated accordingly.
When an instance is constructed all backslash characters are treated as forward slash.
Examples for paths:
/home/User
c:/Users/User
drive:
- Relative:
dir/child
- Relative:
../sibling
- Relative:
../in/parent/tree
- Automatically normalized relative:
some/../directory/tree
will be normalized todirectory/tree
public static final SakerPath | Single instance for an empty path. |
public static final SakerPath | Single instance for the first absolute path that is ordered by the Comparable contract of this class. |
public static final SakerPath | Single instance for the first path that is ordered by the Comparable contract of this class which root is
not the slash drive. |
public static final SakerPath | Single instance for a relative parent path. |
public static final SakerPath | Singleton instance that represents the slash root. |
public static final String | ROOT_SLASH = "/" Path name representing the forward slash root. |
public | For Externalizable. |
public SakerPath | Appends the parameter relative path to this path. |
public static Builder | builder() Creates a relative path builder. |
public static Builder | Creates a path builder with the given root. |
public SakerPath | clone() Shallow clones this path instance. |
public int | Compares this path to the parameter. |
public int | Compares this path to the argument in a case-insensitive manner. |
public boolean | Check if the parameter is a path and represents the same location. |
public boolean | Equals method with already known type of the parameter. |
public boolean | equalsIgnoreCase( Check if this path equals the argument in a case-insensitive manner. |
public SakerPath | Forces the path to be relative by removing any root if present. |
public int | getCommonNameCount( Counts how many common starting path names does this and the parameter have. |
public SakerPath | getCommonSubPath( Returns the common path of this and the parameter path. |
public String | Gets the last path name of this path if it represents a valid file name. |
public String | Gets the last path name in this path. |
public String | getName( Gets the name at the specified index. |
public String[] | Returns an array copy of the path names of this path. |
public int | Gets the path name count in this path. |
public List< | Returns an unmodifiable list of this path's names. |
public List< | getNameList( Returns an unmodifiable list of this path's names in the given range. |
public SakerPath | Returns the path which represents the parent of this path or null if it cannot exist. |
public String[] | Returns an array copy of the optional root and path names of this path. |
public List< | Returns an unmodifiable list of this path's optional root and path names of this path. |
public String | getRoot() Gets the root for this path. |
public SakerPath | Returns a path that contains only the root of this path. |
public int | hashCode() Returns a hash code value for the object. |
public int | indexOfName( Finds the first occurence of the parameter path name in this path. |
public boolean | Returns true if the path is absolute. |
public boolean | isChildPath( Checks if the argument path represents a location that is under this path. |
public boolean | Returns if this is relative and resolving it against an other path will not escape to its parent
path. |
public boolean | Returns true if the path is relative. |
public boolean | isRelativizable( Checks if the parameter path can be relativized against this path. |
public static boolean | isSlashCharacter( Checks if the parameter character can be considered as a path separator slash character. |
public static boolean | Checks if the parameter is a valid path name. |
public static boolean | Checks if the parameter has a valid root name format. |
public Iterable< | Creates an iterable that creates iterators for the path names in this instance. |
public ListIterator< | Creates an iterator for the path names in this instance. |
public ListIterator< | nameIterator( Creates an iterator for the path names starting at a given index. |
public SakerPath | Returns the next sibling path in the natural order specified by compareTo( |
public SakerPath | Returns the first subpath that starts with this path specified by the natural order. |
public static String | normalizeRoot( Normalizes the parameter root for unified representation. |
public Iterable< | Creates an iterable that creates iterators for the root and path names in this instance. |
public Iterator< | Creates an iterator for the root and path names in this instance. |
public SakerPath | Promotes the first path name of this relative path to construct an absolute one. |
public void | The object implements the readExternal method to restore its
contents by calling the methods of DataInput for primitive
types and readObject for objects, strings and arrays. |
public SakerPath | relativize( Relativizes this path against the parameter. |
public SakerPath | replaceRoot( Constructs a path which has the parameter as root. |
public SakerPath | Resolves the given path names against this path. |
public SakerPath | Resolves the given path names against this path. |
public SakerPath | Resolves the given relative argument against this path. |
public SakerPath | Resolves the given relative argument against this path. |
public SakerPath | Resolves the given path names against this path. |
public SakerPath | resolveSibling( Resolves the path to a sibling name. |
public static SakerPath | singleRelative( Creates a relative path with a single path name. |
public boolean | startsWith( Checks if this path starts with the parameter path. |
public SakerPath | subPath( Creates a relative subpath starting from the given index. |
public SakerPath | subPath( Creates a relative subpath in the given range. |
public SakerPath | Creates a subpath starting from the given index with a specific root. |
public SakerPath | Creates a subpath in the given range with a specific root. |
public SakerPath | Converts this path to an all lowercase representation. |
public SakerPath | toLowerCase( Converts this path to an all lowercase representation using the specified locale. |
public String | toString() Converts this path to a String. |
public String | Converts this path to string, but does not include the root if any. |
public SakerPath | tryRelativize( Tries to relativize this path against the parameter. |
public SakerPath | tryResolve( Tries to resolve the parameter path against this path. |
public static SakerPath | Parses the parameter String and creates a path. |
public static SakerPath | Creates a path from the given path argument. |
public static SakerPath | Parses the parameter String and resolves it against the parameter path is it is relative. |
public void | The object implements the writeExternal method to save its contents
by calling the methods of DataOutput for its primitive values or
calling the writeObject method of ObjectOutput for objects, strings,
and arrays. |
All relative paths are ordered before this instance in the natural order.
All relative paths and all slash root paths are ordered before this instance in the natural order.
This instance does not represent a valid path for use.
Creates the empty path.
Appending differs from the resolving only that the resulting path is not normalized. It is the responsibility of the user to provide a path that is forward relative.
".."
).
The parameter might be null
to construct a relative path.
All the backing fields are the same for the new instance as this one.
this
path to the parameter. Relative paths are ordered first.
This method compares the root and the path names sequentially. Shorter paths ordered first.
The method works in a case-sensitive manner.
this
path to the argument in a case-insensitive manner.This method works in a case-sensitive manner.
true
if this object is the same as the obj argument; false
otherwise.true
if the paths equal in a case-insensitive manner.This method can be used to construct a path which contains the same names as this but has no root assigned.
The resulting path will be relative.
The method returns this
if this
is already relative.
This method computes how many common starting path names does this path have with the parameter.
If the paths have different roots, then the result will be -1.
Else this method will return the number of matching path names at the start of both paths.
This works in the same way as getCommonNameCount(
If the roots differ then the result will be null
.
null
if the roots differ.The last path name represents the file name of the location represented by this path.
If this
path is relative and only consists of ".."
names then the result will be
null
as there is no explicit file name defined.
null
if the file name cannot be determined.
This method is similar to getFileName(), but does not examine the returned name if it is actually a
valid file name. If the last name is ".."
then it will be returned.
null
if this path contains none.null
if it cannot exist.
The parent of a path is determined by resolving the ".."
path name against it. If the parent path
cannot exist (e.g. this
is a simple root without subfolders like "/"
or
"c:"
) this function returns null
.
Relative paths always have parent paths.
null
if it cannot exist.The root name will be the first element in the array if the path is absolute.
If the path is relative this method returns the same as getNameArray().
The resulting path will contain the root of this
path and have no path names assigned. If this path
is already contains no path names the result is this
.
If this
path is relative then the result will be the empty path instance.
The general contract of hashCode
is:
- Whenever it is invoked on the same object more than once during an execution of a Java application, the
hashCode
method must consistently return the same integer, provided no information used inequals
comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)
method, then calling thehashCode
method on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal according to the
Object.equals(
Object) method, then calling thehashCode
method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by class Object
does return distinct
integers for distinct objects. (This is typically implemented by converting the internal address of the object
into an integer, but this implementation technique is not required by the Java™ programming language.)
this
path.true
if the path is absolute.
It will only be true
if getRoot() is null
.
true
if the path is absolute.this
path.
This method works in the same way as startsWith(
true
if the argument is a child path of this
.this
is relative and resolving it against an other path will not escape to its parent
path.
This method returns true
if resolving this path against any given path X to result R, then
R.startsWith(X)
will return true
.
Examples by resolving against c:/Users
:
- Forward relative:
dir/subdir -> c:/Users/dir/subdir
- Forward relative:
dir/.. -> c:/Users
- Forward relative:
dir/../otherdir -> c:/Users/otherdir
- Not forward relative:
../dir -> c:/dir
true
if this path is forward relative.true
if the path is relative.
It will only be true
if getRoot() is not null
.
true
if the path is relative.
This method requires the following conditions to be met to return true
:
- Both path have the same root.
- If the paths are relative then
this
path must have less or equal number of".."
path names at the start of it than the parameter.E.g.
"../dir"
is not relativizable against"some/otherdir"
as a path cannot be constructed in order to navigate outside of the".."
name at the start.
true
if the paths are relativizable.true
if the parameter equals '\\'
or '/'
.
Returns true
if it doesn't contain any directory separators and colons (':'
).
true
if it is a valid path name.Valid root name formats are:
- Single forward (
'/'
) or backward ('\\'
) slash character. - Drive format matching the following regex:
"[a-zA-Z]+:"
true
if it is a valid root name.The iterable will not contain the root name. See pathIterable() for including the root too.
The iterator will not contain the root name. See pathIterator() for including the root too.
It is ensured that this.compareTo(result) < 0
is always true
. Any other path that
compares greater than this
and less than the result of this function is a subpath of
this
path.
The resulting path is not semantically correct, it should not be used with files, and should be restricted for ordering comparisons.
this
path specified by the natural order.
It is ensured that this.compareTo(result) < 0
is always true
.
The resulting path is not semantically correct, it should not be used with files, and should be restricted for ordering comparisons.
If the parameter is "\\"
then it will return "/"
.
In any other case the parameter will be converted to lowercase and any trailing slashes will be removed. It is ensured that the parameter is in a valid root format defined by this class.
null
.If this path is absolute then the first element will be the root name.
If this path is relative this call is the same as nameIterator();
this
relative path to construct an absolute one. This method takes the first path name in this path and promotes it to be the root of the newly constructed one. The new root will be removed from the list of path names and will not be duplicated.
this
path against the parameter. The result of this operation constructs a path which is resolved against this will result in the parameter path.
The following will be true
for any two relativizable paths:
SakerPath first = ...; SakerPath other = ...; // the following is true: first.resolve(first.relativize(other)).equals(other);Examples:
"/home"
relativized against"/home/user"
is"user"
"/home/user"
relativized against"/home"
is".."
"/home/user"
relativized against"/home/user"
is""
"/home/user"
relativized against"/home/john"
is"../john"
The parameter root is normalized and can be null
to construct a relative path with the current
names.
Any directory separator characters are normalized.
Any directory separator characters are normalized.
this
.
Path resolution is a binary operation which results in a single path that is the result of the first path and the
second path concatenated. During concatenation any semantically significant path names are normalized
("."
and ".."
)
One can look at this process as navigating to the first path in the filesystem, then navigating according to the second path. The result path is taken using the current path after the navigation.
If this path is absolute, and the argument would escape the root of this path, then an
InvalidPathFormatException is thrown. (E.g.: this path is /home
and argument is
../../file
)
this
.Any directory separator characters are normalized.
Sibling resolution is taking the parent of this
and then resolving the parameter against it.
The sibling resolution will not escape root boundaries and works for relative paths too.
This method is generally useful when a direct sibling of a path is needed.
E.g.
Sibling of "/home/user"
for "john"
is "/home/john"
Sibling of "/home/user"
for "john/content"
is "/home/john/content"
Sibling of "../directory"
for "second"
is ../second"
The resulting path will be relative and contain only the parameter path name.
null
.
Returns true
if both paths have the same roots and all of the path names of the parameter occurs at
the start of this
path.
This method works in a case-sensitive manner.
null
.null
.The default locale is used to convert each character of the path.
Same as:
toLowerCase(Locale.getDefault())
As paths have a case-sensitive representation, it may be useful to convert them to a lowercase representation when comparing them for equality in some cases.
null
.'/'
).
Passing the result of this method to valueOf(this
.
Converting a path that contains only a single drive root will not end in forward slash.
this
path against the parameter. If the paths are not relativizable, the parameter path is returned.
If the parameter is not relative, then it is returned without modification. Else the parameter path is resolved
against this
.
Equivalent to calling valueOf(null
relative resolve parameter.
null
.
The resulting path will be relative only if the argument path is relative. Roots are normalized and extraneous
"."
and ".."
path names are normalized.
null
.This function parses the passed String parameter and constructs a valid immutable SakerPath instance. The path names are semantically checked and an exception is thrown if they are in an illegal format.
The parsed path may be relative or absolute. If it is relative then it will be resolved against the passed path
parameter if not null
.
null
.null
.