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 object)
      Set mapped CBOR object.

      If key is already present, a CBORException is thrown.

      Parameters:
      key - Key (name)
      object - Object (value)
      Returns:
      this
      Throws:
      CBORException
    • merge

      public CBORMap merge(CBORMap map)
      Merge CBOR map.

      Note that a duplicate key causes a CBORException to be thrown.

      Parameters:
      map - Map to be merged into the current mao
      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 object is returned, else a CBORException is thrown.

      Parameters:
      key - Key (name)
      Returns:
      object
      Throws:
      CBORException
    • getConditionally

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

      If key is present, the associated object is returned, else defaultObject is returned. Note: defaultObject may be null.

      Parameters:
      key - Key (name)
      defaultObject - Default object (value)
      Returns:
      object or defaultObject
    • containsKey

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

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

      If key is present, the key and associated object are removed, else a CBORException is thrown.

      Parameters:
      key - Key (name)
      Returns:
      Removed object (value)
      Throws:
      CBORException
    • update

      public CBORObject update(CBORObject key, CBORObject object, boolean existing)
      Update mapped CBOR object.

      If existing is true, key must already be present, else a CBORException is thrown.

      If existing is false, a map entry for key will be created if not already present.

      Parameters:
      key - Key (name)
      object - New object (value)
      existing - Flag
      Returns:
      Previous object. May be null.
      Throws:
      CBORException
    • getKeys

      public ArrayList<CBORObject> getKeys()
      Enumerate all keys in the CBOR map.

      Note: the keys are returned in proper sort order.

      Returns:
      Array of keys