Class 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.Pattern IS_NUMBER  
      private java.lang.String jsonPointer  
      private javax.json.spi.JsonProvider provider  
      private 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.JsonArray add​(javax.json.JsonArray target, javax.json.JsonValue value)
      Adds or replaces a value at the referenced location in the specified target with the specified value.
      javax.json.JsonObject add​(javax.json.JsonObject target, javax.json.JsonValue value)
      Adds or replaces a value at the referenced location in the specified target with the specified value.
      javax.json.JsonStructure add​(javax.json.JsonStructure target, javax.json.JsonValue value)
      Adds or replaces a value at the referenced location in the specified target with the specified value.
      private javax.json.JsonValue addInternal​(javax.json.JsonValue jsonValue, javax.json.JsonValue newValue, java.util.List<java.lang.String> currentPath, boolean check)  
      private <T extends javax.json.JsonStructure>
      T
      addInternal​(T jsonValue, javax.json.JsonValue newValue)  
      private boolean canMatch​(java.util.List<java.lang.String> currentPath)  
      boolean containsValue​(javax.json.JsonStructure target)  
      boolean equals​(java.lang.Object obj)
      Compares this JsonPointer with another object.
      private int getArrayIndex​(java.lang.String referenceToken, javax.json.JsonArray jsonArray, boolean addOperation)  
      (package private) java.lang.String getJsonPointer()  
      javax.json.JsonValue getValue​(javax.json.JsonStructure target)
      Returns the value at the referenced location in the specified target
      private javax.json.JsonValue getValue​(javax.json.JsonValue jsonValue, java.lang.String referenceToken, int currentPosition, int referencePosition)  
      int hashCode()
      Returns the hash code value for this JsonPointer object.
      private boolean isEmptyJsonPointer()  
      private boolean isPositionToAdd​(java.util.List<java.lang.String> currentPath)  
      protected int minusShift()
      This method can be overridden in sub classes.
      javax.json.JsonArray remove​(javax.json.JsonArray target)
      Removes the value at the reference location in the specified target
      javax.json.JsonObject remove​(javax.json.JsonObject target)
      Removes the value at the reference location in the specified target
      javax.json.JsonStructure remove​(javax.json.JsonStructure target)
      Removes the value at the reference location in the specified target
      private javax.json.JsonValue remove​(javax.json.JsonValue jsonValue, int currentPosition)  
      javax.json.JsonArray replace​(javax.json.JsonArray target, javax.json.JsonValue value)
      Replaces the value at the referenced location in the specified
      javax.json.JsonObject replace​(javax.json.JsonObject target, javax.json.JsonValue value)
      Replaces the value at the referenced location in the specified
      javax.json.JsonStructure replace​(javax.json.JsonStructure target, javax.json.JsonValue value)
      Replaces the value at the referenced location in the specified target with the specified value.
      java.lang.String toString()  
      private void validateAdd​(javax.json.JsonValue target)  
      private void validateArrayIndex​(java.lang.String referenceToken)  
      private void validateArraySize​(java.lang.String referenceToken, javax.json.JsonArray jsonArray, int arrayIndex, int arraySize)  
      private void validateJsonPointer​(javax.json.JsonValue target, int size)  
      private void validateRemove​(javax.json.JsonValue target)  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • provider

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

        private final java.lang.String jsonPointer
      • referenceTokens

        private final java.util.List<java.lang.String> referenceTokens
      • IS_NUMBER

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

      • equals

        public boolean equals​(java.lang.Object obj)
        Compares this JsonPointer with another object.
        Overrides:
        equals in class java.lang.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 java.lang.Object
        Returns:
        the hash code value for this JsonPointer object
      • getValue

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

        public boolean containsValue​(javax.json.JsonStructure target)
        Specified by:
        containsValue in interface javax.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 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 javax.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:
        java.lang.NullPointerException - if target is null
        javax.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 javax.json.JsonObject add​(javax.json.JsonObject target,
                                         javax.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:
        java.lang.NullPointerException - if target is null
        javax.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 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:
        java.lang.NullPointerException - if target is null
        javax.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 specified target with the specified value.
        Specified by:
        replace in interface javax.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:
        java.lang.NullPointerException - if target is null
        javax.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 this JsonPointer
        value - the value to be stored at the referenced location
        Returns:
        the transformed target after the value is replaced.
        Throws:
        java.lang.NullPointerException - if target is null
        javax.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 this JsonPointer
        value - the value to be stored at the referenced location
        Returns:
        the transformed target after the value is replaced.
        Throws:
        java.lang.NullPointerException - if target is null
        javax.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 specified target
        Specified by:
        remove in interface javax.json.JsonPointer
        Parameters:
        target - the target referenced by this JsonPointer
        Returns:
        the transformed target after the value is removed.
        Throws:
        java.lang.NullPointerException - if target is null
        javax.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 specified target
        Parameters:
        target - the target referenced by this JsonPointer
        Returns:
        the transformed target after the value is removed.
        Throws:
        java.lang.NullPointerException - if target is null
        javax.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 specified target
        Parameters:
        target - the target referenced by this JsonPointer
        Returns:
        the transformed target after the value is removed.
        Throws:
        java.lang.NullPointerException - if target is null
        javax.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:
        toString in class java.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.NullPointerException
        javax.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