Package gw.fs
Class ResourcePath
- java.lang.Object
-
- gw.fs.ResourcePath
-
- Direct Known Subclasses:
ResourcePath.ResourcePathHead
public class ResourcePath extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classResourcePath.ResourcePathHead
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String_nameprotected ResourcePath_parentstatic java.lang.StringWINDOWS_NETWORK_ROOT
-
Constructor Summary
Constructors Modifier Constructor Description protectedResourcePath(ResourcePath parent, java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static ResourcePathconstruct(java.lang.String headElement, java.util.List<java.lang.String> fullPath, int nameIndex)private voidconstructPathString(java.lang.StringBuilder sb, java.lang.String separator)booleanequals(java.lang.Object obj)Two ResourcePath objects are considered to be equal if they represent the same leaf path and if their parents are equal.java.lang.StringgetFileSystemPathString()Returns the path string for this path using the default file system separator, as defined by the File.separator property.java.lang.StringgetName()Returns the leaf name of this resource path.ResourcePathgetParent()Returns the parent of this resource path.java.lang.StringgetPathString()Returns the path string for this path using the / path separator.java.lang.StringgetPathString(java.lang.String separator)Returns the path string for this path using the specified path separator.inthashCode()booleanisChild(ResourcePath path)booleanisDescendant(ResourcePath path)ResourcePathjoin(java.lang.String otherPath)Takes the specified path fragment and joins it with this ResourcePath to create a new ResourcePath.private static DynamicArray<java.lang.String>normalizePath(DynamicArray<java.lang.String> pathElements)static ResourcePathparse(java.lang.String pathString)java.lang.StringrelativePath(ResourcePath other)java.lang.StringrelativePath(ResourcePath other, java.lang.String separator)private static DynamicArray<java.lang.String>tokenizePathFragment(java.lang.String pathString, int lastIndex)
-
-
-
Field Detail
-
WINDOWS_NETWORK_ROOT
public static final java.lang.String WINDOWS_NETWORK_ROOT
- See Also:
- Constant Field Values
-
_parent
protected final ResourcePath _parent
-
_name
protected final java.lang.String _name
-
-
Constructor Detail
-
ResourcePath
protected ResourcePath(ResourcePath parent, java.lang.String name)
-
-
Method Detail
-
parse
public static ResourcePath parse(java.lang.String pathString)
-
tokenizePathFragment
private static DynamicArray<java.lang.String> tokenizePathFragment(java.lang.String pathString, int lastIndex)
-
normalizePath
private static DynamicArray<java.lang.String> normalizePath(DynamicArray<java.lang.String> pathElements)
-
construct
private static ResourcePath construct(java.lang.String headElement, java.util.List<java.lang.String> fullPath, int nameIndex)
-
getName
public java.lang.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 java.lang.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 java.lang.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 java.lang.String getPathString(java.lang.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
-
constructPathString
private void constructPathString(java.lang.StringBuilder sb, java.lang.String separator)
-
join
public ResourcePath join(java.lang.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(java.lang.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.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the other object- Returns:
- true if the objects are equal, false otherwise
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
isChild
public boolean isChild(ResourcePath path)
-
isDescendant
public boolean isDescendant(ResourcePath path)
-
relativePath
public java.lang.String relativePath(ResourcePath other)
-
relativePath
public java.lang.String relativePath(ResourcePath other, java.lang.String separator)
-
-