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 classThe raw data structure which backs thePathtype. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe separator of the context from the path components.static final CharsetThe default encoding for converting aPathinto an array of bytes.static final StringThe extension separator.static final StringThe path separator.static final PatternAPatternto match valid path components.static final StringThe wildcard character.static final StringDeprecated.static final StringThe recursive-wildcard character. -
Constructor Summary
ConstructorsConstructorDescriptionPath()Path(Path.ContextAndComponents contextAndComponents) Creates a path with the suppliedPath.ContextAndComponentsCreates aPathwith 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 aPathfrom 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.ContextAndComponentscontextAndComponentsFromPath(String path, String pathSeparator) Returns the root path of this one, preserving context.booleanstatic PathformatPath(String fmt, Object... fmtArgs) Formats aPath.static PathfromByteBuffer(ByteBuffer byteBuffer) Gets a path from aByteBufferstatic PathfromBytes(byte[] pathBytes) Converts the supplied byte array representation to aPathstatic PathfromComponents(String... components) Converts the supplied components to aPath.static PathfromContextAndComponents(HasNodeId hasNodeId, String... components) Gets the aPathfrom the supplied context and components.static PathfromContextAndComponents(String context, String... components) Gets the aPathfrom the supplied context and components.static PathfromPathString(String pathString) Converts the supplied string representation of hePathusingPATH_SEPARATORas the separator.static PathfromPathString(String pathString, String pathSeparator) Converts the supplied string representation of hePathwith 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.ContextAndComponentsinstance for this path.booleanReturns true if thisPathhas a context.inthashCode()booleanisRoot()Returns true if this is a root path (ie having no components).booleanTrue if the path is a wildcard.booleanReturns true if thisPathboth has a context and that context is a wildcard context.booleanTrue if the path is a recursive wildcard.booleanTrue if the path is a wildcard.booleanChecks if this path matches the other path.static booleanChecks if two paths match.parent()Gets anIntStreamof all wild card indices.stripWildcard(int wildcardIndex) Returns a newPathwhich strips all components up to the wildcard index.Returns thisPathas a non-wildcard path.byte[]Gets a byte[] representation of thisPath.Converts thisPathto aByteBuffer.Deprecated.usetoRelativeFilesystemPath()()}Returns the normalized path string with context and default path separator usingPATH_SEPARATORand 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 thisPathhas no context, then this will return the path string w/ a path separator.toString()Returns aPathwhich is a recursive wildcard if this instance is not a recursive wildcard.static PathImplements the conventional valueOf method by invokingPath(java.lang.String).Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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.useWILDCARDThe representation for the wildcard context. Literal value "*", e.g. "*://foo/bar".- See Also:
-
VALID_PATH_COMPONENT
APatternto match valid path components. -
ENCODING
The default encoding for converting aPathinto 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 aPathwith the path relative to the given path.- Parameters:
parent- the parent pathpath- the path
-
Path
Constructs aPathfrom 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
PathvalueOf
-
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 resultingPathis 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 aPaththat 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 aPathwhich 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 thisPathhas a context.- Returns:
- true if this
Pathhas a context
-
isWildcardContext
public boolean isWildcardContext()Returns true if thisPathboth 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.ContextAndComponentsinstance for this path.- Returns:
- the
Path.ContextAndComponentsinstance
-
streamWildcardIndices
Gets anIntStreamof 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 newPathwhich 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 thisPathas 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_SEPARATORand 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.separatorand not including context.- Returns:
- the string representation
-
toRelativeFilesystemPath
Converts this path to a relative FS path.- Returns:
- the
Path
-
toRelativePathString
If thisPathhas no context, then this will return the path string w/ a path separator.- Parameters:
pathSeparator- the path separator- Returns:
- a
Stringrepresenting 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- theHasNodeIdinstance- 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:HasNodeIdReturns aNodeIdfor this instance, throwing an exception if theNodeIdis not valid. This may return null to indicate that theNodeIdis neither valid nor invalid, but rather simply not present.- Specified by:
getNodeIdin interfaceHasNodeId- Returns:
- the
NodeIdor 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 thisPathto aByteBuffer.- Returns:
- this, as a byte buffer
-
equals
-
hashCode
public int hashCode() -
fromComponents
Converts the supplied components to aPath. -
fromContextAndComponents
Gets the aPathfrom the supplied context and components.- Parameters:
context- the contextcomponents- the components- Returns:
- the
Pathinstance
-
fromContextAndComponents
Gets the aPathfrom 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 hePathusingPATH_SEPARATORas the separator. -
fromPathString
Converts the supplied string representation of hePathwith 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