Package org.apache.johnzon.core
Class JsonPointerImpl
- java.lang.Object
-
- org.apache.johnzon.core.JsonPointerImpl
-
- All Implemented Interfaces:
javax.json.JsonPointer
public class JsonPointerImpl extends java.lang.Object implements javax.json.JsonPointer
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.PatternIS_NUMBERprivate java.lang.StringjsonPointerprivate javax.json.spi.JsonProviderproviderprivate java.util.List<java.lang.String>referenceTokens
-
Constructor Summary
Constructors Constructor Description JsonPointerImpl(javax.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 javax.json.JsonArrayadd(javax.json.JsonArray target, javax.json.JsonValue value)Adds or replaces a value at the referenced location in the specifiedtargetwith the specifiedvalue.javax.json.JsonObjectadd(javax.json.JsonObject target, javax.json.JsonValue value)Adds or replaces a value at the referenced location in the specifiedtargetwith the specifiedvalue.javax.json.JsonStructureadd(javax.json.JsonStructure target, javax.json.JsonValue value)Adds or replaces a value at the referenced location in the specifiedtargetwith the specifiedvalue.private javax.json.JsonValueaddInternal(javax.json.JsonValue jsonValue, javax.json.JsonValue newValue, java.util.List<java.lang.String> currentPath, boolean check)private <T extends javax.json.JsonStructure>
TaddInternal(T jsonValue, javax.json.JsonValue newValue)private booleancanMatch(java.util.List<java.lang.String> currentPath)booleancontainsValue(javax.json.JsonStructure target)booleanequals(java.lang.Object obj)Compares thisJsonPointerwith another object.private intgetArrayIndex(java.lang.String referenceToken, javax.json.JsonArray jsonArray, boolean addOperation)(package private) java.lang.StringgetJsonPointer()javax.json.JsonValuegetValue(javax.json.JsonStructure target)Returns the value at the referenced location in the specifiedtargetprivate javax.json.JsonValuegetValue(javax.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)protected intminusShift()This method can be overridden in sub classes.javax.json.JsonArrayremove(javax.json.JsonArray target)Removes the value at the reference location in the specifiedtargetjavax.json.JsonObjectremove(javax.json.JsonObject target)Removes the value at the reference location in the specifiedtargetjavax.json.JsonStructureremove(javax.json.JsonStructure target)Removes the value at the reference location in the specifiedtargetprivate javax.json.JsonValueremove(javax.json.JsonValue jsonValue, int currentPosition)javax.json.JsonArrayreplace(javax.json.JsonArray target, javax.json.JsonValue value)Replaces the value at the referenced location in the specifiedjavax.json.JsonObjectreplace(javax.json.JsonObject target, javax.json.JsonValue value)Replaces the value at the referenced location in the specifiedjavax.json.JsonStructurereplace(javax.json.JsonStructure target, javax.json.JsonValue value)Replaces the value at the referenced location in the specifiedtargetwith the specifiedvalue.java.lang.StringtoString()private voidvalidateAdd(javax.json.JsonValue target)private voidvalidateArrayIndex(java.lang.String referenceToken)private voidvalidateArraySize(java.lang.String referenceToken, javax.json.JsonArray jsonArray, int arrayIndex, int arraySize)private voidvalidateJsonPointer(javax.json.JsonValue target, int size)private voidvalidateRemove(javax.json.JsonValue target)
-
-
-
Constructor Detail
-
JsonPointerImpl
public JsonPointerImpl(javax.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- ifjsonPointerisnulljavax.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 javax.json.JsonValue getValue(javax.json.JsonStructure target)
Returns the value at the referenced location in the specifiedtarget- Specified by:
getValuein interfacejavax.json.JsonPointer- Parameters:
target- the target referenced by thisJsonPointer- Returns:
- the referenced value in the target.
- Throws:
java.lang.NullPointerException- iftargetis nulljavax.json.JsonException- if the referenced value does not exist
-
containsValue
public boolean containsValue(javax.json.JsonStructure target)
- Specified by:
containsValuein interfacejavax.json.JsonPointer
-
add
public javax.json.JsonStructure add(javax.json.JsonStructure target, javax.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 interfacejavax.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- iftargetisnulljavax.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 javax.json.JsonObject add(javax.json.JsonObject target, javax.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- iftargetisnulljavax.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 javax.json.JsonArray add(javax.json.JsonArray target, javax.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- iftargetisnulljavax.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 javax.json.JsonStructure replace(javax.json.JsonStructure target, javax.json.JsonValue value)Replaces the value at the referenced location in the specifiedtargetwith the specifiedvalue.- Specified by:
replacein interfacejavax.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- iftargetisnulljavax.json.JsonException- if the referenced value does not exist, or if the reference is the target.
-
replace
public javax.json.JsonObject replace(javax.json.JsonObject target, javax.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- iftargetisnulljavax.json.JsonException- if the referenced value does not exist, or if the reference is the target.- See Also:
replace(JsonStructure, JsonValue)
-
replace
public javax.json.JsonArray replace(javax.json.JsonArray target, javax.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- iftargetisnulljavax.json.JsonException- if the referenced value does not exist, or if the reference is the target.- See Also:
replace(JsonStructure, JsonValue)
-
remove
public javax.json.JsonStructure remove(javax.json.JsonStructure target)
Removes the value at the reference location in the specifiedtarget- Specified by:
removein interfacejavax.json.JsonPointer- Parameters:
target- the target referenced by thisJsonPointer- Returns:
- the transformed
targetafter the value is removed. - Throws:
java.lang.NullPointerException- iftargetisnulljavax.json.JsonException- if the referenced value does not exist, or if the reference is the target.
-
remove
public javax.json.JsonObject remove(javax.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- iftargetisnulljavax.json.JsonException- if the referenced value does not exist, or if the reference is the target.- See Also:
remove(JsonStructure)
-
remove
public javax.json.JsonArray remove(javax.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- iftargetisnulljavax.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()
- Overrides:
toStringin classjava.lang.Object
-
validateAdd
private void validateAdd(javax.json.JsonValue target)
-
validateRemove
private void validateRemove(javax.json.JsonValue target)
-
isEmptyJsonPointer
private boolean isEmptyJsonPointer()
-
getValue
private javax.json.JsonValue getValue(javax.json.JsonValue jsonValue, java.lang.String referenceToken, int currentPosition, int referencePosition)
-
addInternal
private <T extends javax.json.JsonStructure> T addInternal(T jsonValue, javax.json.JsonValue newValue)
-
addInternal
private javax.json.JsonValue addInternal(javax.json.JsonValue jsonValue, javax.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 javax.json.JsonValue remove(javax.json.JsonValue jsonValue, int currentPosition)
-
getArrayIndex
private int getArrayIndex(java.lang.String referenceToken, javax.json.JsonArray jsonArray, boolean addOperation)
-
minusShift
protected int minusShift()
This method can be overridden in sub classes. It's main goal is to support patch operation using "-" to replace, remove last element which is forbidden in JsonPointer- Returns:
- the shift to apply on minus. For backward compatibility it's 1. We can have a strict JSONP compliancy with the dedicated module.
-
validateJsonPointer
private void validateJsonPointer(javax.json.JsonValue target, int size) throws java.lang.NullPointerException, javax.json.JsonException- Throws:
java.lang.NullPointerExceptionjavax.json.JsonException
-
validateArrayIndex
private void validateArrayIndex(java.lang.String referenceToken) throws javax.json.JsonException- Throws:
javax.json.JsonException
-
validateArraySize
private void validateArraySize(java.lang.String referenceToken, javax.json.JsonArray jsonArray, int arrayIndex, int arraySize) throws javax.json.JsonException- Throws:
javax.json.JsonException
-
-