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 defaultObject) Get mapped CBOR object conditionally.getKeys()
Enumerate all keys in the CBORmap
.Merge CBOR map.remove
(CBORObject key) Remove mapped CBOR object.set
(CBORObject key, CBORObject object) Set mapped CBOR object.setSortingMode
(boolean preSortedKeys) Set sorting mode for the CBORmap
.int
size()
Get size of the CBORmap
.update
(CBORObject key, CBORObject object, boolean existing) Update mapped CBOR object.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
- Key (name)object
- Object (value)- Returns:
this
- Throws:
CBORException
-
merge
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
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 associatedobject
is returned, else aCBORException
is thrown.- Parameters:
key
- Key (name)- Returns:
object
- Throws:
CBORException
-
getConditionally
Get mapped CBOR object conditionally.If
key
is present, the associatedobject
is returned, elsedefaultObject
is returned. Note:defaultObject
may benull
.- Parameters:
key
- Key (name)defaultObject
- Default object (value)- Returns:
object
ordefaultObject
-
containsKey
Check CBORmap
for key presence.- Parameters:
key
- Key (name)- Returns:
true
if the key is present
-
remove
Remove mapped CBOR object.If
key
is present, thekey
and associatedobject
are removed, else aCBORException
is thrown.- Parameters:
key
- Key (name)- Returns:
- Removed object (value)
- Throws:
CBORException
-
update
Update mapped CBOR object.If
existing
istrue
,key
must already be present, else aCBORException
is thrown.If
existing
isfalse
, amap
entry forkey
will be created if not already present.- Parameters:
key
- Key (name)object
- New object (value)existing
- Flag- Returns:
- Previous
object
. May benull
. - Throws:
CBORException
-
getKeys
Enumerate all keys in the CBORmap
.Note: the keys are returned in proper sort order.
- Returns:
- Array of keys
-