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.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a JSON pointer, identifying the root value of a JSON structure.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.boolean
Compares the specified object with this pointer for equality.get
(int index) Returns the reference token at the specified position.int
hashCode()
Returns the hash code value for this pointer.boolean
isEmpty()
Returnstrue
if this pointer identifies the root value of a JSON structure.iterator()
Returns an iterator over the pointer's reference tokens.leaf()
Returns the last (leaf) reference token of the JSON pointer, ornull
if the pointer contains no reference tokens (i.e. references document root).parent()
Returns a pointer to the parent of the JSON value identified by this JSON pointer, ornull
if the pointer has no parent JSON value (i.e. references document root).static JsonPointer
Constructs a JSON pointer from an iterable collection of reference tokens.static JsonPointer
Constructs a JSON pointer, identifying the specified pointer value.static JsonPointer
Constructs 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 lastsz
reference tokens contained in this pointer.int
size()
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, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
JsonPointer
public JsonPointer()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
-
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
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, ornull
if 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.
-
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:
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 lastsz
reference tokens contained in this pointer.This method yields the following results:
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
sz
reference tokens contained in this pointer. - Throws:
IndexOutOfBoundsException
- Ifsz
is negative or greater thansize()
.
-
leaf
Returns the last (leaf) reference token of the JSON pointer, ornull
if the pointer contains no reference tokens (i.e. references document root).- Returns:
- the last (leaf) reference token of the JSON pointer if it exists,
null
otherwise
-
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
- ifchild
isnull
.
-
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
- ifchild
is less than zero.
-
isEmpty
Returnstrue
if this pointer identifies the root value of a JSON structure. More specifically, it returnstrue
if this pointer does not contain any reference tokens (i.e.size() == 0
).- Returns:
true
if 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. -
equals
Compares the specified object with this pointer for equality. Returnstrue
if 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
Returns the hash code value for this pointer.
-