Class JsonPointerImpl

  • All Implemented Interfaces:
    jakarta.json.JsonPointer

    public class JsonPointerImpl
    extends Object
    implements jakarta.json.JsonPointer
    • 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 specified target with the specified value.
      jakarta.json.JsonObject add​(jakarta.json.JsonObject target, jakarta.json.JsonValue value)
      Adds or replaces a value at the referenced location in the specified target with the specified value.
      jakarta.json.JsonStructure add​(jakarta.json.JsonStructure target, jakarta.json.JsonValue value)
      Adds or replaces a value at the referenced location in the specified target with the specified value.
      private jakarta.json.JsonValue addInternal​(jakarta.json.JsonValue jsonValue, jakarta.json.JsonValue newValue, List<String> currentPath, boolean check)  
      private <T extends jakarta.json.JsonStructure>
      T
      addInternal​(T jsonValue, jakarta.json.JsonValue newValue)  
      private boolean canMatch​(List<String> currentPath)  
      boolean containsValue​(jakarta.json.JsonStructure target)  
      boolean equals​(Object obj)
      Compares this JsonPointer 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 specified target
      private jakarta.json.JsonValue getValue​(jakarta.json.JsonValue jsonValue, String referenceToken, int currentPosition, int referencePosition)  
      int hashCode()
      Returns the hash code value for this JsonPointer 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 specified target
      jakarta.json.JsonObject remove​(jakarta.json.JsonObject target)
      Removes the value at the reference location in the specified target
      jakarta.json.JsonStructure remove​(jakarta.json.JsonStructure target)
      Removes the value at the reference location in the specified target
      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 specified
      jakarta.json.JsonObject replace​(jakarta.json.JsonObject target, jakarta.json.JsonValue value)
      Replaces the value at the referenced location in the specified
      jakarta.json.JsonStructure replace​(jakarta.json.JsonStructure target, jakarta.json.JsonValue value)
      Replaces the value at the referenced location in the specified target with the specified value.
      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)  
    • Field Detail

      • provider

        private final jakarta.json.spi.JsonProvider provider
      • jsonPointer

        private final String jsonPointer
      • referenceTokens

        private final List<String> referenceTokens
      • IS_NUMBER

        private static final Pattern IS_NUMBER
    • 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 pointer
        jsonPointer - the JSON Pointer string
        Throws:
        NullPointerException - if jsonPointer is null
        jakarta.json.JsonException - if jsonPointer is not a valid JSON Pointer
    • Method Detail

      • equals

        public boolean equals​(Object obj)
        Compares this JsonPointer with another object.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare this JsonPointer against
        Returns:
        true if the given object is a JsonPointer with the same reference tokens as this one, false otherwise.
      • hashCode

        public int hashCode()
        Returns the hash code value for this JsonPointer object. The hash code of this object is defined by the hash codes of it's reference tokens.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code value for this JsonPointer object
      • getValue

        public jakarta.json.JsonValue getValue​(jakarta.json.JsonStructure target)
        Returns the value at the referenced location in the specified target
        Specified by:
        getValue in interface jakarta.json.JsonPointer
        Parameters:
        target - the target referenced by this JsonPointer
        Returns:
        the referenced value in the target.
        Throws:
        NullPointerException - if target is null
        jakarta.json.JsonException - if the referenced value does not exist
      • containsValue

        public boolean containsValue​(jakarta.json.JsonStructure target)
        Specified by:
        containsValue in interface jakarta.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 specified target with the specified value.
        1. If the reference is the target (empty JSON Pointer string), the specified value, which must be the same type as specified target, is returned.
        2. 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.
        3. If the reference is a name/value pair of a JsonObject, and the referenced value exists, the value is replaced by the specified value. If the value does not exist, a new name/value pair is added to the object.
        Specified by:
        add in interface jakarta.json.JsonPointer
        Parameters:
        target - the target referenced by this JsonPointer
        value - the value to be added
        Returns:
        the transformed target after the value is added.
        Throws:
        NullPointerException - if target is null
        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.
      • 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 specified target with the specified value.
        Parameters:
        target - the target referenced by this JsonPointer
        value - the value to be added
        Returns:
        the transformed target after the value is added.
        Throws:
        NullPointerException - if target is null
        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 specified target with the specified value.
        Parameters:
        target - the target referenced by this JsonPointer
        value - the value to be added
        Returns:
        the transformed target after the value is added.
        Throws:
        NullPointerException - if target is null
        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 specified target with the specified value.
        Specified by:
        replace in interface jakarta.json.JsonPointer
        Parameters:
        target - the target referenced by this JsonPointer
        value - the value to be stored at the referenced location
        Returns:
        the transformed target after the value is replaced.
        Throws:
        NullPointerException - if target is null
        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 this JsonPointer
        value - the value to be stored at the referenced location
        Returns:
        the transformed target after the value is replaced.
        Throws:
        NullPointerException - if target is null
        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 this JsonPointer
        value - the value to be stored at the referenced location
        Returns:
        the transformed target after the value is replaced.
        Throws:
        NullPointerException - if target is null
        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 specified target
        Specified by:
        remove in interface jakarta.json.JsonPointer
        Parameters:
        target - the target referenced by this JsonPointer
        Returns:
        the transformed target after the value is removed.
        Throws:
        NullPointerException - if target is null
        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 specified target
        Parameters:
        target - the target referenced by this JsonPointer
        Returns:
        the transformed target after the value is removed.
        Throws:
        NullPointerException - if target is null
        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 specified target
        Parameters:
        target - the target referenced by this JsonPointer
        Returns:
        the transformed target after the value is removed.
        Throws:
        NullPointerException - if target is null
        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()
        Specified by:
        toString in interface jakarta.json.JsonPointer
        Overrides:
        toString in class 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,
                                                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)
      • isPositionToAdd

        private boolean isPositionToAdd​(List<String> currentPath)
      • canMatch

        private boolean canMatch​(List<String> currentPath)
      • 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