Class CBORMap
- All Implemented Interfaces:
Cloneable,Comparable<CBORObject>
{} (map) objects.
Note: to maintain Deterministic Encoding map keys are automatically sorted during insertion.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceSupport interface for dynamic CBOR generation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(CBORObject key) Check CBOR map 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 CBOR map.Merge CBOR map.remove(CBORObject key) Remove mapped CBOR object.set(CBORObject key, CBORObject object) Set mapped CBOR object.setDynamic(CBORMap.Dynamic dynamic) Set CBOR data using an external (dynamic) interface.setSortingMode(boolean preSortedKeys) Set sorting mode for the CBOR map.intsize()Get size of the CBOR map.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, getDateTime, getEpochTime, getExtendedFloat64, getFloat16, getFloat32, getFloat64, getInt16, getInt32, getInt64, getInt8, getMap, getSimple, getString, getTag, getUint16, getUint32, getUint64, getUint8, hashCode, isNull, scan, toDiagnosticNotation, toString
-
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
Set mapped CBOR object.If
keyis already present, aCBORExceptionis thrown.Note that this implementation presumes that
Also seekeyobjects are immutable. To createkeyobjects of arbitrary complexity,keyobjects must either be created inline (using chaining), or be supplied as preset variables.update(CBORObject, CBORObject, boolean).- Parameters:
key- Key (name)object- Object (value)- Returns:
this- Throws:
CBORException
-
setDynamic
Set CBOR data using an external (dynamic) interface. Sample using a construct suitable for chained writing:setDynamic((wr) -> optionalString == null ? wr : wr.set(KEY, new CBORString(optionalString)));
- Parameters:
dynamic- Interface (usually Lambda)- Returns:
this- Throws:
CBORException
-
merge
Merge CBOR map.Note that a duplicate key causes a
CBORExceptionto be thrown.- Parameters:
map- Map to be merged into the current mao- Returns:
this- Throws:
CBORException
-
setSortingMode
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
setSortingModeis only effective during encoding. ThesetSortingModemethod may be called multiple times, permitting certain keys to be automatically sorted and others to be provided in a presorted fashion. See alsoCBORDecoder(InputStream, int, int).- Parameters:
preSortedKeys- Iftrue, keys must be sorted. If a key is not properly sorted when callingset(CBORObject, CBORObject), aCBORExceptionis thrown.- Returns:
this
-
get
Get mapped CBOR object.If
keyis present, the associatedobjectis returned, else aCBORExceptionis thrown.- Parameters:
key- Key (name)- Returns:
object- Throws:
CBORException
-
getConditionally
Get mapped CBOR object conditionally.If
keyis present, the associatedobjectis returned, elsedefaultObjectis returned. Note:defaultObjectmay benull.- Parameters:
key- Key (name)defaultObject- Default object (value)- Returns:
objectordefaultObject
-
containsKey
Check CBOR map for key presence.- Parameters:
key- Key (name)- Returns:
trueif the key is present
-
remove
Remove mapped CBOR object.If
keyis present, thekeyand associatedobjectare removed, else aCBORExceptionis thrown.- Parameters:
key- Key (name)- Returns:
- Removed object (value)
- Throws:
CBORException
-
update
Update mapped CBOR object.If
existingistrue,keymust already be present, else aCBORExceptionis thrown.If
existingisfalse, a map entry forkeywill 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 CBOR map.Note: the keys are returned in proper sort order.
- Returns:
- Array of keys
-