Package jsonvalues
Class Index
java.lang.Object
jsonvalues.Index
- All Implemented Interfaces:
Comparable<Position>,Position
Represents the index of a value in a JSON array.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionasIndex()Returns this index.asKey()Throws a UserError exception because an Index cannot be cast into a Key.intCompares this index with another given position.booleanReturns true if that is an index and both have the same value.inthashCode()Returns the hashcode of this index.booleanisIndex()Returns true.booleanisKey()Returns false.static Indexof(int index) Creates a new instance of the Index class representing the given index.toString()Returns the value of the index as a string.
-
Field Details
-
n
public final int nThe index number.
-
-
Method Details
-
of
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
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:
compareToin interfaceComparable<Position>- Parameters:
o- the given position to compare with- Returns:
- 0 if they are equal, +1 if this is greater, -1 otherwise
-
asKey
Throws a UserError exception because an Index cannot be cast into a Key. -
asIndex
Returns this index. -
isIndex
public boolean isIndex()Returns true. -
isKey
public boolean isKey()Returns false. -
hashCode
public int hashCode()Returns the hashcode of this index. -
equals
Returns true if that is an index and both have the same value. -
toString
Returns the value of the index as a string.
-