Package jsonvalues

Class Index

java.lang.Object
jsonvalues.Index
All Implemented Interfaces:
Comparable<Position>, Position

public final class Index extends Object implements Position
Represents the index of a value in a JSON array.
  • Field Summary Link icon

    Fields
    Modifier and Type
    Field
    Description
    final int
    The index number.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    Returns this index.
    Throws a UserError exception because an Index cannot be cast into a Key.
    int
    Compares this index with another given position.
    boolean
    equals(Object that)
    Returns true if that is an index and both have the same value.
    int
    Returns the hashcode of this index.
    boolean
    Returns true.
    boolean
    Returns false.
    static Index
    of(int index)
    Creates a new instance of the Index class representing the given index.
    Returns the value of the index as a string.

    Methods inherited from class java.lang.Object Link icon

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface jsonvalues.Position Link icon

    isIndex, isKey, match
  • Field Details Link icon

    • n Link icon

      public final int n
      The index number.
  • Method Details Link icon

    • of Link icon

      public static Index of(int index)
      Creates a new instance of the Index class representing the given index.
      Parameters:
      index - the index to represent
      Returns:
      an Index object
      Throws:
      IndexOutOfBoundsException - if the index is less than -1
    • compareTo Link icon

      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>
      Parameters:
      o - the given position to compare with
      Returns:
      0 if they are equal, +1 if this is greater, -1 otherwise
    • asKey Link icon

      public Key asKey()
      Throws a UserError exception because an Index cannot be cast into a Key.
      Specified by:
      asKey in interface Position
      Returns:
      never returns, throws UserError
      Throws:
      UserError - always throws a UserError
    • asIndex Link icon

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

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

      public boolean isKey()
      Returns false.
      Specified by:
      isKey in interface Position
      Returns:
      false
    • hashCode Link icon

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

      public boolean equals(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
    • toString Link icon

      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