Class CBORMap

All Implemented Interfaces:
Cloneable

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

    • CBORMap

      public CBORMap()
      Creates an empty CBOR map.

      Equivalent to CBORMap().setSortingMode(false).

  • Method Details

    • size

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

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

      If key is already present, a CBORException is thrown.

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

      public CBORMap setSortingMode(boolean preSortedKeys)
      Sets sorting mode for a CBOR map.

      This method provides an opportunity using keys that are sorted (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 CBORObject.decode(java.io.InputStream, boolean, boolean, Integer).

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

      If key is not present, a CBORException is thrown.

      Parameters:
      key - Key
      Returns:
      CBORObject
    • getConditionally

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

      If key is not present, defaultValue is returned. defaultValue may be null.

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

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

      public CBORObject remove(CBORObject key)
      Removes mapped object.

      If key is not present, a CBORException is thrown.

      Parameters:
      key - Key
      Returns:
      The CBORObject mapped by key
    • getKeys

      public CBORObject[] getKeys()
      Enumerates all keys in a map.
      Returns:
      Array of keys