Package jsonvalues

Class Index

  • All Implemented Interfaces:
    java.lang.Comparable<Position>, Position

    public final class Index
    extends java.lang.Object
    implements Position
    represents the index of a value in a json array.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int n
      The index number.
      static Prism<Position,​java.lang.Integer> prism
      prism between the sum type Position and Index
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Index asIndex()
      Returns this index.
      Key asKey()
      throws an UserError exception.
      int compareTo​(Position o)
      Compares this index with another given position.
      boolean equals​(java.lang.Object that)
      Returns true if that is an index and both have the same value.
      int hashCode()
      Returns the hashcode of this index.
      boolean isIndex()
      Returns true.
      boolean isKey()
      Returns false.
      static Index of​(int index)
      Returns a new instance witch represents the given index in an array.
      java.lang.String toString()
      Returns the value of the index as a string.
      • Methods inherited from class java.lang.Object

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

      • prism

        public static final Prism<Position,​java.lang.Integer> prism
        prism between the sum type Position and Index
      • 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:
        java.lang.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 java.lang.Comparable<Position>
        Parameters:
        o - the given position
        Returns:
        0 if they are equal, +1 if this is greater, -1 otherwise
      • 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 cast into a Key
      • asIndex

        public Index asIndex()
        Returns this index.
        Specified by:
        asIndex in interface Position
        Returns:
        this object
      • 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
      • hashCode

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

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

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