Package org.apache.johnzon.core
Class JsonPointerImpl
- java.lang.Object
-
- org.apache.johnzon.core.JsonPointerImpl
-
- All Implemented Interfaces:
jakarta.json.JsonPointer
public class JsonPointerImpl extends Object implements jakarta.json.JsonPointer
-
-
Field Summary
Fields Modifier and Type Field Description private static Pattern
IS_NUMBER
private String
jsonPointer
private jakarta.json.spi.JsonProvider
provider
private List<String>
referenceTokens
-
Constructor Summary
Constructors Constructor Description JsonPointerImpl(jakarta.json.spi.JsonProvider provider, String jsonPointer)
Constructs and initializes a JsonPointer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description jakarta.json.JsonArray
add(jakarta.json.JsonArray target, jakarta.json.JsonValue value)
Adds or replaces a value at the referenced location in the specifiedtarget
with the specifiedvalue
.jakarta.json.JsonObject
add(jakarta.json.JsonObject target, jakarta.json.JsonValue value)
Adds or replaces a value at the referenced location in the specifiedtarget
with the specifiedvalue
.jakarta.json.JsonStructure
add(jakarta.json.JsonStructure target, jakarta.json.JsonValue value)
Adds or replaces a value at the referenced location in the specifiedtarget
with the specifiedvalue
.private jakarta.json.JsonValue
addInternal(jakarta.json.JsonValue jsonValue, jakarta.json.JsonValue newValue, List<String> currentPath, boolean check)
private <T extends jakarta.json.JsonStructure>
TaddInternal(T jsonValue, jakarta.json.JsonValue newValue)
private boolean
canMatch(List<String> currentPath)
boolean
containsValue(jakarta.json.JsonStructure target)
boolean
equals(Object obj)
Compares thisJsonPointer
with another object.private int
getArrayIndex(String referenceToken, jakarta.json.JsonArray jsonArray, boolean addOperation)
(package private) String
getJsonPointer()
jakarta.json.JsonValue
getValue(jakarta.json.JsonStructure target)
Returns the value at the referenced location in the specifiedtarget
private jakarta.json.JsonValue
getValue(jakarta.json.JsonValue jsonValue, String referenceToken, int currentPosition, int referencePosition)
int
hashCode()
Returns the hash code value for thisJsonPointer
object.private boolean
isEmptyJsonPointer()
private boolean
isPositionToAdd(List<String> currentPath)
jakarta.json.JsonArray
remove(jakarta.json.JsonArray target)
Removes the value at the reference location in the specifiedtarget
jakarta.json.JsonObject
remove(jakarta.json.JsonObject target)
Removes the value at the reference location in the specifiedtarget
jakarta.json.JsonStructure
remove(jakarta.json.JsonStructure target)
Removes the value at the reference location in the specifiedtarget
private jakarta.json.JsonValue
remove(jakarta.json.JsonValue jsonValue, int currentPosition)
jakarta.json.JsonArray
replace(jakarta.json.JsonArray target, jakarta.json.JsonValue value)
Replaces the value at the referenced location in the specifiedjakarta.json.JsonObject
replace(jakarta.json.JsonObject target, jakarta.json.JsonValue value)
Replaces the value at the referenced location in the specifiedjakarta.json.JsonStructure
replace(jakarta.json.JsonStructure target, jakarta.json.JsonValue value)
Replaces the value at the referenced location in the specifiedtarget
with the specifiedvalue
.String
toString()
private void
validateAdd(jakarta.json.JsonValue target)
private void
validateArrayIndex(String referenceToken)
private void
validateArraySize(String referenceToken, jakarta.json.JsonArray jsonArray, int arrayIndex, int arraySize)
private void
validateJsonPointer(jakarta.json.JsonValue target, int size)
private void
validateRemove(jakarta.json.JsonValue target)
-
-
-
Constructor Detail
-
JsonPointerImpl
public JsonPointerImpl(jakarta.json.spi.JsonProvider provider, String jsonPointer)
Constructs and initializes a JsonPointer.- Parameters:
provider
- the JSON provider used to create this pointerjsonPointer
- the JSON Pointer string- Throws:
NullPointerException
- ifjsonPointer
isnull
jakarta.json.JsonException
- ifjsonPointer
is not a valid JSON Pointer
-
-
Method Detail
-
equals
public boolean equals(Object obj)
Compares thisJsonPointer
with another object.
-
hashCode
public int hashCode()
Returns the hash code value for thisJsonPointer
object. The hash code of this object is defined by the hash codes of it's reference tokens.
-
getValue
public jakarta.json.JsonValue getValue(jakarta.json.JsonStructure target)
Returns the value at the referenced location in the specifiedtarget
- Specified by:
getValue
in interfacejakarta.json.JsonPointer
- Parameters:
target
- the target referenced by thisJsonPointer
- Returns:
- the referenced value in the target.
- Throws:
NullPointerException
- iftarget
is nulljakarta.json.JsonException
- if the referenced value does not exist
-
containsValue
public boolean containsValue(jakarta.json.JsonStructure target)
- Specified by:
containsValue
in interfacejakarta.json.JsonPointer
-
add
public jakarta.json.JsonStructure add(jakarta.json.JsonStructure target, jakarta.json.JsonValue value)
Adds or replaces a value at the referenced location in the specifiedtarget
with the specifiedvalue
.- If the reference is the target (empty JSON Pointer string),
the specified
value
, which must be the same type as specifiedtarget
, is returned. - If the reference is an array element, the specified
value
is inserted into the array, at the referenced index. The value currently at that location, and any subsequent values, are shifted to the right (adds one to the indices). Index starts with 0. If the reference is specified with a "-", or if the index is equal to the size of the array, the value is appended to the array. - If the reference is a name/value pair of a
JsonObject
, and the referenced value exists, the value is replaced by the specifiedvalue
. If the value does not exist, a new name/value pair is added to the object.
- Specified by:
add
in interfacejakarta.json.JsonPointer
- Parameters:
target
- the target referenced by thisJsonPointer
value
- the value to be added- Returns:
- the transformed
target
after the value is added. - Throws:
NullPointerException
- iftarget
isnull
jakarta.json.JsonException
- if the reference is an array element and the index is out of range (index < 0 || index > array size
), or if the pointer contains references to non-existing objects or arrays.
- If the reference is the target (empty JSON Pointer string),
the specified
-
add
public jakarta.json.JsonObject add(jakarta.json.JsonObject target, jakarta.json.JsonValue value)
Adds or replaces a value at the referenced location in the specifiedtarget
with the specifiedvalue
.- Parameters:
target
- the target referenced by thisJsonPointer
value
- the value to be added- Returns:
- the transformed
target
after the value is added. - Throws:
NullPointerException
- iftarget
isnull
jakarta.json.JsonException
- if the reference is an array element and the index is out of range (index < 0 || index > array size
), or if the pointer contains references to non-existing objects or arrays.- See Also:
add(JsonStructure, JsonValue)
-
add
public jakarta.json.JsonArray add(jakarta.json.JsonArray target, jakarta.json.JsonValue value)
Adds or replaces a value at the referenced location in the specifiedtarget
with the specifiedvalue
.- Parameters:
target
- the target referenced by thisJsonPointer
value
- the value to be added- Returns:
- the transformed
target
after the value is added. - Throws:
NullPointerException
- iftarget
isnull
jakarta.json.JsonException
- if the reference is an array element and the index is out of range (index < 0 || index > array size
), or if the pointer contains references to non-existing objects or arrays.- See Also:
add(JsonStructure, JsonValue)
-
replace
public jakarta.json.JsonStructure replace(jakarta.json.JsonStructure target, jakarta.json.JsonValue value)
Replaces the value at the referenced location in the specifiedtarget
with the specifiedvalue
.- Specified by:
replace
in interfacejakarta.json.JsonPointer
- Parameters:
target
- the target referenced by thisJsonPointer
value
- the value to be stored at the referenced location- Returns:
- the transformed
target
after the value is replaced. - Throws:
NullPointerException
- iftarget
isnull
jakarta.json.JsonException
- if the referenced value does not exist, or if the reference is the target.
-
replace
public jakarta.json.JsonObject replace(jakarta.json.JsonObject target, jakarta.json.JsonValue value)
Replaces the value at the referenced location in the specified- Parameters:
target
- the target referenced by thisJsonPointer
value
- the value to be stored at the referenced location- Returns:
- the transformed
target
after the value is replaced. - Throws:
NullPointerException
- iftarget
isnull
jakarta.json.JsonException
- if the referenced value does not exist, or if the reference is the target.- See Also:
replace(JsonStructure, JsonValue)
-
replace
public jakarta.json.JsonArray replace(jakarta.json.JsonArray target, jakarta.json.JsonValue value)
Replaces the value at the referenced location in the specified- Parameters:
target
- the target referenced by thisJsonPointer
value
- the value to be stored at the referenced location- Returns:
- the transformed
target
after the value is replaced. - Throws:
NullPointerException
- iftarget
isnull
jakarta.json.JsonException
- if the referenced value does not exist, or if the reference is the target.- See Also:
replace(JsonStructure, JsonValue)
-
remove
public jakarta.json.JsonStructure remove(jakarta.json.JsonStructure target)
Removes the value at the reference location in the specifiedtarget
- Specified by:
remove
in interfacejakarta.json.JsonPointer
- Parameters:
target
- the target referenced by thisJsonPointer
- Returns:
- the transformed
target
after the value is removed. - Throws:
NullPointerException
- iftarget
isnull
jakarta.json.JsonException
- if the referenced value does not exist, or if the reference is the target.
-
remove
public jakarta.json.JsonObject remove(jakarta.json.JsonObject target)
Removes the value at the reference location in the specifiedtarget
- Parameters:
target
- the target referenced by thisJsonPointer
- Returns:
- the transformed
target
after the value is removed. - Throws:
NullPointerException
- iftarget
isnull
jakarta.json.JsonException
- if the referenced value does not exist, or if the reference is the target.- See Also:
remove(JsonStructure)
-
remove
public jakarta.json.JsonArray remove(jakarta.json.JsonArray target)
Removes the value at the reference location in the specifiedtarget
- Parameters:
target
- the target referenced by thisJsonPointer
- Returns:
- the transformed
target
after the value is removed. - Throws:
NullPointerException
- iftarget
isnull
jakarta.json.JsonException
- if the referenced value does not exist, or if the reference is the target.- See Also:
remove(JsonStructure)
-
getJsonPointer
String getJsonPointer()
-
toString
public String toString()
-
validateAdd
private void validateAdd(jakarta.json.JsonValue target)
-
validateRemove
private void validateRemove(jakarta.json.JsonValue target)
-
isEmptyJsonPointer
private boolean isEmptyJsonPointer()
-
getValue
private jakarta.json.JsonValue getValue(jakarta.json.JsonValue jsonValue, String referenceToken, int currentPosition, int referencePosition)
-
addInternal
private <T extends jakarta.json.JsonStructure> T addInternal(T jsonValue, jakarta.json.JsonValue newValue)
-
addInternal
private jakarta.json.JsonValue addInternal(jakarta.json.JsonValue jsonValue, jakarta.json.JsonValue newValue, List<String> currentPath, boolean check)
-
remove
private jakarta.json.JsonValue remove(jakarta.json.JsonValue jsonValue, int currentPosition)
-
getArrayIndex
private int getArrayIndex(String referenceToken, jakarta.json.JsonArray jsonArray, boolean addOperation)
-
validateJsonPointer
private void validateJsonPointer(jakarta.json.JsonValue target, int size) throws NullPointerException, jakarta.json.JsonException
- Throws:
NullPointerException
jakarta.json.JsonException
-
validateArrayIndex
private void validateArrayIndex(String referenceToken) throws jakarta.json.JsonException
- Throws:
jakarta.json.JsonException
-
validateArraySize
private void validateArraySize(String referenceToken, jakarta.json.JsonArray jsonArray, int arrayIndex, int arraySize) throws jakarta.json.JsonException
- Throws:
jakarta.json.JsonException
-
-