public final class PathUtils extends 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 | Method and Description |
---|---|
static String |
concat(String parentPath,
String... relativePaths)
Concatenate path elements.
|
static String |
concat(String parentPath,
String subPath)
Concatenate path elements.
|
static boolean |
denotesCurrent(String element) |
static boolean |
denotesParent(String element) |
static boolean |
denotesRoot(String path)
Whether the path is the root path ("/").
|
static String |
dropIndexFromName(String name)
Returns the given name without the possible SNS index suffix.
|
static Iterable<String> |
elements(String path)
Returns an
Iterable for the path elements. |
static String |
getAncestorPath(String path,
int nth)
Get the nth ancestor of a path.
|
static int |
getDepth(String path)
Calculate the number of elements in the path.
|
static String |
getName(String path)
Get the last element of the (absolute or relative) path.
|
static int |
getNextSlash(String path,
int index)
Get the index of the next slash.
|
static String |
getParentPath(String path)
Get the parent of a path.
|
static boolean |
isAbsolute(String path)
Whether the path is absolute (starts with a slash) or not.
|
static boolean |
isAncestor(String ancestor,
String path)
Check if a path is a (direct or indirect) ancestor of another path.
|
static boolean |
isValid(String path)
Check if the path is valid.
|
static String |
relativize(String parentPath,
String path)
Relativize a path wrt.
|
static void |
validate(String path)
Check if the path is valid, and throw an IllegalArgumentException if not.
|
public static boolean denotesRoot(String path)
path
- the pathpublic static boolean denotesCurrent(String element)
element
- The path segment to check for being the current elementtrue
if the specified element equals "."; false
otherwise.public static boolean denotesParent(String element)
element
- The path segment to check for being the parent elementtrue
if the specified element equals ".."; false
otherwise.public static boolean isAbsolute(String path)
path
- the pathpublic static String getParentPath(String path)
path
- the pathpublic static String getAncestorPath(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.public static String getName(String path)
path
- the complete pathpublic static String dropIndexFromName(String name)
name
- name with a possible SNS index suffixpublic static int getDepth(String path)
path
- the pathpublic static Iterable<String> elements(String path)
Iterable
for the path elements. The root path ("/") and the
empty path ("") have zero elements.path
- the pathpublic static String concat(String parentPath, String... relativePaths)
parentPath
- the parent pathrelativePaths
- the relative path elements to addpublic static String concat(String parentPath, String subPath)
parentPath
- the parent pathsubPath
- the subPath path to addpublic static boolean isAncestor(String ancestor, String path)
ancestor
- the ancestor pathpath
- the potential offspring pathpublic static String relativize(String parentPath, String path)
relativize(parentPath, concat(parentPath, path)) == paths
holds.parentPath
- parent pthpath
- path to relativizepublic static int getNextSlash(String path, int index)
path
- the pathindex
- the starting indexpublic static void validate(String path)
path
- the pathpublic static boolean isValid(String path)
path
- the pathtrue
iff the path is valid."Copyright © 2006 - 2015 Adobe Systems Incorporated. All Rights Reserved"