Package com.evolveum.midpoint.prism.path
Interface ItemPath
- All Superinterfaces:
Serializable
,ShortDumpable
- All Known Subinterfaces:
UniformItemPath
- All Known Implementing Classes:
AttributePath
,InfraItemName
,ItemName
,ItemName.WithoutPrefix
,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
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescription@NotNull ItemPath
Returns all segments except the last one.default ItemPath
allUpToIncluding
(int i) Returns all segments up to the specified one (including it).default @NotNull ItemPath
Returns all segments up to the last named one (excluding).default @NotNull ItemPath
Returns a newly created path containing all the segments of this path with added components.default ItemName
If the path consists of a single name segment (not variable nor special symbol), returns the corresponding value.default @NotNull ItemName
If the path consists of a single name segment (not variable nor special symbol), returns the corresponding value.static void
static void
default ItemPath.CompareResult
compareComplex
(@Nullable ItemPath otherPath) Compares two item paths.default boolean
containsNameExactly
(QName name) Returns true if the path contains the specified name (requires exact match).default boolean
default boolean
static @NotNull ItemPath
Creates the path from given components.static @NotNull ItemPath
Creates the path from given components.static @NotNull ItemPath
createReverse
(@NotNull List<?> components) Creates the path from given components in reverse direction.static ItemPath
emptyIfNull
(ItemPath path) Converts null ItemPath to empty one.static boolean
Utility method performingequals(Object, boolean)
on two nullable objects.default boolean
Compares with the other object either literally (exact = true) or via .equivalent (exact = false).default boolean
equivalent
(ItemPath path) Checks if the paths are equivalent.static boolean
equivalent
(ItemPath path1, ItemPath path2) @Nullable Object
first()
Returns the first segment or null if the path is empty.Returns the first segment as an ItemPath.default @Nullable ItemName
Returns the value of the first name segment or null if there's no name segment.default int
Returns the first name segment index; or -1 if there's no such segment.default @NotNull ItemName
The same as firstName but throws an exception if there's no name.default Long
Returns the value of the first segment if it is a Id segment; otherwise throws an exception.default Long
Returns the value of the first segment if it is a Id segment; otherwise null.static Long
firstToIdOrNull
(ItemPath path) default @NotNull ItemName
Returns the value of the first segment if it is a name segment or throws an exception otherwise.default @Nullable ItemName
Returns the value of the first segment if it is a name segment; otherwise null.static ItemName
firstToNameOrNull
(ItemPath itemPath) default @NotNull QName
Returns the value of the first segment if it is a name segment or throws.default QName
Returns the value of the first segment if it is a variable name segment; otherwise null.static ItemPath
fromString
(@NotNull String value) PrismContext
must be already initialized in order to call this method.@Nullable Object
getSegment
(int i) Returns the given path segment.@NotNull List<?>
Returns the path segments.boolean
isEmpty()
Returns true if the path is empty i.e.static boolean
Returns true if the path is null or empty.static boolean
Returns true if the segment is the container Id.static boolean
isIdentifier
(Object segment) Returns true if the segment is the Identifier one ("#").static boolean
isInfraItem
(QName name) static boolean
isItemOrInfraItem
(Object segment) default boolean
Returns `true` if this path points to a value metadata.static boolean
Returns true if the segment is a name segment.static boolean
isNotEmpty
(ItemPath path) static boolean
Returns true if the segment is the container Id with value of NULL.static boolean
isObjectReference
(Object segment) Returns true if the segment is the Object Reference one ("@").static boolean
Returns true if the segment is the Parent one ("..").default boolean
Returns true if the path consists of a single name segment.static boolean
Returns true if the segment is a special one: parent, reference, identifier, variable.default boolean
Checks if current path is a strict subpath (prefix) of the other path.default boolean
isSubPathOrEquivalent
(ItemPath otherPath) Check if current path is a subpath (prefix) of the other path or they are equivalent.default boolean
isSuperPath
(ItemPath otherPath) Check if the other path is a strict subpath (prefix) of this path.default boolean
Check if the other path is a subpath (prefix) of this path or they are equivalent.static boolean
isVariable
(Object segment) Returns true if the segment is the Variable one ("$...").@Nullable Object
last()
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 int
Returns the last name segment index; or -1 if there's no such segment.@NotNull ItemPath
Returns the path containing only the regular named segments.default ItemPath
Returns the remainder of "this" path after passing all segments from the other path.@NotNull ItemPath
Returns the path with no Id segments.default @NotNull ItemPath
rest()
Returns the rest of the path (the tail).@NotNull ItemPath
rest
(int n) Returns the rest of the path (the tail), starting at position "n".static boolean
segmentsEquivalent
(Object segment1, Object segment2) Returns true if the given segments are equivalent.default void
Show the content of the object intended for diagnostics.int
size()
Returns path size i.e.default boolean
startsWith
(ItemPath prefix) Convenience method with understandable semantics.default boolean
Returns true if the path starts with with value Id.default boolean
Returns true if the path starts with an identifier (#).default boolean
Returns true if the path starts with the standard segment name (i.e.default boolean
startsWithName
(QName name) Returns true if the path starts with the specified name (approximate match).default boolean
Returns true if the path starts with the value Id of null.default boolean
Returns true if the path starts with an object reference (@).default boolean
Returns true if the path starts with a parent segment (..).default boolean
Returns true if the path starts with variable name ($...).default @NotNull ItemPath
Removes the leading variable segment, if present.subPath
(int from, int to) Returns a sub-path from (including) to (excluding) given indices.default ItemPathType
toBean()
static Long
Returns a Long value corresponding to the container Id segment, or throw an exception otherwise.static Long
toIdOrNull
(Object segment) Returns a Long value corresponding to the container Id segment, or return null otherwise.static @NotNull ItemName
Returns a name corresponding to the name segment, or throw an exception otherwise.static @Nullable QName
toNameNullSafe
(@Nullable Object segment) Returns a name corresponding to the name segment, or throw an exception otherwise.static @Nullable ItemName
toNameOrNull
(Object segment) Returns a name corresponding to the name segment, or null if it's no name.default String
Returns the standalone representation of this path, i.e.static QName
toVariableName
(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
PrismContext
must be already initialized in order to call this method. -
isInfraItem
-
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. -
isItemOrInfraItem
-
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). -
isMetadataRelated
default boolean isMetadataRelated()Returns `true` if this path points to a value metadata. Limitations: APPROXIMATE IMPLEMENTATION. It does not detect unqualified metadata paths. It is perhaps safer to skip these than to return false positive information (e.g. when an attribute is called "metadata"). -
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:ShortDumpable
Show 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:
shortDump
in interfaceShortDumpable
- Parameters:
sb
- StringBuilder to which to a compact one-line content of the object intended for diagnostics by system administrator should be appended.
-