Class ARecord

All Implemented Interfaces:
IAssociative<Keyword,ACell>, IValidated, IWriteable, Map<Keyword,ACell>
Direct Known Subclasses:
AccountStatus, ARecordGeneric, ATransaction, Belief, Block, BlockResult, Order, PeerStatus, SignedData, 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

    • DEFAULT_VALUE

      public static final ARecord DEFAULT_VALUE
  • Constructor Details

    • ARecord

      protected ARecord(long n)
  • 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 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 class ACell
      Returns:
      true if the object is in canonical format, false otherwise
    • toCanonical

      public ARecord 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 class ACell
      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 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
    • getKeys

      public final AVector<Keyword> getKeys()
      Gets a vector of keys for this record
      Overrides:
      getKeys in class AMap<Keyword,ACell>
      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(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
    • get

      public abstract ACell get(Keyword key)
      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.
      Specified by:
      getTag in class ACell
      Returns:
      Record tag byte
    • 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
    • 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(ACell value)
      Description copied from class: AMap
      CHecks if this map contains the given value. WARNING: probably O(n)
      Specified by:
      containsValue in class AMap<Keyword,ACell>
      Parameters:
      value - Value to check
      Returns:
      true if map contains value, false otherwise
    • 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> keyRef)
      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:
      keyRef - 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. Caller responsible for bounds check!
      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
    • 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 Type as this data structure.
      Specified by:
      empty in class ADataStructure<MapEntry<Keyword,ACell>>
      Returns:
      An empty data structure
    • getFormat

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