Package convex.core.data
Class ARecord
java.lang.Object
- All Implemented Interfaces:
IAssociative<Keyword,
,ACell> IValidated
,IWriteable
,Map<Keyword,
ACell>
- Direct Known Subclasses:
AccountStatus
,ARecordGeneric
,ATransaction
,Belief
,Block
,BlockResult
,Order
,PeerStatus
,SignedData
,State
Base class for Record data types.
Records are Map-like data structures with fixed sets of keys, and optional custom behaviour.
Ordering of fields is defined by the Record's RecordFormat
-
Nested Class Summary
-
Field Summary
FieldsFields inherited from class convex.core.data.ADataStructure
count
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Accumulate all entries from this map in the given HashSet.protected void
Accumulate all keys from this map in the given HashSet.protected void
Accumulate all values from this map in the given ArrayList.Associates the given key with the specified value.Associate the given map entry into the map.boolean
containsKey
(ACell key) Checks if the data structure contains the specified keyboolean
containsValue
(ACell value) CHecks if this map contains the given value.Dissociates a key from this map, returning an updated map if the key was removed, or the same unchanged map if the key is not present.empty()
Returns an empty instance of the same Type as this data structure.int
encodeRaw
(byte[] bs, int pos) Writes the raw fields of this record in declared orderentryAt
(long i) Gets the entry in this map at a specified index, according to the map-specific order.entrySet()
int
Estimate the encoded data size for this Cell.void
forEach
(BiConsumer<? super Keyword, ? super ACell> action) final ACell
Gets the record field content for a given key, or null if not found.abstract ACell
Gets the record field content for a given key, or null if not found.Gets the MapEntry for the given keygetEntryByHash
(Hash hash) Gets the map entry with the specified hashabstract RecordFormat
Gets the RecordFormat instance that describes this Record's layoutgetKeyRefEntry
(Ref<ACell> keyRef) Get an entry given a Ref to the key value.getKeys()
Gets a vector of keys for this recordabstract byte
getTag()
Gets the tag byte for this record type.getType()
Gets the most specific known runtime Type for this Cell.ACell[]
Gets an array containing all values in this record, in format-defined key order.boolean
Returns true if this Cell is in a canonical representation for message writing.boolean
Returns true if this Cell represents a first class CVM Value.keySet()
<R> R
reduceEntries
(BiFunction<? super R, MapEntry<Keyword, ACell>, ? extends R> func, R initial) Reduce over all map entries in this map<R> R
reduceValues
(BiFunction<? super R, ? super ACell, ? extends R> func, R initial) Reduce over all values in this mapConverts this Cell to its canonical version.Converts this record to a HashMapvalues()
Gets a vector of values for this Record, in format-determined orderMethods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, containsValue, entryVector, filterValues, get, get, get, getElementRef, merge, print, put, putAll, remove, slice, slice
Methods inherited from class convex.core.data.ADataStructure
checkIndex, conjAll, count, isEmpty, size, toCVMString
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, encode, equals, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, getRefCount, hashCode, isCompletelyEncoded, isEmbedded, mark, mark, toString, updateRefs, validate, validateCell
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll, size
-
Field Details
-
DEFAULT_VALUE
-
-
Constructor Details
-
ARecord
protected ARecord(long n)
-
-
Method Details
-
getType
Description copied from class:ACell
Gets the most specific known runtime Type for this Cell. -
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteable
Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is highly likely to contain the entire object when encoded, including the tag byte. Should not traverse soft Refs, i.e. must be usable on arbitrary partial data structures- Returns:
- The estimated size for the binary representation of this object.
-
isCanonical
public boolean isCanonical()Description copied from class:ACell
Returns true if this Cell is in a canonical representation for message writing. Non-canonical objects may be used on a temporary internal basis, they must always be converted to canonical representations for external use (e.g. Encoding).- Specified by:
isCanonical
in classACell
- Returns:
- true if the object is in canonical format, false otherwise
-
toCanonical
Description copied from class:ACell
Converts this Cell to its canonical version. Must return this Cell if already canonical, may be O(n) in size of value otherwise.- Specified by:
toCanonical
in classACell
- Returns:
- Canonical version of Cell
-
isCVMValue
public boolean isCVMValue()Description copied from class:ACell
Returns true if this Cell represents a first class CVM Value. Sub-structural cells that are not themselves first class values should return false, pretty much everything else should return true. Note: CVM values might not be in a canonical format, e.g. temporary data structures- Specified by:
isCVMValue
in classACell
- Returns:
- true if the object is a CVM Value, false otherwise
-
encodeRaw
public int encodeRaw(byte[] bs, int pos) Writes the raw fields of this record in declared order -
getKeys
Gets a vector of keys for this record -
values
Gets a vector of values for this Record, in format-determined order -
get
Gets the record field content for a given key, or null if not found. -
get
Gets the record field content for a given key, or null if not found.- Parameters:
key
- Key to look up in this record- Returns:
- Field value for the given key
-
getTag
public abstract byte getTag()Gets the tag byte for this record type. The Tag is the byte used to identify the record in the binary encoding. -
getValuesArray
Gets an array containing all values in this record, in format-defined key order.- Returns:
- Array of Values in this record
-
containsKey
Description copied from class:ADataStructure
Checks if the data structure contains the specified key- Overrides:
containsKey
in classAMap<Keyword,
ACell> - Parameters:
key
- Associative key to look up- Returns:
- true if the data structure contains the key, false otherwise
-
containsValue
Description copied from class:AMap
CHecks if this map contains the given value. WARNING: probably O(n)- Specified by:
containsValue
in classAMap<Keyword,
ACell> - Parameters:
value
- Value to check- Returns:
- true if map contains value, false otherwise
-
keySet
-
entrySet
-
assoc
Description copied from class:AMap
Associates the given key with the specified value. -
dissoc
-
dissoc
Description copied from class:AMap
Dissociates a key from this map, returning an updated map if the key was removed, or the same unchanged map if the key is not present. -
getKeyRefEntry
Description copied from class:AMap
Get an entry given a Ref to the key value. This is more efficient than directly looking up using the key for some map types, and should be preferred if the caller already has a Ref available.- Specified by:
getKeyRefEntry
in classAMap<Keyword,
ACell> - Parameters:
keyRef
- Ref to Map key- Returns:
- MapEntry for the given key ref
-
accumulateEntrySet
Description copied from class:AMap
Accumulate all entries from this map in the given HashSet.- Specified by:
accumulateEntrySet
in classAMap<Keyword,
ACell> - Parameters:
h
- HashSet in which to accumulate entries
-
accumulateKeySet
Description copied from class:AMap
Accumulate all keys from this map in the given HashSet.- Specified by:
accumulateKeySet
in classAMap<Keyword,
ACell> - Parameters:
h
- HashSet in which to accumulate keys
-
accumulateValues
Description copied from class:AMap
Accumulate all values from this map in the given ArrayList.- Specified by:
accumulateValues
in classAMap<Keyword,
ACell> - Parameters:
al
- ArrayList in which to accumulate values
-
forEach
-
assocEntry
Description copied from class:AMap
Associate the given map entry into the map. May return null if the map entry is not valid for this map type.- Specified by:
assocEntry
in classAMap<Keyword,
ACell> - Parameters:
e
- A map entry- Returns:
- The updated map
-
entryAt
Description copied from class:AMap
Gets the entry in this map at a specified index, according to the map-specific order. Caller responsible for bounds check! -
getEntry
Description copied from class:AMap
Gets the MapEntry for the given key -
reduceValues
Description copied from class:AMap
Reduce over all values in this map- Specified by:
reduceValues
in classAMap<Keyword,
ACell> - Type Parameters:
R
- Type of reduction return value- Parameters:
func
- A function taking the reduction value and a map valueinitial
- Initial reduction value- Returns:
- The final reduction value
-
reduceEntries
public <R> R reduceEntries(BiFunction<? super R, MapEntry<Keyword, ACell>, ? extends R> func, R initial) Description copied from class:AMap
Reduce over all map entries in this map- Specified by:
reduceEntries
in classAMap<Keyword,
ACell> - Type Parameters:
R
- Type of reduction return value- Parameters:
func
- A function taking the reduction value and a map entryinitial
- Initial reduction value- Returns:
- The final reduction value
-
toHashMap
Converts this record to a HashMap- Returns:
- HashMap instance
-
getEntryByHash
Description copied from class:AMap
Gets the map entry with the specified hash- Specified by:
getEntryByHash
in classAMap<Keyword,
ACell> - Parameters:
hash
- Hash of key to lookup- Returns:
- The specified MapEntry, or null if not found.
-
empty
Description copied from class:ADataStructure
Returns an empty instance of the same Type as this data structure.- Specified by:
empty
in classADataStructure<MapEntry<Keyword,
ACell>> - Returns:
- An empty data structure
-
getFormat
Gets the RecordFormat instance that describes this Record's layout- Returns:
- RecordFormat instance
-