Class ARecord

All Implemented Interfaces:
IValidated, IWriteable, Map<Keyword,​ACell>
Direct Known Subclasses:
AccountStatus, ARecordGeneric, Belief, Block, BlockResult, PeerStatus, State

public abstract class ARecord extends AMap<Keyword,​ACell>
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
  • Field Details

    • format

      protected final RecordFormat format
    • DEFAULT_VALUE

      public static final ARecord DEFAULT_VALUE
  • Constructor Details

  • Method Details

    • getType

      public AType getType()
      Description copied from class: ACell
      Gets the most specific known runtime Type for this Cell.
      Overrides:
      getType in class AMap<Keyword,​ACell>
      Returns:
      The Type of this Call
    • 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 class ACell
      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 class ACell
      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
      Specified by:
      encodeRaw in class ACell
      Parameters:
      bs - Array to write to
      pos - The offset into the byte array
      Returns:
      New position after writing
    • print

      public void print(StringBuilder sb)
      Description copied from class: AObject
      Prints this Object to a readable String Representation
      Overrides:
      print in class AMap<Keyword,​ACell>
      Parameters:
      sb - StringBuilder to append to
    • getKeys

      public final AVector<Keyword> getKeys()
      Gets a vector of keys for this record
      Returns:
      Vector of Keywords
    • values

      public AVector<ACell> values()
      Gets a vector of values for this record, in format-determined order
      Specified by:
      values in interface Map<Keyword,​ACell>
      Overrides:
      values in class AMap<Keyword,​ACell>
      Returns:
      Vector of Values
    • get

      public final ACell get(Object key)
      Gets the record field content for a given key, or null if not found.
      Specified by:
      get in interface Map<Keyword,​ACell>
      Overrides:
      get in class AMap<Keyword,​ACell>
      Parameters:
      key - Key to look up in this record
      Returns:
      Field value for the given key
    • get

      public abstract ACell get(ACell key)
      Gets the record field content for a given key, or null if not found.
      Specified by:
      get in class AMap<Keyword,​ACell>
      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.
      Specified by:
      getTag in class ACell
      Returns:
      Record tag byte
    • 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 class ACell
      Returns:
      The number of Refs in this Cell
    • getRef

      public <R extends ACell> Ref<R> getRef(int index)
      Description copied from class: ACell
      Gets a numbered child Ref from within this Cell.
      Overrides:
      getRef in class ACell
      Type Parameters:
      R - Type of referenced Cell
      Parameters:
      index - Index of ref to get
      Returns:
      The Ref at the specified index
    • updateRefs

      public ARecord updateRefs(IRefFunction func)
      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 class ACell
      Parameters:
      func - Ref update function
      Returns:
      Cell with updated Refs
    • getValuesArray

      public ACell[] getValuesArray()
      Gets an array containing all values in this record, in format-defined key order.
      Returns:
      Array of Values in this record
    • updateAll

      protected abstract ARecord updateAll(ACell[] newVals)
      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

      public boolean containsKey(ACell key)
      Description copied from class: ADataStructure
      Checks if the data structure contains the specified key
      Overrides:
      containsKey in class AMap<Keyword,​ACell>
      Parameters:
      key - Associative key to look up
      Returns:
      true if the data structure contains the key, false otherwise
    • containsValue

      public boolean containsValue(Object value)
    • keySet

      public Set<Keyword> keySet()
      Specified by:
      keySet in interface Map<Keyword,​ACell>
      Overrides:
      keySet in class AMap<Keyword,​ACell>
    • entrySet

      public Set<Map.Entry<Keyword,​ACell>> entrySet()
    • assoc

      public AMap<Keyword,​ACell> assoc(ACell key, ACell value)
      Description copied from class: AMap
      Associates the given key with the specified value.
      Specified by:
      assoc in class AMap<Keyword,​ACell>
      Parameters:
      key - Map key to associate
      value - Map value
      Returns:
      An updated map with the new association, or null if the association fails
    • dissoc

      public AMap<Keyword,​ACell> dissoc(Keyword key)
    • dissoc

      public AMap<Keyword,​ACell> dissoc(ACell key)
      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.
      Specified by:
      dissoc in class AMap<Keyword,​ACell>
      Parameters:
      key - Key to remove.
      Returns:
      Updated map
    • getKeyRefEntry

      public MapEntry<Keyword,​ACell> getKeyRefEntry(Ref<ACell> ref)
      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 class AMap<Keyword,​ACell>
      Parameters:
      ref - Ref to Map key
      Returns:
      MapEntry for the given key ref
    • accumulateEntrySet

      protected void accumulateEntrySet(HashSet<Map.Entry<Keyword,​ACell>> h)
      Description copied from class: AMap
      Accumulate all entries from this map in the given HashSet.
      Specified by:
      accumulateEntrySet in class AMap<Keyword,​ACell>
      Parameters:
      h - HashSet in which to accumulate entries
    • accumulateKeySet

      protected void accumulateKeySet(HashSet<Keyword> h)
      Description copied from class: AMap
      Accumulate all keys from this map in the given HashSet.
      Specified by:
      accumulateKeySet in class AMap<Keyword,​ACell>
      Parameters:
      h - HashSet in which to accumulate keys
    • accumulateValues

      protected void accumulateValues(ArrayList<ACell> al)
      Description copied from class: AMap
      Accumulate all values from this map in the given ArrayList.
      Specified by:
      accumulateValues in class AMap<Keyword,​ACell>
      Parameters:
      al - ArrayList in which to accumulate values
    • forEach

      public void forEach(BiConsumer<? super Keyword,​? super ACell> action)
      Specified by:
      forEach in interface Map<Keyword,​ACell>
      Specified by:
      forEach in class AMap<Keyword,​ACell>
    • assocEntry

      public AMap<Keyword,​ACell> assocEntry(MapEntry<Keyword,​ACell> e)
      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 class AMap<Keyword,​ACell>
      Parameters:
      e - A map entry
      Returns:
      The updated map
    • entryAt

      public MapEntry<Keyword,​ACell> entryAt(long i)
      Description copied from class: AMap
      Gets the entry in this map at a specified index, according to the map-specific order.
      Specified by:
      entryAt in class AMap<Keyword,​ACell>
      Parameters:
      i - Index of entry
      Returns:
      MapEntry at the specified index.
    • getEntry

      public MapEntry<Keyword,​ACell> getEntry(ACell k)
      Description copied from class: AMap
      Gets the MapEntry for the given key
      Specified by:
      getEntry in class AMap<Keyword,​ACell>
      Parameters:
      k - Key to lookup in Map
      Returns:
      The map entry, or null if the key is not found
    • reduceValues

      public <R> R reduceValues(BiFunction<? super R,​? super ACell,​? extends R> func, R initial)
      Description copied from class: AMap
      Reduce over all values in this map
      Specified by:
      reduceValues in class AMap<Keyword,​ACell>
      Type Parameters:
      R - Type of reduction return value
      Parameters:
      func - A function taking the reduction value and a map value
      initial - 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 class AMap<Keyword,​ACell>
      Type Parameters:
      R - Type of reduction return value
      Parameters:
      func - A function taking the reduction value and a map entry
      initial - Initial reduction value
      Returns:
      The final reduction value
    • equalsKeys

      public boolean equalsKeys(AMap<Keyword,​ACell> map)
      Description copied from class: AMap
      Returns true if this map has exactly the same keys as the other map
      Specified by:
      equalsKeys in class AMap<Keyword,​ACell>
      Parameters:
      map - Map to compare with
      Returns:
      true if maps have the same keys, false otherwise
    • toHashMap

      protected AHashMap<Keyword,​ACell> toHashMap()
      Converts this record to a hashmap
      Returns:
      HashMap instance
    • getEntryByHash

      protected MapEntry<Keyword,​ACell> getEntryByHash(Hash hash)
      Description copied from class: AMap
      Gets the map entry with the specified hash
      Specified by:
      getEntryByHash in class AMap<Keyword,​ACell>
      Parameters:
      hash - Hash of key to lookup
      Returns:
      The specified MapEntry, or null if not found.
    • empty

      public AHashMap<Keyword,​ACell> empty()
      Description copied from class: ADataStructure
      Returns an empty instance of the same general type as this data structure.
      Specified by:
      empty in class ADataStructure<MapEntry<Keyword,​ACell>>
      Returns:
      An empty data structure
    • getFormat

      public RecordFormat getFormat()
      Gets the RecordFormat instance that describes this Record's layout
      Returns:
      RecordFormat instance
    • toCanonical

      public ARecord toCanonical()
      Description copied from class: ACell
      Converts this Cell to its canonical version. Returns this if already canonical
      Specified by:
      toCanonical in class ACell
      Returns:
      Canonical version of Cell