public final class PathUtils
extends java.lang.Object
Each method validates the input, except if the system property {packageName}.SKIP_VALIDATION is set, in which case only minimal validation takes place within this function, so when the parameter is an illegal path, the the result of this method is undefined.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ROOT_NAME |
static java.lang.String |
ROOT_PATH |
Modifier and Type | Method and Description |
---|---|
static @NotNull java.lang.String |
concat(java.lang.String parentPath,
java.lang.String... relativePaths)
Concatenate path elements.
|
static @NotNull java.lang.String |
concat(java.lang.String parentPath,
java.lang.String subPath)
Concatenate path elements.
|
static @Nullable java.lang.String |
concatRelativePaths(java.lang.String... relativePaths)
Relative path concatenation.
|
static boolean |
denotesCurrent(java.lang.String element) |
static boolean |
denotesParent(java.lang.String element) |
static boolean |
denotesRoot(java.lang.String path)
Whether the path is the root path ("/").
|
static @NotNull java.lang.String |
dropIndexFromName(@NotNull java.lang.String name)
Returns the given name without the possible SNS index suffix.
|
static @NotNull java.lang.Iterable<java.lang.String> |
elements(java.lang.String path)
Returns an
Iterable for the path elements. |
static @NotNull java.lang.String |
getAncestorPath(java.lang.String path,
int nth)
Get the nth ancestor of a path.
|
static int |
getDepth(java.lang.String path)
Calculate the number of elements in the path.
|
static @NotNull java.lang.String |
getName(java.lang.String path)
Get the last element of the (absolute or relative) path.
|
static int |
getNextSlash(java.lang.String path,
int index)
Get the index of the next slash.
|
static @NotNull java.lang.String |
getParentPath(java.lang.String path)
Get the parent of a path.
|
static boolean |
isAbsolute(java.lang.String path)
Whether the path is absolute (starts with a slash) or not.
|
static boolean |
isAncestor(java.lang.String ancestor,
java.lang.String path)
Check if a path is a (direct or indirect) ancestor of another path.
|
static boolean |
isValid(java.lang.String path)
Check if the path is valid.
|
static @NotNull java.lang.String |
relativize(java.lang.String parentPath,
java.lang.String path)
Relativize a path wrt.
|
static void |
unifyInExcludes(java.util.Set<java.lang.String> includePaths,
java.util.Set<java.lang.String> excludedPaths)
Unify path inclusions and exclusions.
|
static void |
validate(java.lang.String path)
Check if the path is valid, and throw an IllegalArgumentException if not.
|
public static final java.lang.String ROOT_PATH
public static final java.lang.String ROOT_NAME
public static boolean denotesRoot(java.lang.String path)
path
- the pathpublic static boolean denotesCurrent(java.lang.String element)
element
- The path segment to check for being the current elementtrue
if the specified element equals "."; false
otherwise.public static boolean denotesParent(java.lang.String element)
element
- The path segment to check for being the parent elementtrue
if the specified element equals ".."; false
otherwise.public static boolean isAbsolute(java.lang.String path)
path
- the path@NotNull public static @NotNull java.lang.String getParentPath(java.lang.String path)
path
- the path@NotNull public static @NotNull java.lang.String getAncestorPath(java.lang.String path, int nth)
If nth <= 0
, the path argument is returned as is.
path
- the pathnth
- indicates the ancestor level for which the path should be
calculated.@NotNull public static @NotNull java.lang.String getName(java.lang.String path)
path
- the complete path@NotNull public static @NotNull java.lang.String dropIndexFromName(@NotNull @NotNull java.lang.String name)
name
- name with a possible SNS index suffixpublic static int getDepth(java.lang.String path)
path
- the path@NotNull public static @NotNull java.lang.Iterable<java.lang.String> elements(java.lang.String path)
Iterable
for the path elements. The root path ("/") and the
empty path ("") have zero elements.path
- the path@NotNull public static @NotNull java.lang.String concat(java.lang.String parentPath, java.lang.String... relativePaths)
parentPath
- the parent pathrelativePaths
- the relative path elements to add@NotNull public static @NotNull java.lang.String concat(java.lang.String parentPath, java.lang.String subPath)
parentPath
- the parent pathsubPath
- the subPath path to add@Nullable public static @Nullable java.lang.String concatRelativePaths(java.lang.String... relativePaths)
relativePaths
- relative pathsnull
if the resulting path is empty.public static boolean isAncestor(java.lang.String ancestor, java.lang.String path)
ancestor
- the ancestor pathpath
- the potential offspring path@NotNull public static @NotNull java.lang.String relativize(java.lang.String parentPath, java.lang.String path)
relativize(parentPath, concat(parentPath, path)) == paths
holds.parentPath
- parent pthpath
- path to relativizepublic static int getNextSlash(java.lang.String path, int index)
path
- the pathindex
- the starting indexpublic static void validate(java.lang.String path)
path
- the pathpublic static boolean isValid(java.lang.String path)
path
- the pathtrue
iff the path is valid.public static void unifyInExcludes(java.util.Set<java.lang.String> includePaths, java.util.Set<java.lang.String> excludedPaths)
includePaths
is only retained if includePaths
contains
none of its ancestors and excludePaths
contains neither of its ancestors nor
that path itself.excludePaths
is only retained if includePaths
contains
an ancestor of that path.includePaths
and excludePaths
by first excluding all paths that have an ancestor or are contained in excludePaths
and then including all paths that have an ancestor or are contained in includePaths
then the result is the same regardless whether the includePaths
and
excludePaths
sets have been run through this method or not.includePaths
- set of paths to be includedexcludedPaths
- set of paths to be excludedCopyright © 2010 - 2020 Adobe. All Rights Reserved