Class CBORMap
- All Implemented Interfaces:
Cloneable
map
objects.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(CBORObject key) Checks map for key presence.get
(CBORObject key) Returns mapped object.getConditionally
(CBORObject key, CBORObject defaultValue) Returns mapped object conditionally.getKeys()
Enumerates all keys in a map.remove
(CBORObject key) Removes mapped object.set
(CBORObject key, CBORObject value) Sets mapped object.setSortingMode
(boolean preSortedKeys) Sets sorting mode for a CBORmap
.int
size()
Returns the size of the map.Methods inherited from class org.webpki.cbor.CBORObject
checkForUnread, clone, decode, decode, encode, equals, getArray, getBigInteger, getBoolean, getByte, getBytes, getDouble, getFloat, getInt, getLong, getMap, getShort, getString, getTag, getType, getUnsignedByte, getUnsignedInt, getUnsignedLong, getUnsignedShort, hashCode, isNull, scan, toDiagnosticNotation, toString
-
Constructor Details
-
CBORMap
public CBORMap()Creates an empty CBORmap
.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
Sets mapped object.If
key
is already present, aCBORException
is thrown.- Parameters:
key
- Keyvalue
- Value- Returns:
this
-
setSortingMode
Sets sorting mode for a CBORmap
.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. ThesetSortingMode
method may be called multiple times, permitting certain keys to be automatically sorted and others to be provided in a presorted fashion. See alsoCBORObject.decode(java.io.InputStream, boolean, boolean, Integer)
.- Parameters:
preSortedKeys
- Iftrue
, keys must be sorted. If a key is not properly sorted when callingset(CBORObject, CBORObject)
, aCBORException
is thrown.- Returns:
this
-
get
Returns mapped object.If
key
is not present, aCBORException
is thrown.- Parameters:
key
- Key- Returns:
CBORObject
-
getConditionally
Returns mapped object conditionally.If
key
is not present,defaultValue
is returned.defaultValue
may benull
.- Parameters:
key
- KeydefaultValue
- Default value- Returns:
CBORObject
ordefaultValue
-
containsKey
Checks map for key presence.- Parameters:
key
- Key- Returns:
true
if the key is present
-
remove
Removes mapped object.If
key
is not present, aCBORException
is thrown.- Parameters:
key
- Key- Returns:
- The
CBORObject
mapped bykey
-
getKeys
Enumerates all keys in a map.- Returns:
- Array of keys
-