Package jsonvalues
Class Key
java.lang.Object
jsonvalues.Key
- All Implemented Interfaces:
Comparable<Position>,Position
Represents the key of a value in a JSON object.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionasIndex()Throws a UserError exception.asKey()Returns this key.intCompares this key with another given position.booleanReturns true if that is a key and both have the same name.inthashCode()Returns the hashcode of this key.booleanisIndex()Returns false.booleanisKey()Returns true.static KeyReturns a new instance representing a key with the given name in a JSON object.toString()Returns the name of the key.
-
Field Details
-
name
The name of the key.
-
-
Method Details
-
of
Returns a new instance representing a key with the given name in a JSON object. Any string, except null, can represent a key in a JSON object, even the empty string.- Parameters:
key- the given name of the key- Returns:
- a new Key object
-
compareTo
Compares this key with another given position. If the given position is a key, both are compared lexicographically. If it's an index, both are compared numerically.- Specified by:
compareToin interfaceComparable<Position>- Parameters:
o- the given position- Returns:
- 0 if they are equal, +1 if this is greater, -1 otherwise
-
asKey
Returns this key. -
asIndex
Throws a UserError exception. -
isIndex
public boolean isIndex()Returns false. -
isKey
public boolean isKey()Returns true. -
hashCode
public int hashCode()Returns the hashcode of this key. -
equals
Returns true if that is a key and both have the same name. -
toString
Returns the name of the key.
-