Class CBORMap

All Implemented Interfaces:
Cloneable, Comparable<CBORObject>

public class CBORMap extends CBORObject
Class for holding CBOR map objects.

Note: to maintain Deterministic Encoding map keys are automatically sorted during insertion.

  • Constructor Details

    • CBORMap

      public CBORMap()
      Creates an empty CBOR map.

      Equivalent to CBORMap().setSortingMode(false).

  • Method Details

    • size

      public int size()
      Get size of the CBOR map.
      Returns:
      The number of entries (keys) in the map
    • set

      public CBORMap set(CBORObject key, CBORObject value)
      Set mapped CBOR object.

      If key is already present, a CBORException is thrown.

      Parameters:
      key - Key
      value - Value
      Returns:
      this
      Throws:
      CBORException
    • setSortingMode

      public CBORMap setSortingMode(boolean preSortedKeys)
      Set sorting mode for the CBOR map.

      This method provides an opportunity using keys that are presorted (in lexicographic order), which in maps with many keys can offer performance improvements.

      Note that setSortingMode is only effective during encoding. The setSortingMode method may be called multiple times, permitting certain keys to be automatically sorted and others to be provided in a presorted fashion. See also CBORDecoder.setDeterministicMode(boolean).

      Parameters:
      preSortedKeys - If true, keys must be sorted. If a key is not properly sorted when calling set(CBORObject, CBORObject), a CBORException is thrown.
      Returns:
      this
    • get

      public CBORObject get(CBORObject key)
      Get mapped CBOR object.

      If key is present, the associated value is returned, else a CBORException is thrown.

      Parameters:
      key - Key
      Returns:
      value
      Throws:
      CBORException
    • getConditionally

      public CBORObject getConditionally(CBORObject key, CBORObject defaultValue)
      Get mapped CBOR object conditionally.

      If key is present, the associated value is returned, else defaultValue is returned. Note: defaultValue may be null.

      Parameters:
      key - Key
      defaultValue - Default value
      Returns:
      value or defaultValue
    • containsKey

      public boolean containsKey(CBORObject key)
      Check CBOR map for key presence.
      Parameters:
      key - Key
      Returns:
      true if the key is present
    • remove

      public CBORObject remove(CBORObject key)
      Remove mapped CBOR object.

      If key is present, the associated value is returned, else a CBORException is thrown.

      After saving value for return, the key and its associated value are removed.

      Parameters:
      key - Key
      Returns:
      value
      Throws:
      CBORException
    • getKeys

      public CBORObject[] getKeys()
      Enumerate all keys in the CBOR map.

      Note: the keys are returned in proper sort order.

      Returns:
      Array of keys