public abstract class Path extends Object
CanonicalPath or RelativePath.
The path can be iterated both ways either from the current segment up from the root down to the current segment
using the ascendingIterator() or descendingIterator() respectively. The Iterable interface
is implemented using the ascendingIterator().
The up() and down() methods can also be used to get at the paths of the ancestors in an
easy manner. Note though, that these methods don't do any "database lookup" of any sort. They merely work with
the path of the first path instance created.
The following examples illustrate the behavior of up() and down() methods:
CanonicalPath p = CanonicalPath.of().tenant("t").environment("e").resource("r").build();
p.down(); // == undefined (p.down().isDefined() == false)
p.up(); // == t/e
p.up(2); // == t
p.up().up(2); // == undefined
p.up().down(); // == t/e/r
p.up().up().down(); // == t/e
p.up().down().down(); // == undefined
The serialized form of the path has the following format:
type;id/type;id/type;id
I.e. each of the path segments consists of the type of the element it represents followed by the id of the element.
The type of the entity is one of:
In addition to that, the relative paths can contain the special "up" token - .. - instead of the
type:id pair. E.g. a relative path may look like this: ../e;production/r;myResource.
| Modifier and Type | Class and Description |
|---|---|
static class |
Path.Extender
While
CanonicalPath.Builder or RelativePath.Builder provide compile-time-safe canonical path
construction, this class provides the same behavior at runtime, throwing IllegalArgumentExceptions if
the segments being added to a path are invalid in given context. |
protected static interface |
Path.ExtenderConstructor |
static class |
Path.HintedTypeProvider
This is a type provider (
Path.TypeProvider) implementation that tries
to deduce the types on the path based on the current position and the intended type of the final segment of
the path. |
static class |
Path.Segment |
static class |
Path.StructuredDataHintingTypeProvider |
static interface |
Path.TypeProvider
An interface that is used to help parsing partially untyped path strings.
|
| Modifier and Type | Field and Description |
|---|---|
protected int |
endIdx |
protected List<Path.Segment> |
path |
static char |
PATH_DELIM |
protected int |
startIdx |
static char |
TYPE_DELIM |
| Modifier and Type | Method and Description |
|---|---|
Iterator<? extends Path> |
ascendingIterator() |
Iterator<? extends Path> |
descendingIterator() |
Path |
down()
If this path was created by going
up from another path, then this method can be used to go back
down to the previous paths representing some child resource of the resource represented by this path object. |
Path |
down(int distance)
If this path was created by going
up from another path, then this method can be used to go back
down n steps to the previous paths representing some (grand-)child resource of the resource represented by
this path object. |
boolean |
equals(Object o) |
static Path |
fromPartiallyUntypedString(String path,
CanonicalPath canonicalPathsOrigin,
CanonicalPath relativePathsOrigin,
SegmentType intendedFinalType)
This is mostly meant as a helper to REST API.
|
static Path |
fromPartiallyUntypedString(String path,
Path.TypeProvider typeProvider)
Parses the provided path using the type provider (
Path.TypeProvider)
to figure out the types of segments that don't explicitly mention it. |
static Path |
fromString(String path) |
int |
getDepth() |
List<Path.Segment> |
getPath()
Get the full path represented as an array of the individual segments.
|
Path.Segment |
getSegment() |
Path.Segment |
getTop() |
int |
hashCode() |
boolean |
isCanonical() |
boolean |
isDefined()
Checks whether the path is well-formed.
|
protected boolean |
isParentOf(Path other) |
boolean |
isRelative() |
abstract Path.Extender |
modified() |
protected abstract Path |
newInstance(int startIdx,
int endIx,
List<Path.Segment> segments) |
abstract CanonicalPath |
toCanonicalPath()
Tries to convert this path to a canonical path.
|
abstract RelativePath |
toRelativePath()
Tries to convert this path to a relative path.
|
String |
toString() |
Path |
up()
Returns a path corresponding to the direct ancestor of the resource represented by this path object.
|
Path |
up(int distance)
Returns a path corresponding to the n-th ancestor in the hierarchy.
|
public static final char TYPE_DELIM
public static final char PATH_DELIM
protected final List<Path.Segment> path
protected final int startIdx
protected final int endIdx
public static Path fromPartiallyUntypedString(String path, Path.TypeProvider typeProvider)
Path.TypeProvider)
to figure out the types of segments that don't explicitly mention it.
This is mainly geared at REST API in which this is used to parse the relative paths out of URIs in which the type of some segments can be easily deduced from the endpoint address.
path - the path to parsetypeProvider - the type provider used to figure out types of segments that don't explicitly mention itpublic static Path fromPartiallyUntypedString(String path, CanonicalPath canonicalPathsOrigin, CanonicalPath relativePathsOrigin, SegmentType intendedFinalType)
canonicalPathOrigin together with the
intendedFinalType will be used to construct a full canonical path from the potentially untyped input.
If the input path is relative, the relativePathsOrigin will be used instead.path - the potentially partially untyped input pathcanonicalPathsOrigin - the origin to "prefix" the path if it is canonicalrelativePathsOrigin - the origin to resolve the relative path against (if the input path is relative)intendedFinalType - the intended type of the final segment of the pathprotected abstract Path newInstance(int startIdx, int endIx, List<Path.Segment> segments)
public abstract RelativePath toRelativePath()
public abstract CanonicalPath toCanonicalPath()
IllegalArgumentException - if this instance is a relative path and it cannot be converted to canonical pathprotected boolean isParentOf(Path other)
public abstract Path.Extender modified()
public boolean isCanonical()
CanonicalPath, false otherwisepublic boolean isRelative()
RelativePath, false otherwisepublic boolean isDefined()
up() or down() on the path can render it
undefined if it is traversed "too far" in either of the directions.public Path up()
undefined.public Path up(int distance)
distance - the distance of the ancestor from the resource represented by this path object.undefined.public Path down()
up from another path, then this method can be used to go back
down to the previous paths representing some child resource of the resource represented by this path object.undefined.public Path down(int distance)
up from another path, then this method can be used to go back
down n steps to the previous paths representing some (grand-)child resource of the resource represented by
this path object.distance - the distance from this path to the child pathundefined.public int getDepth()
isDefined()).public Path.Segment getTop()
defined.public Path.Segment getSegment()
defined. E.g. if this
path represents "a/b/c" then the segment returned from this method is "c"public List<Path.Segment> getPath()
undefined.public Iterator<? extends Path> ascendingIterator()
public Iterator<? extends Path> descendingIterator()
Copyright © 2014–2016 Red Hat, Inc.. All rights reserved.