Package jsonvalues

Class Key

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

    public final class Key
    extends java.lang.Object
    implements Position
    represents the key of a value in a json object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.lang.String name
      name of the key.
      static Prism<Position,​java.lang.String> prism
      prism between the sum type Position and Key
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Index asIndex()
      throws an UserError exception.
      Key asKey()
      Returns this key.
      int compareTo​(Position o)
      compares this key with another given position.
      boolean equals​(java.lang.Object that)
      Returns true if that is a key and both have the same name.
      int hashCode()
      Returns the hashcode of this key.
      boolean isIndex()
      Returns false.
      boolean isKey()
      Returns true.
      static Key of​(java.lang.String key)
      Returns a new instance which represents a key with the given name in a json object.
      java.lang.String toString()
      Returns the name of the key.
      • 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.String> prism
        prism between the sum type Position and Key
      • name

        public final java.lang.String name
        name of the key.
    • Method Detail

      • of

        public static Key of​(java.lang.String key)
        Returns a new instance which represents a key with the given name in a json object. Any string, but 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

        public int compareTo​(Position o)
        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:
        compareTo in interface java.lang.Comparable<Position>
        Specified by:
        compareTo in interface Position
        Parameters:
        o - the given position
        Returns:
        0 if they are equal, +1 if this is greater, -1 otherwise
      • asKey

        public Key asKey()
        Returns this key.
        Specified by:
        asKey in interface Position
        Returns:
        this object
      • asIndex

        public Index asIndex()
        throws an UserError exception.
        Specified by:
        asIndex in interface Position
        Returns:
        this position as an Index
        Throws:
        UserError - a Key can't be casted into an Index
      • isIndex

        public boolean isIndex()
        Returns false.
        Specified by:
        isIndex in interface Position
        Returns:
        false
      • isKey

        public boolean isKey()
        Returns true.
        Specified by:
        isKey in interface Position
        Returns:
        true
      • hashCode

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

        public boolean equals​(java.lang.Object that)
        Returns true if that is a key and both have the same name.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        that - other object
        Returns:
        true if both object are Keys with the same name
      • toString

        public java.lang.String toString()
        Returns the name of the key.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the name of the key