Package com.evolveum.midpoint.prism.path
Interface ItemPath
- All Superinterfaces:
Serializable,ShortDumpable
- All Known Subinterfaces:
UniformItemPath
- All Known Implementing Classes:
ItemName,ItemPathImpl
General interface to ItemPath objects.
A path is viewed as a sequence of path segments.
There are three basic implementations of this interface:
1) ItemPathImpl
===============
This is memory-optimized implementation, minimizing the number of objects created during initialization.
Its segments contain plain objects (e.g. QNames, Longs), mixed with ItemPathSegments where necessary.
Please see ItemPathImpl for details.
2) ItemName
===========
A subclass of QName representing a single-item path. It eliminates the need to create artificial ItemPath objects
to represent a single name.
The problem with ItemPathImpl and ItemName is that equals/hashCode methods do not work on them as one would expect.
There are too many ways how to represent a given path, so one cannot rely on these methods. (QName.equals and hashCode
are final, so they cannot be adapted.)
So, if ItemPath is to be used e.g. as a key in HashMap, the original implementation has to be used.
3) UniformItemPathImpl
======================
This is the original implementation. It sees the path as a sequence of ItemPathSegment objects.
Its advantage is the reasonable equals/hashCode methods. The disadvantage is the memory intensiveness
(creating a high number of tiny objects during path manipulations).
Objects of ItemPath type are designed to be immutable. Modification operations in this API always create new objects.
Naming convention:
* A path consists of SEGMENTS.
* However, when creating the path, we provide a sequence of COMPONENTS.
We transform components into segments by applying a normalization procedure.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescription@NotNull ItemPathReturns all segments except the last one.default ItemPathallUpToIncluding(int i) Returns all segments up to the specified one (including it).default @NotNull ItemPathReturns all segments up to the last named one (excluding).default @NotNull ItemPathReturns a newly created path containing all the segments of this path with added components.default ItemNameIf the path consists of a single name segment (not variable nor special symbol), returns the corresponding value.default @NotNull ItemNameIf the path consists of a single name segment (not variable nor special symbol), returns the corresponding value.static voidstatic voiddefault ItemPath.CompareResultcompareComplex(@Nullable ItemPath otherPath) Compares two item paths.default booleancontainsNameExactly(QName name) Returns true if the path contains the specified name (requires exact match).default booleandefault booleanstatic @NotNull ItemPathCreates the path from given components.static @NotNull ItemPathCreates the path from given components.static @NotNull ItemPathcreateReverse(@NotNull List<?> components) Creates the path from given components in reverse direction.static ItemPathemptyIfNull(ItemPath path) Converts null ItemPath to empty one.static booleanUtility method performingequals(Object, boolean)on two nullable objects.default booleanCompares with the other object either literally (exact = true) or via .equivalent (exact = false).default booleanequivalent(ItemPath path) Checks if the paths are equivalent.static booleanequivalent(ItemPath path1, ItemPath path2) @Nullable Objectfirst()Returns the first segment or null if the path is empty.Returns the first segment as an ItemPath.default @Nullable ItemNameReturns the value of the first name segment or null if there's no name segment.default intReturns the first name segment index; or -1 if there's no such segment.default @NotNull ItemNameThe same as firstName but throws an exception if there's no name.default LongReturns the value of the first segment if it is a Id segment; otherwise throws an exception.default LongReturns the value of the first segment if it is a Id segment; otherwise null.static LongfirstToIdOrNull(ItemPath path) default @NotNull ItemNameReturns the value of the first segment if it is a name segment or throws an exception otherwise.default @Nullable ItemNameReturns the value of the first segment if it is a name segment; otherwise null.static ItemNamefirstToNameOrNull(ItemPath itemPath) default @NotNull QNameReturns the value of the first segment if it is a name segment or throws.default QNameReturns the value of the first segment if it is a variable name segment; otherwise null.static ItemPathfromString(@NotNull String value) PrismContextmust be already initialized in order to call this method.@Nullable ObjectgetSegment(int i) Returns the given path segment.@NotNull List<?>Returns the path segments.booleanisEmpty()Returns true if the path is empty i.e. has no components.static booleanReturns true if the path is null or empty.static booleanReturns true if the segment is the container Id.static booleanisIdentifier(Object segment) Returns true if the segment is the Identifier one ("#").static booleanReturns true if the segment is a name segment.static booleanisNotEmpty(ItemPath path) static booleanReturns true if the segment is the container Id with value of NULL.static booleanisObjectReference(Object segment) Returns true if the segment is the Object Reference one ("@").static booleanReturns true if the segment is the Parent one ("..").default booleanReturns true if the path consists of a single name segment.static booleanReturns true if the segment is a special one: parent, reference, identifier, variable.default booleanChecks if current path is a strict subpath (prefix) of the other path.default booleanisSubPathOrEquivalent(ItemPath otherPath) Check if current path is a subpath (prefix) of the other path or they are equivalent.default booleanisSuperPath(ItemPath otherPath) Check if the other path is a strict subpath (prefix) of this path.default booleanCheck if the other path is a subpath (prefix) of this path or they are equivalent.static booleanisVariable(Object segment) Returns true if the segment is the Variable one ("$...").@Nullable Objectlast()Returns the last segment (or null if the path is empty).lastName()Returns the last name segment value; or null if there's no name segment.default intReturns the last name segment index; or -1 if there's no such segment.@NotNull ItemPathReturns the path containing only the regular named segments.default ItemPathReturns the remainder of "this" path after passing all segments from the other path.@NotNull ItemPathReturns the path with no Id segments.default @NotNull ItemPathrest()Returns the rest of the path (the tail).@NotNull ItemPathrest(int n) Returns the rest of the path (the tail), starting at position "n".static booleansegmentsEquivalent(Object segment1, Object segment2) Returns true if the given segments are equivalent.default voidShow the content of the object intended for diagnostics.intsize()Returns path size i.e. the number of components.default booleanstartsWith(ItemPath prefix) Convenience method with understandable semantics.default booleanReturns true if the path starts with with value Id.default booleanReturns true if the path starts with an identifier (#).default booleanReturns true if the path starts with the standard segment name (i.e.default booleanstartsWithName(QName name) Returns true if the path starts with the specified name (approximate match).default booleanReturns true if the path starts with the value Id of null.default booleanReturns true if the path starts with an object reference (@).default booleanReturns true if the path starts with a parent segment (..).default booleanReturns true if the path starts with variable name ($...).default @NotNull ItemPathRemoves the leading variable segment, if present.subPath(int from, int to) Returns a sub-path from (including) to (excluding) given indices.default ItemPathTypetoBean()static LongReturns a Long value corresponding to the container Id segment, or throw an exception otherwise.static LongtoIdOrNull(Object segment) Returns a Long value corresponding to the container Id segment, or return null otherwise.static @NotNull ItemNameReturns a name corresponding to the name segment, or throw an exception otherwise.static @Nullable QNametoNameNullSafe(@Nullable Object segment) Returns a name corresponding to the name segment, or throw an exception otherwise.static @Nullable ItemNametoNameOrNull(Object segment) Returns a name corresponding to the name segment, or null if it's no name.default StringReturns the standalone representation of this path, i.e. the one with all the namespaces explicitly declared.static QNametoVariableName(Object segment) Returns a name corresponding to the Variable segment, or throw an exception otherwise.Methods inherited from interface com.evolveum.midpoint.util.ShortDumpable
shortDump, shortDumpLazily
-
Field Details
-
EMPTY_PATH
-
SELF_PATH
Self path is just an empty path, but gives it better interpretation in some contexts.
-
-
Method Details
-
create
Creates the path from given components. The components can contain objects of various kinds: - QName -> interpreted as either named segment or a special segment (if the name exactly matches special segment name) - Integer/Long -> interpreted as Id path segment - null -> interpreted as null Id path segment - ItemPathSegment -> interpreted as such - ItemPath, Object[], Collection -> interpreted recursively as a sequence of components Creates the default implementation of ItemPathImpl. Components are normalized on creation as necessary; although the number of object creation is minimized. -
create
Creates the path from given components.- See Also:
-
createReverse
Creates the path from given components in reverse direction. E.g. [a, b, c] -> c/b/a -
fromString
PrismContextmust be already initialized in order to call this method. -
isEmpty
boolean isEmpty()Returns true if the path is empty i.e. has no components. -
isEmpty
Returns true if the path is null or empty. -
isNotEmpty
-
size
int size()Returns path size i.e. the number of components. -
append
Returns a newly created path containing all the segments of this path with added components. -
getSegments
Returns the path segments. Avoid using this method and access segments directly. Instead try to find suitable method in ItemPath interface. NEVER change path content using this method. TODO consider returning unmodifiable collection here (beware of performance implications) -
getSegment
Returns the given path segment.- Throws:
IndexOutOfBoundsException- if the index is out of range
-
toBean
-
compareComplex
Compares two item paths. -
equivalent
Checks if the paths are equivalent. Resolves some differences in path segment representation, e.g. NameItemPathSegment vs QName, null vs missing Id path segments. Does NOT detect higher-level semantic equivalency like activation[1]/administrativeStatus vs activation/administrativeStatus. These are treated as not equivalent. -
equivalent
-
equals
Compares with the other object either literally (exact = true) or via .equivalent (exact = false). -
equals
static boolean equals(@Nullable @Nullable ItemPath itemPath, @Nullable @Nullable Object other, boolean exact) Utility method performingequals(Object, boolean)on two nullable objects. -
isSubPath
Checks if current path is a strict subpath (prefix) of the other path. -
isSubPathOrEquivalent
Check if current path is a subpath (prefix) of the other path or they are equivalent. -
isSuperPath
Check if the other path is a strict subpath (prefix) of this path. The same as otherPath.isSubPath(this). -
isSuperPathOrEquivalent
Check if the other path is a subpath (prefix) of this path or they are equivalent. The same as otherPath.isSubPathOrEquivalent(this). -
startsWith
Convenience method with understandable semantics. -
isName
Returns true if the segment is a name segment. Note that special segments (parent, reference, identifier, variable) are NOT considered to be name segments, even if they can be represented using QName. -
toName
Returns a name corresponding to the name segment, or throw an exception otherwise. -
toNameNullSafe
Returns a name corresponding to the name segment, or throw an exception otherwise. However, accepts null segments. TODO determine whether to keep this method -
toNameOrNull
Returns a name corresponding to the name segment, or null if it's no name. -
isId
Returns true if the segment is the container Id. -
isNullId
Returns true if the segment is the container Id with value of NULL. -
toId
Returns a Long value corresponding to the container Id segment, or throw an exception otherwise. -
toIdOrNull
Returns a Long value corresponding to the container Id segment, or return null otherwise. -
isSpecial
Returns true if the segment is a special one: parent, reference, identifier, variable. -
isParent
Returns true if the segment is the Parent one (".."). -
isObjectReference
Returns true if the segment is the Object Reference one ("@"). -
isIdentifier
Returns true if the segment is the Identifier one ("#"). -
isVariable
Returns true if the segment is the Variable one ("$..."). -
toVariableName
Returns a name corresponding to the Variable segment, or throw an exception otherwise. -
first
Returns the first segment or null if the path is empty. -
rest
Returns the rest of the path (the tail). -
rest
Returns the rest of the path (the tail), starting at position "n". -
firstAsPath
ItemPath firstAsPath()Returns the first segment as an ItemPath. TODO consider the necessity of such method -
remainder
Returns the remainder of "this" path after passing all segments from the other path. (I.e. this path must begin with the content of the other path. Throws an exception when it is not the case.) -
last
Returns the last segment (or null if the path is empty). -
allExceptLast
Returns all segments except the last one. -
allUpToIncluding
Returns all segments up to the specified one (including it). -
allUpToLastName
Returns all segments up to the last named one (excluding). Returns empty path if there's no named segment. -
subPath
Returns a sub-path from (including) to (excluding) given indices. -
startsWithName
default boolean startsWithName()Returns true if the path starts with the standard segment name (i.e. NOT variable nor special symbol). -
startsWithId
default boolean startsWithId()Returns true if the path starts with with value Id. -
startsWithNullId
default boolean startsWithNullId()Returns true if the path starts with the value Id of null. -
startsWithIdentifier
default boolean startsWithIdentifier()Returns true if the path starts with an identifier (#). -
startsWithVariable
default boolean startsWithVariable()Returns true if the path starts with variable name ($...). -
startsWithObjectReference
default boolean startsWithObjectReference()Returns true if the path starts with an object reference (@). -
startsWithParent
default boolean startsWithParent()Returns true if the path starts with a parent segment (..). -
asSingleName
If the path consists of a single name segment (not variable nor special symbol), returns the corresponding value. Otherwise returns null. -
asSingleNameOrFail
If the path consists of a single name segment (not variable nor special symbol), returns the corresponding value. Otherwise throws an exception. -
isSingleName
default boolean isSingleName()Returns true if the path consists of a single name segment. (Not variable nor special symbol.) -
firstToName
Returns the value of the first segment if it is a name segment or throws an exception otherwise. -
firstToQName
Returns the value of the first segment if it is a name segment or throws. parent, id, name, variable -
firstToNameOrNull
Returns the value of the first segment if it is a name segment; otherwise null. -
firstToNameOrNull
-
firstToVariableNameOrNull
Returns the value of the first segment if it is a variable name segment; otherwise null. -
firstToId
Returns the value of the first segment if it is a Id segment; otherwise throws an exception. -
firstToIdOrNull
Returns the value of the first segment if it is a Id segment; otherwise null. -
firstToIdOrNull
-
firstName
Returns the value of the first name segment or null if there's no name segment. NOTE: The difference between firstToName and firstName is that the former always looks at the first segment and tries to interpret it as a name. The latter, however, tries to find the first segment of Name type. -
firstNameOrFail
The same as firstName but throws an exception if there's no name. -
firstNameIndex
default int firstNameIndex()Returns the first name segment index; or -1 if there's no such segment. -
lastName
ItemName lastName()Returns the last name segment value; or null if there's no name segment. -
lastNameIndex
default int lastNameIndex()Returns the last name segment index; or -1 if there's no such segment. -
checkNoSpecialSymbols
-
checkNoSpecialSymbolsExceptParent
-
containsSpecialSymbols
default boolean containsSpecialSymbols() -
containsSpecialSymbolsExceptParent
default boolean containsSpecialSymbolsExceptParent() -
namedSegmentsOnly
Returns the path containing only the regular named segments. -
removeIds
Returns the path with no Id segments. -
stripVariableSegment
Removes the leading variable segment, if present. -
containsNameExactly
Returns true if the path contains the specified name (requires exact match). -
startsWithName
Returns true if the path starts with the specified name (approximate match). -
emptyIfNull
Converts null ItemPath to empty one. -
segmentsEquivalent
Returns true if the given segments are equivalent. -
toStringStandalone
Returns the standalone representation of this path, i.e. the one with all the namespaces explicitly declared. -
shortDump
Description copied from interface:ShortDumpableShow the content of the object intended for diagnostics. This method is supposed to append a compact, human-readable output in a single line. Unlike toString() method, there is no requirement to identify the actual class or type of the object. It is assumed that the class/type will be obvious from the context in which the output is used.- Specified by:
shortDumpin interfaceShortDumpable- Parameters:
sb- StringBuilder to which to a compact one-line content of the object intended for diagnostics by system administrator should be appended.
-