Class RecordList

java.lang.Object
com.northconcepts.datapipeline.core.RecordList
All Implemented Interfaces:
JsonSerializable, RecordSerializable, Serializable, Cloneable, Iterable<Record>
Direct Known Subclasses:
ConcurrentRecordList

public class RecordList extends Object implements Cloneable, Serializable, Iterable<Record>, RecordSerializable
An in-memory list of records that can be sorted, searched with a Filter, and converted to binary, arrays or a reader.
See Also:
  • Field Details

    • log

      public static final Logger log
  • Constructor Details

    • RecordList

      public RecordList()
    • RecordList

      public RecordList(int initialCapacity)
    • RecordList

      public RecordList(Record... records)
    • RecordList

      public RecordList(DataReader reader)
      Creates a list of all records read from the reader, which is opened if needed and closed afterwards.
  • Method Details

    • ensureCapacity

      public RecordList ensureCapacity(int minCapacity)
      Increases the capacity of this RecordList to allow it to hold the specified number of elements if needed.
    • iterator

      public Iterator<Record> iterator()
      Returns an iterator over the records in this list.
      Specified by:
      iterator in interface Iterable<Record>
    • clone

      public RecordList clone()
      Returns a new RecordList that is a copy of this RecordList.
      Overrides:
      clone in class Object
    • getRecords

      public List<Record> getRecords()
      Returns a list of records.
    • getValuesAsArray

      public ArrayValue getValuesAsArray()
      Returns a multi-dimensional, ArrayValue of ArrayValues of all the values in this list.
    • getValuesAsArray

      public ArrayValue getValuesAsArray(String fieldPath, boolean includeNulls, boolean flattenArrayValues)
      Returns an ArrayValue of all the values matching the fieldPath in this list.
      Parameters:
      fieldPath - the path to the field to extract values from
      includeNulls - whether to include null values in the result
      flattenArrayValues - whether to flatten array values (add elements individually instead of as nested arrays)
      Returns:
      an ArrayValue containing the collected values
    • getValuesAsArray

      public ArrayValue getValuesAsArray(FieldPath fieldPath, boolean includeNulls, boolean flattenArrayValues)
      Returns an ArrayValue of all the values matching the fieldPath in this list.
      Parameters:
      fieldPath - the path to the field to extract values from
      includeNulls - whether to include null values in the result
      flattenArrayValues - whether to flatten array values (add elements individually instead of as nested arrays)
      Returns:
      an ArrayValue containing the collected values
    • forEach

      public void forEach(Consumer<? super Record> consumer)
      Performs the given action for each record in this list.
      Specified by:
      forEach in interface Iterable<Record>
    • stream

      public Stream<Record> stream()
      Returns a sequential Stream of the records in this list.
    • parallelStream

      public Stream<Record> parallelStream()
      Returns a parallel Stream of the records in this list.
    • getRecordCount

      public int getRecordCount()
      Returns the number of records in this list -- an alias for size().
    • size

      public int size()
      Returns the number of records in this list.
    • isEmpty

      public boolean isEmpty()
      Returns true if this list contains no records.
    • isNotEmpty

      public boolean isNotEmpty()
      Returns true if this list contains at least one record.
    • get

      public Record get(int index)
      Returns the record at the specified position in this list.
    • add

      public RecordList add(Record... records)
      Appends all the specified records to the end of this list.
    • addAll

      public RecordList addAll(RecordList recordList)
      Appends all the records in the specified recordList to the end of this list.
    • addAll

      public RecordList addAll(Collection<Record> records)
      Appends all the records in the specified collection to the end of this list.
    • add

      public RecordList add(int index, Record record)
      Inserts a record at the specified position in this list, shifting any record at or after index to the right.
    • set

      public RecordList set(int index, Record record)
      Replaces the record at the specified position in this list with a new record.
    • move

      public RecordList move(int oldIndex, int newIndex)
      Moves the index field at the oldIndex to the newIndex, shifting any existing elements at or after newIndex to the right.
    • addAll

      public RecordList addAll(DataReader reader)
      Writes all the records in the specified reader to the end of this list.
    • sublist

      public RecordList sublist(int fromIndex, int toIndex, boolean cloneRecords)
      Returns a new list with the records from fromIndex (inclusive) to toIndex (exclusive), cloning each record if cloneRecords is true.
    • sublist

      public RecordList sublist(int fromIndex, boolean cloneRecords)
    • clear

      public void clear()
    • sort

      public RecordList sort(RecordComparator comparator, boolean cacheFieldIndexes)
    • sort

      public RecordList sort(RecordComparator comparator)
      Sorts this list in place with the comparator; the sort is stable.
    • findFirst

      public int findFirst(Filter filter, int from)
      Returns the index of the first record at or after from that the filter allows, or -1 if none; a negative from starts at 0.
    • findLast

      public int findLast(Filter filter, int from)
      Returns the index of the last record at or before from that the filter allows, or -1 if none; a from of -1 or past the end starts at the last record.
    • findAll

      public RecordList findAll(Filter filter)
      Returns a new list with the records the filter allows; the records are shared, not copied.
    • count

      public int count(Filter filter)
      Counts the number of records in this list that pass the specified filter.
      Parameters:
      filter - the filter to test records against
      Returns:
      the count of records that pass the filter
    • getSizeInBytes

      public long getSizeInBytes()
      Returns the estimated memory used by this list in bytes, counting the first record's field names once for all records.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toRecord

      public Record toRecord()
      Description copied from interface: RecordSerializable
      Converts this object's state to a record that RecordSerializable.fromRecord(Record) can load.
      Specified by:
      toRecord in interface RecordSerializable
    • fromRecord

      public RecordList fromRecord(Record source)
      Description copied from interface: RecordSerializable
      Loads this instance's state from a record and returns this (for fluid API call chaining). For fluid API call chaining, the overridden method should change the declared return type to its class.
      Specified by:
      fromRecord in interface RecordSerializable
      Parameters:
      source -
      Returns:
      this instance.
    • toBinary

      public byte[] toBinary()
      Serializes the records to bytes in the binary format read by fromBinary(byte[]).
    • toBinary

      public void toBinary(OutputStream outputStream)
      Writes the records to the stream in binary format, then closes the stream.
    • toBinary

      public void toBinary(DataOutput output)
      Writes the records to the output in binary format, then closes the output if it is Closeable.
    • fromBinary

      public static RecordList fromBinary(byte[] bytes)
      Creates a list from bytes produced by toBinary().
    • fromBinary

      public static RecordList fromBinary(InputStream inputStream)
      Reads a list in binary format from the stream, then closes the stream.
    • fromBinary

      public static RecordList fromBinary(DataInput input)
      Reads a list in binary format from the input, then closes the input if it is Closeable.
    • toArrayValue

      public ArrayValue toArrayValue()
      Returns a new array holding these records themselves (not copies), which become children of that array.
    • fromArrayValue

      public RecordList fromArrayValue(ArrayValue arrayValue)
      Replaces this list's contents with the array's elements, which must be records; a null array leaves the list empty.
    • toDataReader

      public MemoryReader toDataReader()