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 JsElem in a JsArray.
-
-
Field Summary
Fields Modifier and Type Field Description int
n
The index number.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Index
asIndex()
Returns this index.Key
asKey()
Throws an UnsupportedOperationException.int
compareTo(Position o)
Compares this index with another given position.boolean
equals(@Nullable 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.String
toString()
Returns the value of the index as a string.
-
-
-
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 interfaceComparable<Position>
- Specified by:
compareTo
in interfacePosition
- Parameters:
o
- the given position- Returns:
- 0 if they are equal, +1 if this is greater, -1 otherwise
-
isIndex
public boolean isIndex()
Returns true.
-
isKey
public boolean isKey()
Returns false.
-
asKey
public Key asKey()
Throws an UnsupportedOperationException.- Specified by:
asKey
in interfacePosition
- Returns:
- this position as a Key
- Throws:
UnsupportedOperationException
- an Index can't be casted into an Key
-
asIndex
public Index asIndex()
Returns this index.
-
toString
public String toString()
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.
-
-