Package org.forgerock.json
Class JsonPointer
java.lang.Object
org.forgerock.json.JsonPointer
Identifies a specific value within a JSON structure. Conforms with
draft-pbryan-zip-json-pointer-02.
This class is immutable.
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.JsonPointer(Iterable<String> iterable) Constructs a JSON pointer from an iterable collection of reference tokens.JsonPointer(String pointer) Constructs a JSON pointer, identifying the specified pointer value.JsonPointer(String... tokens) Constructs a JSON pointer from an array of reference tokens. -
Method Summary
Modifier and TypeMethodDescriptionchild(int child) Returns a new JSON pointer, which identifies a specified child element of the array identified by this pointer.Returns a new JSON pointer, which identifies a specified child member of the object identified by this pointer.concat(JsonPointer suffix) Creates a new JSON pointer which is a descendant of this JSON pointer.booleanCompares the specified object with this pointer for equality.get(int index) Returns the reference token at the specified position.getValue()Returns the JSON pointer string value.inthashCode()Returns the hash code value for this pointer.head(int endIndex) Returns a pointer which is a subsequence of the path elements contained in this pointer beginning with the first element (0) and ending with the element at positionendIndex-1.booleanisEmpty()Returnstrueif this pointer identifies the root value of a JSON structure.booleanisPrefixOf(JsonPointer candidate) Checks whethercandidateis an extension of this JSON Pointer.iterator()Returns an iterator over the pointer's reference tokens.leaf()Returns the last (leaf) reference token of the JSON pointer, ornullif the pointer contains no reference tokens (i.e.parent()Returns a pointer to the parent of the JSON value identified by this JSON pointer, ornullif the pointer has no parent JSON value (i.e.static JsonPointerConstructs a JSON pointer from an iterable collection of reference tokens.static JsonPointerConstructs a JSON pointer, identifying the specified pointer value.static JsonPointerConstructs a JSON pointer from an array of reference tokens.Returns a pointer containing all but the first reference token contained in this pointer, or/if this pointer contains less than 2 reference tokens.relativePointer(int sz) Returns a pointer containing the lastszreference tokens contained in this pointer.static JsonPointerrootPtr()Returns a JSON pointer identifying the root value of a JSON structure.intsize()Returns the number of reference tokens in the pointer.String[]toArray()Returns a newly allocated array of strings, containing the pointer's reference tokens.toString()Returns the JSON pointer string value.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
JsonPointer
Deprecated.UserootPtr()instead.Constructs a JSON pointer, identifying the root value of a JSON structure. -
JsonPointer
Constructs a JSON pointer, identifying the specified pointer value.- Parameters:
pointer- a string containing the JSON pointer of the value to identify.- Throws:
JsonException- if the pointer is malformed.
-
JsonPointer
Constructs a JSON pointer from an array of reference tokens.- Parameters:
tokens- an array of string reference tokens.
-
JsonPointer
Constructs a JSON pointer from an iterable collection of reference tokens.- Parameters:
iterable- an iterable collection of reference tokens.
-
-
Method Details
-
rootPtr
Returns a JSON pointer identifying the root value of a JSON structure.- Returns:
- A JSON pointer identifying the root value of a JSON structure.
-
ptr
Constructs a JSON pointer, identifying the specified pointer value.- Parameters:
pointer- a string containing the JSON pointer of the value to identify.- Returns:
- The new JSON pointer
- Throws:
JsonException- if the pointer is malformed.
-
ptr
Constructs a JSON pointer from an array of reference tokens.- Parameters:
tokens- an array of string reference tokens.- Returns:
- The new json pointer
-
ptr
Constructs a JSON pointer from an iterable collection of reference tokens.- Parameters:
iterable- an iterable collection of reference tokens.- Returns:
- The new json pointer
-
size
public int size()Returns the number of reference tokens in the pointer.- Returns:
- the number of reference tokens in the pointer.
-
get
Returns the reference token at the specified position.- Parameters:
index- the index of the reference token to return.- Returns:
- the reference token at the specified position.
- Throws:
IndexOutOfBoundsException- if the index is out of range.
-
toArray
Returns a newly allocated array of strings, containing the pointer's reference tokens. No references to the array are maintained by the pointer. Hence, the caller is free to modify it.- Returns:
- a newly allocated array of strings, containing the pointer's reference tokens.
-
parent
Returns a pointer to the parent of the JSON value identified by this JSON pointer, ornullif the pointer has no parent JSON value (i.e. references document root).- Returns:
- a pointer to the parent of of this JSON pointer. Can be null.
-
head
Returns a pointer which is a subsequence of the path elements contained in this pointer beginning with the first element (0) and ending with the element at positionendIndex-1. The returned pointer will therefore have the sizeendIndex.- Parameters:
endIndex- The end index, exclusive.- Returns:
- A pointer which is a subsequence of the path elements contained in this resource path.
- Throws:
IndexOutOfBoundsException- IfendIndexis bigger thansize().
-
isPrefixOf
Checks whethercandidateis an extension of this JSON Pointer.- Parameters:
candidate- The JSON Pointer to test.- Returns:
- true if this JSON Pointer is a prefix for the
candidateJSON Pointer.
-
relativePointer
Returns a pointer containing all but the first reference token contained in this pointer, or/if this pointer contains less than 2 reference tokens.This method yields the following results:
Examples illustrating usage of relativePointer Input Output / //a //a/b /b /a/b/c /b/c - Returns:
- A pointer containing all but the first reference token contained in this pointer.
-
relativePointer
Returns a pointer containing the lastszreference tokens contained in this pointer.This method yields the following results:
Examples illustrating usage of relativePointer Input sz Output /a/b/c 0 / /a/b/c 1 /c /a/b/c 2 /b/c /a/b/c 3 /a/b/c - Parameters:
sz- The number of trailing reference tokens to retain.- Returns:
- A pointer containing the last
szreference tokens contained in this pointer. - Throws:
IndexOutOfBoundsException- Ifszis negative or greater thansize().
-
leaf
Returns the last (leaf) reference token of the JSON pointer, ornullif the pointer contains no reference tokens (i.e. references document root).- Returns:
- the last (leaf) reference token of the JSON pointer if it exists,
nullotherwise
-
child
Returns a new JSON pointer, which identifies a specified child member of the object identified by this pointer.- Parameters:
child- the name of the child member to identify.- Returns:
- the child JSON pointer.
- Throws:
NullPointerException- ifchildisnull.
-
child
Returns a new JSON pointer, which identifies a specified child element of the array identified by this pointer.- Parameters:
child- the index of the child element to identify.- Returns:
- the child JSON pointer.
- Throws:
IndexOutOfBoundsException- ifchildis less than zero.
-
concat
Creates a new JSON pointer which is a descendant of this JSON pointer. The returned JSON pointer will have been formed of the concatenation of this JSON pointer and the provided JSON pointer.- Parameters:
suffix- the JSON pointer to be appended to this JSON pointer.- Returns:
- A new JSON pointer which is a descendant of this JSON pointer.
-
isEmpty
public boolean isEmpty()Returnstrueif this pointer identifies the root value of a JSON structure. More specifically, it returnstrueif this pointer does not contain any reference tokens (i.e.size() == 0).- Returns:
trueif this pointer identifies the root value of a JSON structure.
-
iterator
Returns an iterator over the pointer's reference tokens. -
toString
Returns the JSON pointer string value. -
getValue
Returns the JSON pointer string value.- Returns:
- the JSON pointer string value.
-
equals
Compares the specified object with this pointer for equality. Returnstrueif and only if the specified object is also a JSON pointer, both pointers have the same size, and all corresponding pairs of reference tokens in the two pointers are equal. -
hashCode
public int hashCode()Returns the hash code value for this pointer.
-
rootPtr()instead.