Package gw.fs
Class ResourcePath
- java.lang.Object
-
- gw.fs.ResourcePath
-
public class ResourcePath extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected String
_name
protected ResourcePath
_parent
static String
WINDOWS_NETWORK_ROOT
-
Constructor Summary
Constructors Modifier Constructor Description protected
ResourcePath(ResourcePath parent, String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Two ResourcePath objects are considered to be equal if they represent the same leaf path and if their parents are equal.String
getFileSystemPathString()
Returns the path string for this path using the default file system separator, as defined by the File.separator property.String
getName()
Returns the leaf name of this resource path.ResourcePath
getParent()
Returns the parent of this resource path.String
getPathString()
Returns the path string for this path using the / path separator.String
getPathString(String separator)
Returns the path string for this path using the specified path separator.int
hashCode()
boolean
isChild(ResourcePath path)
boolean
isDescendant(ResourcePath path)
ResourcePath
join(String otherPath)
Takes the specified path fragment and joins it with this ResourcePath to create a new ResourcePath.static ResourcePath
parse(String pathString)
String
relativePath(ResourcePath other)
String
relativePath(ResourcePath other, String separator)
-
-
-
Field Detail
-
WINDOWS_NETWORK_ROOT
public static final String WINDOWS_NETWORK_ROOT
- See Also:
- Constant Field Values
-
_parent
protected final ResourcePath _parent
-
_name
protected final String _name
-
-
Constructor Detail
-
ResourcePath
protected ResourcePath(ResourcePath parent, String name)
-
-
Method Detail
-
parse
public static ResourcePath parse(String pathString)
-
getName
public String getName()
Returns the leaf name of this resource path. If this path object represents the path "/usr/local/bin", then the getName() method will return the String "bin". In the case of the root path element, this method will return the empty string for the unix filesystem root and a windows drive letter, normalized to upper case, with no trailing path separator for a windows path root. This method will never return a null value.- Returns:
- the name of the last element of the path.
-
getParent
public ResourcePath getParent()
Returns the parent of this resource path. If this path object represents the root of the filesystem, this method will return null.- Returns:
- the parent of this ResourcePath
-
getPathString
public String getPathString()
Returns the path string for this path using the / path separator.- Returns:
- the path string for this path using the / path separator.
- See Also:
getPathString(String)
-
getFileSystemPathString
public String getFileSystemPathString()
Returns the path string for this path using the default file system separator, as defined by the File.separator property.- Returns:
- the path string for this path using the default file system separator
- See Also:
getPathString(String)
-
getPathString
public String getPathString(String separator)
Returns the path string for this path using the specified path separator. The path constructed will begin with the root of the path, which will be one of:- A windows drive letter, normalized to upper case, followed by : and the separator
- The windows network path start \\
- Just the separator, in the case of the unix root
- C:\temp\downloads
- /
- \\files\documents
- Parameters:
separator
- the separator to use when constructing the path- Returns:
- the path string for this path using the specified path separator
-
join
public ResourcePath join(String otherPath)
Takes the specified path fragment and joins it with this ResourcePath to create a new ResourcePath. The specified path can use either \ or / separator characters (or a mix of the two), and it can include . or .. elements in the path, which will be traversed appropriately. The path can start and/or end with a separator character, but it should not start with a windows drive letter or network root. The resulting path will have the same root as this path. Some examples:- "/usr/local".join("lib/java") -> "/usr/local/lib/java"
- "/usr/local".join("/..") -> "/usr"
- "/usr/local".join("/.") -> "/usr/local
- Parameters:
otherPath
- the path to join with this one- Returns:
- a ResourcePath that results from appending otherPath to this path and then normalizing the result
-
equals
public boolean equals(Object obj)
Two ResourcePath objects are considered to be equal if they represent the same leaf path and if their parents are equal. Note that currently the name matching is case-sensitive, even when this is being called on a case-insensitive file system.
-
isChild
public boolean isChild(ResourcePath path)
-
isDescendant
public boolean isDescendant(ResourcePath path)
-
relativePath
public String relativePath(ResourcePath other)
-
relativePath
public String relativePath(ResourcePath other, String separator)
-
-