Class ACollection<T extends ACell>

Type Parameters:
T - Type of elements in this collection
All Implemented Interfaces:
IValidated, IWriteable, Iterable<T>, Collection<T>
Direct Known Subclasses:
ASequence, ASet

public abstract class ACollection<T extends ACell> extends ADataStructure<T> implements Collection<T>
Abstract base class for Persistent Merkle Collections

A Collection is a data structure that contains zero or more elements. Possible collection subtypes include:

  • Sequential collections (Lists, Vectors)
  • Sets (with unique elements)
  • Constructor Details

    • ACollection

      protected ACollection(long count)
  • Method Details

    • getType

      public abstract AType getType()
      Description copied from class: ACell
      Gets the most specific known runtime Type for this Cell.
      Overrides:
      getType in class ACell
      Returns:
      The Type of this Call
    • encode

      public abstract int encode(byte[] bs, int pos)
      Description copied from class: ACell
      Writes this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.
      Specified by:
      encode in interface IWriteable
      Specified by:
      encode in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • contains

      public abstract boolean contains(Object o)
      Specified by:
      contains in interface Collection<T extends ACell>
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Collection<T extends ACell>
      Specified by:
      iterator in interface Iterable<T extends ACell>
    • add

      public final boolean add(T e)
      Specified by:
      add in interface Collection<T extends ACell>
    • remove

      public final boolean remove(Object o)
      Specified by:
      remove in interface Collection<T extends ACell>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Specified by:
      containsAll in interface Collection<T extends ACell>
    • addAll

      public final boolean addAll(Collection<? extends T> c)
      Specified by:
      addAll in interface Collection<T extends ACell>
    • removeAll

      public final boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<T extends ACell>
    • retainAll

      public final boolean retainAll(Collection<?> c)
      Specified by:
      retainAll in interface Collection<T extends ACell>
    • clear

      public final void clear()
      Specified by:
      clear in interface Collection<T extends ACell>
    • toVector

      public abstract <R extends ACell> AVector<R> toVector()
      Converts this collection to a canonical vector of elements
      Returns:
      This collection coerced to a vector
    • copyToArray

      protected abstract <R> void copyToArray(R[] arr, int offset)
      Copies the elements of this collection in order to an array at the specified offset
      Type Parameters:
      R - Type of array elements required
      Parameters:
      arr -
      offset -
    • toCellArray

      public ACell[] toCellArray()
      Converts this collection to a new Cell array
      Returns:
      A new cell array containing the elements of this sequence
    • toArray

      public <V> V[] toArray(V[] a)
      Specified by:
      toArray in interface Collection<T extends ACell>
    • conj

      public abstract <R extends ACell> ACollection<R> conj(R x)
      Adds an element to this collection, according to the natural semantics of the collection
      Specified by:
      conj in class ADataStructure<T extends ACell>
      Type Parameters:
      R - Type of Value added
      Parameters:
      x - Value to add, should be the element type of the data structure
      Returns:
      The updated collection
    • map

      public abstract <R extends ACell> ACollection<R> map(Function<? super T,​? extends R> mapper)
      Maps a function over a collection, applying it to each element in turn.
      Type Parameters:
      R - Type of element in resulting collection
      Parameters:
      mapper - Function to map over collection
      Returns:
      Collection after function applied to each element