Class CBORMap
- All Implemented Interfaces:
Cloneable
,Comparable<CBORObject>
map
objects.
Note: to maintain
Deterministic Encoding
map
keys are automatically sorted during insertion.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(CBORObject key) Check CBORmap
for key presence.get
(CBORObject key) Get mapped CBOR object.getConditionally
(CBORObject key, CBORObject defaultValue) Get mapped CBOR object conditionally.getKeys()
Enumerate all keys in the CBORmap
.remove
(CBORObject key) Remove mapped CBOR object.set
(CBORObject key, CBORObject value) Set mapped CBOR object.setSortingMode
(boolean preSortedKeys) Set sorting mode for the CBORmap
.int
size()
Get size of the CBORmap
.Methods inherited from class org.webpki.cbor.CBORObject
checkForUnread, clone, compareTo, encode, equals, getArray, getBigInteger, getBoolean, getBytes, getFloat16, getFloat32, getFloat64, getInt16, getInt32, getInt64, getInt8, getMap, getString, getTag, getUint16, getUint32, getUint64, getUint8, 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()Get size of the CBORmap
.- Returns:
- The number of entries (keys) in the map
-
set
Set mapped CBOR object.If
key
is already present, aCBORException
is thrown.- Parameters:
key
- Keyvalue
- Value- Returns:
this
- Throws:
CBORException
-
setSortingMode
Set sorting mode for the CBORmap
.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. ThesetSortingMode
method may be called multiple times, permitting certain keys to be automatically sorted and others to be provided in a presorted fashion. See alsoCBORDecoder.setDeterministicMode(boolean)
.- Parameters:
preSortedKeys
- Iftrue
, keys must be sorted. If a key is not properly sorted when callingset(CBORObject, CBORObject)
, aCBORException
is thrown.- Returns:
this
-
get
Get mapped CBOR object.If
key
is present, the associatedvalue
is returned, else aCBORException
is thrown.- Parameters:
key
- Key- Returns:
value
- Throws:
CBORException
-
getConditionally
Get mapped CBOR object conditionally.If
key
is present, the associatedvalue
is returned, elsedefaultValue
is returned. Note:defaultValue
may benull
.- Parameters:
key
- KeydefaultValue
- Default value- Returns:
value
ordefaultValue
-
containsKey
Check CBORmap
for key presence.- Parameters:
key
- Key- Returns:
true
if the key is present
-
remove
Remove mapped CBOR object.If
key
is present, the associatedvalue
is returned, else aCBORException
is thrown.After saving
value
for return, thekey
and its associatedvalue
are removed.- Parameters:
key
- Key- Returns:
value
- Throws:
CBORException
-
getKeys
Enumerate all keys in the CBORmap
.Note: the keys are returned in proper sort order.
- Returns:
- Array of keys
-