Package convex.core.data
Class ARecord
java.lang.Object
- All Implemented Interfaces:
IValidated
,IWriteable
,Map<Keyword,ACell>
- Direct Known Subclasses:
AccountStatus
,ARecordGeneric
,Belief
,Block
,BlockResult
,PeerStatus
,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
accumulateValues(ArrayList<ACell> al)
Accumulate all values from this map in the given ArrayList.Associates the given key with the specified value.assocEntry(MapEntry<Keyword,ACell> e)
Associate the given map entry into the map.boolean
containsKey(ACell key)
Checks if the data structure contains the specified keyboolean
containsValue(Object 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 general 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()
boolean
equalsKeys(AMap<Keyword,ACell> map)
Returns true if this map has exactly the same keys as the other mapint
Estimate the encoded data size for this Cell.void
forEach(BiConsumer<? super Keyword,? super ACell> action)
abstract ACell
Gets the record field content for a given key, or null if not found.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 hashGets the RecordFormat instance that describes this Record's layoutgetKeyRefEntry(Ref<ACell> ref)
Get an entry given a Ref to the key value.getKeys()
Gets a vector of keys for this recordgetRef(int index)
Gets a numbered child Ref from within this Cell.int
Gets the number of Refs contained within this Cell.abstract 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 format for message writing.boolean
Returns true if this object represents a first class CVM Value.keySet()
void
print(StringBuilder sb)
Prints this Object to a readable String Representation<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 hashmapprotected abstract ARecord
Updates all values in this record, in declared field order.updateRefs(IRefFunction func)
Updates all Refs in this object using the given function.values()
Gets a vector of values for this record, in format-determined orderMethods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, entryVector, equals, equals, filterValues, get, get, getElementRef, put, putAll, remove
Methods inherited from class convex.core.data.ADataStructure
conjAll, count, isEmpty, size
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, encode, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, hashCode, isEmbedded, mark, mark, toString, validate, validateCell, write
Methods inherited from class convex.core.data.AObject
attachEncoding, 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
-
format
-
DEFAULT_VALUE
-
-
Constructor Details
-
ARecord
-
-
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 likely to contain the entire object when represented in binary format, including the tag byte.- 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 format for message writing. Reading or writing a non-canonical value should be considered illegal, but non-canonical objects may be used on a temporary internal basis.- Specified by:
isCanonical
in classACell
- Returns:
- true if the object is in canonical format, false otherwise
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACell
Returns true if this object represents a first class CVM Value. Sub-structural cells that are not themselves first class values should return false. 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 -
print
Description copied from class:AObject
Prints this Object to a readable String Representation -
getKeys
Gets a vector of keys for this record- Returns:
- Vector of Keywords
-
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. -
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. -
getRefCount
public int getRefCount()Description copied from class:ACell
Gets the number of Refs contained within this Cell. This number is final / immutable for any given instance. Contained Refs may be either external or embedded.- Specified by:
getRefCount
in classACell
- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACell
Gets a numbered child Ref from within this Cell. -
updateRefs
Description copied from class:ACell
Updates all Refs in this object using the given function. The function *must not* change the hash value of Refs, in order to ensure structural integrity of modified data structures. This is a building block for a very sneaky trick that enables use to do a lot of efficient operations on large trees of smart references. Must return the same object if no Refs are altered.- Overrides:
updateRefs
in classACell
- Parameters:
func
- Ref update function- Returns:
- Cell with updated Refs
-
getValuesArray
Gets an array containing all values in this record, in format-defined key order.- Returns:
- Array of Values in this record
-
updateAll
Updates all values in this record, in declared field order. Returns this if all values are identical.- Parameters:
newVals
- New values to replace current- Returns:
- Updated 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:
ref
- 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. -
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
-
equalsKeys
Description copied from class:AMap
Returns true if this map has exactly the same keys as the other map- Specified by:
equalsKeys
in classAMap<Keyword,ACell>
- Parameters:
map
- Map to compare with- Returns:
- true if maps have the same keys, false otherwise
-
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 general 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
-
toCanonical
Description copied from class:ACell
Converts this Cell to its canonical version. Returns this if already canonical- Specified by:
toCanonical
in classACell
- Returns:
- Canonical version of Cell
-