|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--lava.string.PathToolbox
Path string manipulation.
Details: PathToolbox is a collection of functions for manipulating path strings. All paths manipulated by functions in this class are expected to be in Unix format, and all paths are returned in Unix format.
Constructor Summary | |
PathToolbox()
|
Method Summary | |
static java.lang.String |
concatenatePaths(java.lang.String path1,
java.lang.String path2)
Concatenates paths. |
static java.lang.String |
getFilename(java.lang.String path)
Returns last path component. |
static java.lang.String |
getParentPath(java.lang.String path)
Returns parent. |
static boolean |
isAbsolutePath(java.lang.String path)
Determines whether path is absolute. |
static boolean |
isRelativePath(java.lang.String path)
Determines whether path is relative. |
static java.lang.String |
resolveRelativePath(java.lang.String wd,
java.lang.String rel)
Resolves relative path from working directory. |
static java.lang.String |
simplifyPath(java.lang.String path)
Generates shortest equivalent path.. |
static java.lang.String |
toRelativePath(java.lang.String from,
java.lang.String to)
Computes relative path leading from one directory to another. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PathToolbox()
Method Detail |
public static java.lang.String simplifyPath(java.lang.String path)
Details: simplifyPath
modifies the given path name to represent the path's most natural form. For example,
/usr//bin/../local/./bin/
is transformed into
/usr/local/bin
.
Parent directory path components ("..
") and current directory path components (".
") are eliminated wherever possible, and trailing slashes and redundant slashes are always removed (except where the path is simply "/
"). Also, the parent of the root directory is assumed to be itself. If the empty string is supplied, the returned path is "."
path
- the unnormalized path namepublic static java.lang.String getParentPath(java.lang.String path)
Details: getParentPath returns the parent directory of the given path (path). The root directory is its own parent. The returned path is simplified according to the rules described in simplifyPath
.
path
- the pathpublic static java.lang.String getFilename(java.lang.String path)
Details: getFilename returns the last component of the given path (path). If the empty string is supplied, the empty string is returned.
Examples:
input | output |
---|---|
"/usr/local/bin" | "bin" | "/usr/local/." | "." | "../.." | ".." |
path
- the pathpublic static boolean isAbsolutePath(java.lang.String path)
Details: isAbsolutePath
determines whether the given path (path) is an absolute path (in other words, whether the first character is '/').
path
- the pathpublic static boolean isRelativePath(java.lang.String path)
Details: isRelativePath
determines whether the given path (path) is an relative path (in other words, whether the first character is not '/').
path
- the pathpublic static java.lang.String concatenatePaths(java.lang.String path1, java.lang.String path2)
Details: concatenatePaths
concatenates the two path strings together, inserting a slash inbetween them if necessary.
path1
- the first path stringpath2
- the second path stringpublic static java.lang.String resolveRelativePath(java.lang.String wd, java.lang.String rel)
Details: resolves the given relative path (rel) in the context of the given working directory (wd). Specifically,
resolveRelativePath
returns rel if rel is an absolute path, or the concatenation (by concatenatePaths
) of wd and rel otherwise.
wd
- the working directoryrel
- the relative pathpublic static java.lang.String toRelativePath(java.lang.String from, java.lang.String to)
Details: toRelativePath
finds the shortest relative path leading from one directory (from) to another (to). If to is already a relative path, then to is simplified and returned. Otherwise, the relative path from from to to is computed and returned. from is treated as a directory and must be absolute.
from
- the starting directoryto
- the target directory
|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |