Package org.rapidcontext.core.storage
Class Path
java.lang.Object
org.rapidcontext.core.storage.Path
A data storage path. This class encapsulates the path (directory
plus name) of an object, a file or an index. It also provides
some simple help methods to access and work with the path and to
locate the object addressed by it.
- Version:
- 1.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionCreates a new path to a child index or object.int
depth()
Returns the directory depth.boolean
Checks if this path is identical to another path.static Path
Creates a new path from a string representation (similar to a file system path).int
hashCode()
Returns a hash code for this object.boolean
isHidden()
Checks if this path contains a hidden part.boolean
isIndex()
Checks if this path corresponds to an index.boolean
isRoot()
Checks if this path corresponds to the root index.int
length()
Returns the path length.name()
Returns the name of the last element in the path.name
(int pos) Returns the name of the path element at the specified position.parent()
Creates a new path to the parent index.removePrefix
(Path prefix) Creates a new path with the specified prefix removed.static Path
Resolves a path starting at a parent path.static Path
Resolves a path starting at a parent path.Creates a new path to a sibling index or object.boolean
startsWith
(Path path) Checks if this path starts with the specified path.toIdent
(int pos) Returns an object identifier based on this path.toString()
Returns a string representation of this object.
-
Field Details
-
ROOT
A root path constant. Note that several paths may be root paths, so this is not a unique instance. It is only here for convenience. -
PREFIX_HIDDEN
The prefix for hidden path elements. These paths are normally not included in listings or possible to load.- See Also:
-
-
Method Details
-
from
Creates a new path from a string representation (similar to a file system path).- Parameters:
path
- the string path to parse- Returns:
- the path created
-
resolve
Resolves a path starting at a parent path. Leading and duplicate separator ('/') characters are ignored. A trailing separator ('/') character indicates that the resulting path is an index. Any relative ('../') path components will be resolved to the extent possible.- Parameters:
parent
- the parent index pathpath
- the descendant path- Returns:
- the resolved path
-
resolve
Resolves a path starting at a parent path. Any relative ('../') path components will be resolved to the extent possible.- Parameters:
parent
- the parent index pathpath
- the descendant path- Returns:
- the resolved path
-
toString
Returns a string representation of this object. -
toIdent
Returns an object identifier based on this path. The identifier will start at the specified position in this path.- Parameters:
pos
- the position, from 0 to length()- Returns:
- an object identifier for this path (without prefix)
-
equals
Checks if this path is identical to another path. The two paths will be considered equal if they have the same length, all elements are equal and the index flag is identical. -
hashCode
public int hashCode()Returns a hash code for this object. -
isRoot
public boolean isRoot()Checks if this path corresponds to the root index.- Returns:
- true if the path is for the root index, or false otherwise
-
isIndex
public boolean isIndex()Checks if this path corresponds to an index.- Returns:
- true if the path is an index, or false otherwise
-
isHidden
public boolean isHidden()Checks if this path contains a hidden part.- Returns:
- true if the path is hidden, or false otherwise
-
startsWith
Checks if this path starts with the specified path. All the path elements must match up to the length of the specified path. As a special case, this method will return true if the two paths are identical. It will also return true for a null path.- Parameters:
path
- the path to compare with- Returns:
- true if this path starts with the specified path, or false otherwise
-
depth
public int depth()Returns the directory depth. The root index, and any objects located directly there, have depth zero (0). For each additional sub-level traversed, the depth is increased by one (1). Objects and files in the storage tree will not affect the depth.- Returns:
- the path directory depth
-
length
public int length()Returns the path length. The length contains the number of elements in the path, counting both indices and any named object or file. The length is always greater or equal to the depth.- Returns:
- the path length
-
name
Returns the name of the last element in the path. This is normally the object name.- Returns:
- the object or index name, or null for the root index
-
name
Returns the name of the path element at the specified position. A zero position will return the first element traversed, i.e. the one located in the root.- Parameters:
pos
- the position, from 0 to length()- Returns:
- the name of the element at the specified position, or null if the position is out of range
-
parent
Creates a new path to the parent index.- Returns:
- a new path to the parent index
-
child
Creates a new path to a child index or object.- Parameters:
name
- the child nameisIndex
- the index flag- Returns:
- a new path to a child index or object
-
sibling
Creates a new path to a sibling index or object.- Parameters:
name
- the sibling name- Returns:
- a new path to a sibling index or object
-
removePrefix
Creates a new path with the specified prefix removed.- Parameters:
prefix
- the prefix path to remove- Returns:
- a new path with the common prefix removed
-