- java.lang.Object
-
- org.apache.johnzon.core.JsonPointerImpl
-
- All Implemented Interfaces:
jakarta.json.JsonPointer
public class JsonPointerImpl extends java.lang.Object implements jakarta.json.JsonPointer
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.PatternIS_NUMBERprivate java.lang.StringjsonPointerprivate jakarta.json.spi.JsonProviderproviderprivate java.util.List<java.lang.String>referenceTokens
-
Constructor Summary
Constructors Constructor Description JsonPointerImpl(jakarta.json.spi.JsonProvider provider, java.lang.String jsonPointer)Constructs and initializes a JsonPointer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description jakarta.json.JsonArrayadd(jakarta.json.JsonArray target, jakarta.json.JsonValue value)Adds or replaces a value at the referenced location in the specifiedtargetwith the specifiedvalue.jakarta.json.JsonObjectadd(jakarta.json.JsonObject target, jakarta.json.JsonValue value)Adds or replaces a value at the referenced location in the specifiedtargetwith the specifiedvalue.jakarta.json.JsonStructureadd(jakarta.json.JsonStructure target, jakarta.json.JsonValue value)Adds or replaces a value at the referenced location in the specifiedtargetwith the specifiedvalue.private jakarta.json.JsonValueaddInternal(jakarta.json.JsonValue jsonValue, jakarta.json.JsonValue newValue, java.util.List<java.lang.String> currentPath, boolean check)private <T extends jakarta.json.JsonStructure>
TaddInternal(T jsonValue, jakarta.json.JsonValue newValue)private booleancanMatch(java.util.List<java.lang.String> currentPath)booleancontainsValue(jakarta.json.JsonStructure target)booleanequals(java.lang.Object obj)Compares thisJsonPointerwith another object.private intgetArrayIndex(java.lang.String referenceToken, jakarta.json.JsonArray jsonArray, boolean addOperation)(package private) java.lang.StringgetJsonPointer()jakarta.json.JsonValuegetValue(jakarta.json.JsonStructure target)Returns the value at the referenced location in the specifiedtargetprivate jakarta.json.JsonValuegetValue(jakarta.json.JsonValue jsonValue, java.lang.String referenceToken, int currentPosition, int referencePosition)inthashCode()Returns the hash code value for thisJsonPointerobject.private booleanisEmptyJsonPointer()private booleanisPositionToAdd(java.util.List<java.lang.String> currentPath)jakarta.json.JsonArrayremove(jakarta.json.JsonArray target)Removes the value at the reference location in the specifiedtargetjakarta.json.JsonObjectremove(jakarta.json.JsonObject target)Removes the value at the reference location in the specifiedtargetjakarta.json.JsonStructureremove(jakarta.json.JsonStructure target)Removes the value at the reference location in the specifiedtargetprivate jakarta.json.JsonValueremove(jakarta.json.JsonValue jsonValue, int currentPosition)jakarta.json.JsonArrayreplace(jakarta.json.JsonArray target, jakarta.json.JsonValue value)Replaces the value at the referenced location in the specifiedjakarta.json.JsonObjectreplace(jakarta.json.JsonObject target, jakarta.json.JsonValue value)Replaces the value at the referenced location in the specifiedjakarta.json.JsonStructurereplace(jakarta.json.JsonStructure target, jakarta.json.JsonValue value)Replaces the value at the referenced location in the specifiedtargetwith the specifiedvalue.java.lang.StringtoString()private voidvalidateAdd(jakarta.json.JsonValue target)private voidvalidateArrayIndex(java.lang.String referenceToken)private voidvalidateArraySize(java.lang.String referenceToken, jakarta.json.JsonArray jsonArray, int arrayIndex, int arraySize)private voidvalidateJsonPointer(jakarta.json.JsonValue target, int size)private voidvalidateRemove(jakarta.json.JsonValue target)
-
-
-
Constructor Detail
-
JsonPointerImpl
public JsonPointerImpl(jakarta.json.spi.JsonProvider provider, java.lang.String jsonPointer)Constructs and initializes a JsonPointer.- Parameters:
provider- the JSON provider used to create this pointerjsonPointer- the JSON Pointer string- Throws:
java.lang.NullPointerException- ifjsonPointerisnulljakarta.json.JsonException- ifjsonPointeris not a valid JSON Pointer
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object obj)
Compares thisJsonPointerwith another object.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare thisJsonPointeragainst- Returns:
- true if the given object is a
JsonPointerwith the same reference tokens as this one, false otherwise.
-
hashCode
public int hashCode()
Returns the hash code value for thisJsonPointerobject. The hash code of this object is defined by the hash codes of it's reference tokens.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code value for this
JsonPointerobject
-
getValue
public jakarta.json.JsonValue getValue(jakarta.json.JsonStructure target)
Returns the value at the referenced location in the specifiedtarget- Specified by:
getValuein interfacejakarta.json.JsonPointer- Parameters:
target- the target referenced by thisJsonPointer- Returns:
- the referenced value in the target.
- Throws:
java.lang.NullPointerException- iftargetis nulljakarta.json.JsonException- if the referenced value does not exist
-
containsValue
public boolean containsValue(jakarta.json.JsonStructure target)
- Specified by:
containsValuein 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 specifiedtargetwith 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
valueis 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:
addin interfacejakarta.json.JsonPointer- Parameters:
target- the target referenced by thisJsonPointervalue- the value to be added- Returns:
- the transformed
targetafter the value is added. - Throws:
java.lang.NullPointerException- iftargetisnulljakarta.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 specifiedtargetwith the specifiedvalue.- Parameters:
target- the target referenced by thisJsonPointervalue- the value to be added- Returns:
- the transformed
targetafter the value is added. - Throws:
java.lang.NullPointerException- iftargetisnulljakarta.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 specifiedtargetwith the specifiedvalue.- Parameters:
target- the target referenced by thisJsonPointervalue- the value to be added- Returns:
- the transformed
targetafter the value is added. - Throws:
java.lang.NullPointerException- iftargetisnulljakarta.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 specifiedtargetwith the specifiedvalue.- Specified by:
replacein interfacejakarta.json.JsonPointer- Parameters:
target- the target referenced by thisJsonPointervalue- the value to be stored at the referenced location- Returns:
- the transformed
targetafter the value is replaced. - Throws:
java.lang.NullPointerException- iftargetisnulljakarta.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 thisJsonPointervalue- the value to be stored at the referenced location- Returns:
- the transformed
targetafter the value is replaced. - Throws:
java.lang.NullPointerException- iftargetisnulljakarta.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 thisJsonPointervalue- the value to be stored at the referenced location- Returns:
- the transformed
targetafter the value is replaced. - Throws:
java.lang.NullPointerException- iftargetisnulljakarta.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:
removein interfacejakarta.json.JsonPointer- Parameters:
target- the target referenced by thisJsonPointer- Returns:
- the transformed
targetafter the value is removed. - Throws:
java.lang.NullPointerException- iftargetisnulljakarta.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
targetafter the value is removed. - Throws:
java.lang.NullPointerException- iftargetisnulljakarta.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
targetafter the value is removed. - Throws:
java.lang.NullPointerException- iftargetisnulljakarta.json.JsonException- if the referenced value does not exist, or if the reference is the target.- See Also:
remove(JsonStructure)
-
getJsonPointer
java.lang.String getJsonPointer()
-
toString
public java.lang.String toString()
- Specified by:
toStringin interfacejakarta.json.JsonPointer- Overrides:
toStringin classjava.lang.Object
-
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, java.lang.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, java.util.List<java.lang.String> currentPath, boolean check)
-
isPositionToAdd
private boolean isPositionToAdd(java.util.List<java.lang.String> currentPath)
-
canMatch
private boolean canMatch(java.util.List<java.lang.String> currentPath)
-
remove
private jakarta.json.JsonValue remove(jakarta.json.JsonValue jsonValue, int currentPosition)
-
getArrayIndex
private int getArrayIndex(java.lang.String referenceToken, jakarta.json.JsonArray jsonArray, boolean addOperation)
-
validateJsonPointer
private void validateJsonPointer(jakarta.json.JsonValue target, int size) throws java.lang.NullPointerException, jakarta.json.JsonException- Throws:
java.lang.NullPointerExceptionjakarta.json.JsonException
-
validateArrayIndex
private void validateArrayIndex(java.lang.String referenceToken) throws jakarta.json.JsonException- Throws:
jakarta.json.JsonException
-
validateArraySize
private void validateArraySize(java.lang.String referenceToken, jakarta.json.JsonArray jsonArray, int arrayIndex, int arraySize) throws jakarta.json.JsonException- Throws:
jakarta.json.JsonException
-
-