Package jsonvalues

Class Index

    • Field Detail

      • n

        public final int n
        The index number.
    • Method Detail

      • of

        public static Index of​(int index)
        Returns a new instance witch represents the given index in an array. The special index -1 points to the last element of an array.
        Parameters:
        index - the given position
        Returns:
        an Index object
        Throws:
        IndexOutOfBoundsException - if the index is less than -1
      • compareTo

        public int compareTo​(Position o)
        Compares this index with another given position. If the given position is an index, both are compared numerically, if it's a key, both are compared lexicographically.
        Specified by:
        compareTo in interface Comparable<Position>
        Specified by:
        compareTo in interface Position
        Parameters:
        o - the given position
        Returns:
        0 if they are equal, +1 if this is greater, -1 otherwise
      • isIndex

        public boolean isIndex()
        Returns true.
        Specified by:
        isIndex in interface Position
        Returns:
        true
      • isKey

        public boolean isKey()
        Returns false.
        Specified by:
        isKey in interface Position
        Returns:
        false
      • asKey

        public Key asKey()
        throws an UserError exception.
        Specified by:
        asKey in interface Position
        Returns:
        this position as a Key
        Throws:
        UserError - an Index can't be casted into a Key
      • asIndex

        public Index asIndex()
        Returns this index.
        Specified by:
        asIndex in interface Position
        Returns:
        this object
      • toString

        public String toString()
        Returns the value of the index as a string.
        Overrides:
        toString in class Object
        Returns:
        the value of the index as a string
      • equals

        public boolean equals​(@Nullable Object that)
        Returns true if that is an index and both have the same value.
        Overrides:
        equals in class Object
        Parameters:
        that - other object
        Returns:
        true if both objects are indexes representing the same position
      • hashCode

        public int hashCode()
        Returns the hashcode of this index.
        Overrides:
        hashCode in class Object
        Returns:
        the index value