Class ASequence<T extends ACell>

Type Parameters:
T - Type of list elements
All Implemented Interfaces:
IAssociative<CVMLong,​T>, IValidated, IWriteable, Iterable<T>, Collection<T>, List<T>
Direct Known Subclasses:
AList, AVector

public abstract class ASequence<T extends ACell> extends ACollection<T> implements List<T>, IAssociative<CVMLong,​T>
Abstract base class for persistent lists and vectors
  • Constructor Details

    • ASequence

      public ASequence(long count)
  • Method Details

    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<T extends ACell>
      Specified by:
      contains in interface List<T extends ACell>
      Specified by:
      contains in class ACollection<T extends ACell>
    • longIndexOf

      public abstract long longIndexOf(Object value)
      Gets the first long index at which the specified value appears in the the sequence.
      Parameters:
      value - Any value which could appear as an element of the sequence.
      Returns:
      Index of the value, or -1 if not found.
    • longLastIndexOf

      public abstract long longLastIndexOf(Object value)
      Gets the last long index at which the specified value appears in the the sequence.
      Parameters:
      value - Any value which could appear as an element of the sequence.
      Returns:
      Index of the value, or -1 if not found.
    • map

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

      public abstract void forEach(Consumer<? super T> action)
      Specified by:
      forEach in interface Iterable<T extends ACell>
    • visitElementRefs

      public abstract void visitElementRefs(Consumer<Ref<T>> f)
      Visits all elements in this sequence, calling the specified consumer for each.
      Parameters:
      f - Function to call for each element
    • flatMap

      public <R extends ACell> ASequence<R> flatMap(Function<? super T,​? extends ASequence<R>> mapper)
    • concat

      public abstract <R extends ACell> ASequence<R> concat(ASequence<R> vals)
      Concatenates the elements from another sequence to the end of this sequence. Potentially O(n) in size of resulting sequence
      Parameters:
      vals - A sequence of values to concatenate.
      Returns:
      The concatenated sequence, of the same type as this sequence.
    • addAll

      public final boolean addAll(int index, Collection<? extends T> c)
      Specified by:
      addAll in interface List<T extends ACell>
    • next

      public abstract ASequence<T> next()
      Gets the sequence of all elements after the first, or null if no elements remain
      Returns:
      Sequence following the first element
    • get

      public T get(int index)
      Gets the element at the specified index in this sequence. Behaves as if the index was considered as a long
      Specified by:
      get in interface List<T extends ACell>
      Parameters:
      index - Index of element to get
      Returns:
      Element at the specified index
    • get

      public abstract T get(long index)
      Description copied from class: ACountable
      Gets the element at the specified index in this collection
      Specified by:
      get in class ACountable<T extends ACell>
      Parameters:
      index - Index of element to get
      Returns:
      Element at the specified index
    • get

      public T get(ACell key)
      Gets the element at the specified key
      Specified by:
      get in class ADataStructure<T extends ACell>
      Parameters:
      key - Key of element to get
      Returns:
      The value at the specified index, or null if not valid
    • get

      public ACell get(ACell key, ACell notFound)
      Description copied from class: ADataStructure
      Get the value associated with a given key.
      Specified by:
      get in class ADataStructure<T extends ACell>
      Parameters:
      key - Key to look up in data structure
      notFound - Value to return if key is not found
      Returns:
      Value from collection, or notFound value if not found
    • containsKey

      public boolean containsKey(ACell key)
      Description copied from class: ADataStructure
      Checks if the data structure contains the specified key
      Specified by:
      containsKey in class ADataStructure<T extends ACell>
      Parameters:
      key - Associative key to look up
      Returns:
      true if the data structure contains the key, false otherwise
    • getElementRef

      public abstract Ref<T> getElementRef(long index)
      Gets the element Ref at the specified index
      Specified by:
      getElementRef in class ACountable<T extends ACell>
      Parameters:
      index - Index of element to get
      Returns:
      Ref to element at specified index
    • set

      public T set(int index, T element)
      Specified by:
      set in interface List<T extends ACell>
    • assoc

      public ASequence<T> assoc(ACell key, ACell value)
      Description copied from class: ADataStructure
      Associates a key with a value in this associative data structure. May return null if the Key or Value is incompatible with the data structure.
      Specified by:
      assoc in class ADataStructure<T extends ACell>
      Parameters:
      key - Associative key
      value - Value to associate with key
      Returns:
      Updates data structure, or null if data types are invalid
    • assoc

      public abstract <R extends ACell> ASequence<R> assoc(long i, R value)
      Updates a value at the given position in the sequence.
      Parameters:
      i - Index of element to update
      value - New element value
      Returns:
      Updated sequence, or null if index is out of range
    • checkRange

      protected void checkRange(long start, long length)
      Checks if an index range is valid for this sequence
      Parameters:
      start -
      length -
    • add

      public final void add(int index, T element)
      Specified by:
      add in interface List<T extends ACell>
    • remove

      public final T remove(int index)
      Specified by:
      remove in interface List<T extends ACell>
    • toCellArray

      public ACell[] toCellArray()
      Converts this sequence to a new Cell array
      Overrides:
      toCellArray in class ACollection<T extends ACell>
      Returns:
      A new cell array containing the elements of this sequence
    • conj

      public abstract <R extends ACell> ASequence<R> conj(R value)
      Adds an element to the sequence in the natural position
      Specified by:
      conj in class ACollection<T extends ACell>
      Type Parameters:
      R - Type of Value added
      Parameters:
      value - Value to add
      Returns:
      Updated sequence
    • slice

      public abstract ASequence<T> slice(long start, long length)
      Produces a slice of this sequence, beginning with the specified start index and of the given length. The start and length must be contained within this sequence. Will return the same sequence if the start is zero and the length matches this sequence.
      Parameters:
      start - Index of the start element
      length - Length of slice to create.
      Returns:
      A sequence representing the requested slice.
    • cons

      public abstract AList<T> cons(T x)
      Prepends an element to this sequence, returning a list.
      Parameters:
      x - Any new element value
      Returns:
      A list starting with the new element.
    • subVector

      public abstract <R extends ACell> AVector<R> subVector(long start, long length)
      Gets a vector containing the specified subset of this sequence.
      Parameters:
      start - Start index of sub vector
      length - Length of sub vector to produce
      Returns:
      Sub-vector of this sequence
    • subList

      public final List<T> subList(int fromIndex, int toIndex)
      Specified by:
      subList in interface List<T extends ACell>
    • listIterator

      protected abstract ListIterator<T> listIterator(long l)
      Gets the ListIterator for a long position
      Parameters:
      l -
      Returns:
      ListIterator instance.
    • reverse

      public abstract ASequence<T> reverse()
      Reverses a sequence, converting Lists to Vectors and vice versa
      Returns:
      Reversed sequence