Class Path
java.lang.Object
dev.getelements.elements.sdk.cluster.path.Path
- All Implemented Interfaces:
HasNodeId
,Serializable
Represents the path scheme for use in the server.
This implements
HasNodeId
which uses the getContext()
to attempt to derive the NodeId
or
throw an exception if the context does not produce a valid NodeId
.
If the path has a wildcard context, then it returns a null NodeId
.
Created by patricktwohig on 9/4/15.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
The raw data structure which backs thePath
type. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The separator of the context from the path components.static final Charset
The default encoding for converting aPath
into an array of bytes.static final String
The extension separator.static final String
The path separator.static final Pattern
APattern
to match valid path components.static final String
The wildcard character.static final String
Deprecated.static final String
The recursive-wildcard character. -
Constructor Summary
ConstructorsConstructorDescriptionPath()
Path
(Path.ContextAndComponents contextAndComponents) Creates a path with the suppliedPath.ContextAndComponents
Creates aPath
with the path relative to the given path.Parses the path into components and checks for hte wildcard character.Creates a path with components and the wildcard flag.Constructs aPath
from the supplied components. -
Method Summary
Modifier and TypeMethodDescriptionAppends the following path to this path such that the final path is expressed as follows: newPath = this/otherPathappendComponents
(String first) Appends components to the path and returns a newPath
.appendComponents
(String first, String... subsequent) Appends components to the path and returns a newPath
.appendExtension
(String extension) Appends an extension using theEXTENSION_SEPARATOR
.appendExtension
(String extension, String pathSeparator) Appends an extension to thisPath
, using the supplied separator.appendIfWildcard
(Supplier<String> stringSupplier) Appends a single component if this path ends in a wildcard or recursive wildcard, then this method will return a new Path with the result of theSupplier
.Appends a UUID component if this path is a wildcard path.static Path.ContextAndComponents
contextAndComponentsFromPath
(String path, String pathSeparator) Returns the root path of this one, preserving context.boolean
static Path
formatPath
(String fmt, Object... fmtArgs) Formats aPath
.static Path
fromByteBuffer
(ByteBuffer byteBuffer) Gets a path from aByteBuffer
static Path
fromBytes
(byte[] pathBytes) Converts the supplied byte array representation to aPath
static Path
fromComponents
(String... components) Converts the supplied components to aPath
.static Path
fromContextAndComponents
(HasNodeId hasNodeId, String... components) Gets the aPath
from the supplied context and components.static Path
fromContextAndComponents
(String context, String... components) Gets the aPath
from the supplied context and components.static Path
fromPathString
(String pathString) Converts the supplied string representation of hePath
usingPATH_SEPARATOR
as the separator.static Path
fromPathString
(String pathString, String pathSeparator) Converts the supplied string representation of hePath
with the supplied separator string.getComponent
(int index) Gets the component of a Path at the supplied index.Gets the components of this path.Gets the context of thisPath
, or null if no context exists.Gets thePath.ContextAndComponents
instance for this path.boolean
Returns true if thisPath
has a context.int
hashCode()
boolean
isRoot()
Returns true if this is a root path (ie having no components).boolean
True if the path is a wildcard.boolean
Returns true if thisPath
both has a context and that context is a wildcard context.boolean
True if the path is a recursive wildcard.boolean
True if the path is a wildcard.boolean
Checks if this path matches the other path.static boolean
Checks if two paths match.parent()
Gets anIntStream
of all wild card indices.stripWildcard
(int wildcardIndex) Returns a newPath
which strips all components up to the wildcard index.Returns thisPath
as a non-wildcard path.byte[]
Gets a byte[] representation of thisPath
.Converts thisPath
to aByteBuffer
.Deprecated.usetoRelativeFilesystemPath()
()}Returns the normalized path string with context and default path separator usingPATH_SEPARATOR
and including context.toNormalizedPathString
(String pathSeparator) Returns the normalized path string.toNormalizedPathString
(String pathSeparator, boolean shouldIncludeContext) toPathWithContext
(String newContext) Returns a Path which will have the context specified.toPathWithContextIfAbsent
(HasNodeId hasNodeId) Returns a Path which will have the context specified.toPathWithContextIfAbsent
(String newContext) Returns a Path which will have the context specified.toPathWithNodeId
(HasNodeId hasNodeId) Returns a Path without any context.Converts this path to a relative FS path.toRelativePathString
(String pathSeparator) If thisPath
has no context, then this will return the path string w/ a path separator.toString()
Returns aPath
which is a recursive wildcard if this instance is not a recursive wildcard.static Path
Implements the conventional valueOf method by invokingPath(java.lang.String)
.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface dev.getelements.elements.sdk.cluster.id.HasNodeId
getOptionalNodeId
-
Field Details
-
CONTEXT_SEPARATOR
The separator of the context from the path components. Literal value "://", e.g. "myContext://foo/bar".- See Also:
-
PATH_SEPARATOR
The path separator. Literal value "/"- See Also:
-
EXTENSION_SEPARATOR
The extension separator.- See Also:
-
WILDCARD
The wildcard character. Literal value "*"- See Also:
-
WILDCARD_RECURSIVE
The recursive-wildcard character. Literal value "**"- See Also:
-
WILDCARD_CONTEXT_REPRESENTATION
Deprecated.useWILDCARD
The representation for the wildcard context. Literal value "*", e.g. "*://foo/bar".- See Also:
-
VALID_PATH_COMPONENT
APattern
to match valid path components. -
ENCODING
The default encoding for converting aPath
into an array of bytes.
-
-
Constructor Details
-
Path
public Path() -
Path
Parses the path into components and checks for hte wildcard character.- Parameters:
path
- the path as represented by aString
-
Path
Creates aPath
with the path relative to the given path.- Parameters:
parent
- the parent pathpath
- the path
-
Path
Constructs aPath
from the supplied components.- Parameters:
components
- the list of components
-
Path
Creates a path with components and the wildcard flag.- Parameters:
context
- the contextcomponents
- the path components
-
Path
Creates a path with the suppliedPath.ContextAndComponents
- Parameters:
contextAndComponents
- thePath.ContextAndComponents
-
-
Method Details
-
valueOf
Implements the conventional valueOf method by invokingPath(java.lang.String)
.- Parameters:
string
- the path to parse- Returns:
- the
Path
valueOf
-
formatPath
Formats aPath
.- Parameters:
fmt
-fmtArgs
-- Returns:
-
append
Appends the following path to this path such that the final path is expressed as follows: newPath = this/otherPath- Parameters:
otherPath
- the other path to append- Returns:
- a new
Path
, appending the components of this path
-
appendComponents
Appends components to the path and returns a newPath
.- Parameters:
first
- the first component to add- Returns:
- the newly created path.
-
appendComponents
Appends components to the path and returns a newPath
.- Parameters:
first
- the first component to addsubsequent
- the subsequent components- Returns:
- the newly created path.
-
appendIfWildcard
Appends a single component if this path ends in a wildcard or recursive wildcard, then this method will return a new Path with the result of theSupplier
. Otherwise, this method will return this instance as-is. This will avoid invoking the supplier in case the supplier exhausts a system resource, sou- Parameters:
stringSupplier
- a supplier for the component to add.- Returns:
- the newly created path.
-
appendUUIDIfWildcard
Appends a UUID component if this path is a wildcard path.- Returns:
- the newly created path.
-
appendExtension
Appends an extension using theEXTENSION_SEPARATOR
.- Parameters:
extension
- the extension- Returns:
- a new
Path
, applying the supplied extension
-
appendExtension
Appends an extension to thisPath
, using the supplied separator. The final resultingPath
is the result of appending the separator and the extension to the last component of the string.- Parameters:
extension
- the extensionpathSeparator
- the separator- Returns:
- a new
Path
, applying the supplied extension
-
parent
Returns aPath
that is the parent to thisPath
, preserving the context (if any). If this path is the root path (ie having no components), then this will return this object.- Returns:
- the parent
Path
, or this if this is a root path
-
toWildcardRecursive
Returns aPath
which is a recursive wildcard if this instance is not a recursive wildcard. If the path is already a wildcard recursive, then this path will- Returns:
- this
Path
-
isRoot
public boolean isRoot()Returns true if this is a root path (ie having no components).- Returns:
- true if this is a root path
-
contextRootPath
Returns the root path of this one, preserving context.- Returns:
- the root path
-
getContext
Gets the context of thisPath
, or null if no context exists.- Returns:
- the context or null
-
hasContext
public boolean hasContext()Returns true if thisPath
has a context.- Returns:
- true if this
Path
has a context
-
isWildcardContext
public boolean isWildcardContext()Returns true if thisPath
both has a context and that context is a wildcard context.- Returns:
- true if the context is a wildcard context
-
getComponent
Gets the component of a Path at the supplied index. Additionally, this allows for negative numbers indicating the reverse-order index of the list.- Parameters:
index
- the index or reverse-index specified by a netagive integer
-
getComponents
Gets the components of this path.- Returns:
- the components of this path
-
getContextAndComponents
Gets thePath.ContextAndComponents
instance for this path.- Returns:
- the
Path.ContextAndComponents
instance
-
streamWildcardIndices
Gets anIntStream
of all wild card indices.- Returns:
- the wildcard indices
-
getWildcardIndices
-
isWildcard
public boolean isWildcard()True if the path is a wildcard.- Returns:
- true if wildcard, false otherwise
-
isWildcardTerminated
public boolean isWildcardTerminated()True if the path is a wildcard.- Returns:
- true if wildcard, false otherwise
-
isWildcardRecursive
public boolean isWildcardRecursive()True if the path is a recursive wildcard.- Returns:
- true if wildcard, false otherwise
-
stripWildcard
Returns a newPath
which strips all components up to the wildcard index. The wildcard index is the zero indexed n'th position of thePath
. The index may be negative, indicating the wildcard index will be stripped from the end of the indices. If the path has no wildcard components, then this will simply return this object.- Parameters:
wildcardIndex
- >= 0 for the n'th from beginning, <0 for the n'th index from the end- Returns:
- the
Path
-
stripWildcardRecursive
Returns thisPath
as a non-wildcard path. If the path is not a wildcard, this will simply return this object.- Returns:
- this path, stripping the wildcard.
-
matches
Checks if this path matches the other path. Note that this considers wildcards whereas thehashCode()
andequals(Object)
methods determine absolute equality.- Parameters:
other
- the other path- Returns:
- true if this path matches the other
-
toNormalizedPathString
Returns the normalized path string with context and default path separator usingPATH_SEPARATOR
and including context.- Returns:
- the normalized path as a string
-
toFileSystemPathString
Deprecated.usetoRelativeFilesystemPath()
()}Returns the String representation of this Path as a file system path usingFile.separator
and not including context.- Returns:
- the string representation
-
toRelativeFilesystemPath
Converts this path to a relative FS path.- Returns:
- the
Path
-
toRelativePathString
If thisPath
has no context, then this will return the path string w/ a path separator.- Parameters:
pathSeparator
- the path separator- Returns:
- a
String
representing the relative portion of this path.
-
toNormalizedPathString
Returns the normalized path string. Note thattoString()
does not return a properly formatted path. But rather a path useful for debugging and logging information.- Returns:
- the normalized path as a string
-
toNormalizedPathString
- Parameters:
pathSeparator
- the path separatorshouldIncludeContext
- true if the context should be included- Returns:
- the String representing the path
-
toPathWithContext
Returns a Path which will have the context specified.- Parameters:
newContext
- the context- Returns:
- the Path, or this if the context matches
- Throws:
IllegalArgumentException
- if the context mismatches
-
toPathWithContextIfAbsent
Returns a Path which will have the context specified.- Parameters:
hasNodeId
- theHasNodeId
instance- Returns:
- the Path, or this if the context matches
- Throws:
IllegalArgumentException
- if the context mismatches
-
toPathWithContextIfAbsent
Returns a Path which will have the context specified.- Parameters:
newContext
- the context- Returns:
- the Path, or this if the context matches
- Throws:
IllegalArgumentException
- if the context mismatches
-
toPathWithoutContext
Returns a Path without any context.- Returns:
- the Path with no context
-
toPathWithNodeId
-
getNodeId
Description copied from interface:HasNodeId
Returns aNodeId
for this instance, throwing an exception if theNodeId
is not valid. This may return null to indicate that theNodeId
is neither valid nor invalid, but rather simply not present.- Specified by:
getNodeId
in interfaceHasNodeId
- Returns:
- the
NodeId
or null. - Throws:
InvalidNodeIdException
- if this instance is unable to derive aNodeId
-
toString
-
toByteArray
public byte[] toByteArray()Gets a byte[] representation of thisPath
.- Returns:
- the byte array
-
toByteBuffer
Converts thisPath
to aByteBuffer
.- Returns:
- this, as a byte buffer
-
equals
-
hashCode
public int hashCode() -
fromComponents
Converts the supplied components to aPath
. -
fromContextAndComponents
Gets the aPath
from the supplied context and components.- Parameters:
context
- the contextcomponents
- the components- Returns:
- the
Path
instance
-
fromContextAndComponents
Gets the aPath
from the supplied context and components. -
fromBytes
Converts the supplied byte array representation to aPath
- Parameters:
pathBytes
- the bytes of the path- Returns:
- the
Path
-
fromByteBuffer
Gets a path from aByteBuffer
- Parameters:
byteBuffer
- theByteBuffer
- Returns:
- the
Path
-
fromPathString
Converts the supplied string representation of hePath
usingPATH_SEPARATOR
as the separator. -
fromPathString
Converts the supplied string representation of hePath
with the supplied separator string. -
matches
Checks if two paths match.- Parameters:
lhs
-rhs
-- Returns:
-
contextAndComponentsFromPath
public static Path.ContextAndComponents contextAndComponentsFromPath(String path, String pathSeparator)
-
WILDCARD