Package convex.core.data
Class ARecord
- All Implemented Interfaces:
IAssociative<Keyword,
,ACell> IValidated
,IWriteable
,Map<Keyword,
ACell>
- Direct Known Subclasses:
AccountStatus
,ARecordGeneric
,ATransaction
,Belief
,Block
,BlockResult
,Order
,PeerStatus
,Receipt
,SignedData
,State
Base class for Record data types.
Records are Map-like data structures with fixed sets of Keyword 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, memorySize
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Accumulate all entries from this map in the given mutable Set.protected void
Accumulate all keys from this map in the given mutable Set.protected void
accumulateValues
(List<ACell> al) Accumulate all values from this map in the given mutable list.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.entryAt
(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.boolean
Returns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM should return false.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 mapprotected ARecord
Converts this Cell to a 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, isDataValue, isEmpty, size, toCVMString
Methods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, encode, encodeRaw, equals, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, getRef, getRefCount, hashCode, isEmbedded, 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
-
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. Non-canonical objects may be used on a temporary internal basis, they should be converted to canonical representations for general purpose use.- 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 a canonical version. Must return this Cell if already canonical, may be O(n) in size of value otherwise. Callers should usually use getCanonical(), which caches canonical instances once created- Specified by:
toCanonical
in classACell
- Returns:
- Canonical version of Cell
-
isCVMValue
public boolean isCVMValue()Description copied from class:ACell
Returns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM 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
-
getKeys
-
values
-
get
-
get
-
getTag
-
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
-
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
-
accumulateKeySet
-
accumulateValues
-
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
-
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
-
getEntryByHash
-
empty
-
getFormat
Gets the RecordFormat instance that describes this Record's layout- Returns:
- RecordFormat instance
-