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 Summary
FieldsFields inherited from interface com.northconcepts.datapipeline.core.RecordSerializable
SERIALIZED_CLASS_NAME, TYPE -
Constructor Summary
ConstructorsConstructorDescriptionRecordList(int initialCapacity) RecordList(DataReader reader) Creates a list of all records read from the reader, which is opened if needed and closed afterwards.RecordList(Record... records) -
Method Summary
Modifier and TypeMethodDescriptionInserts a record at the specified position in this list, shifting any record at or afterindexto the right.Appends all the specified records to the end of this list.addAll(DataReader reader) Writes all the records in the specified reader to the end of this list.addAll(RecordList recordList) Appends all the records in the specifiedrecordListto the end of this list.addAll(Collection<Record> records) Appends all the records in the specified collection to the end of this list.voidclear()clone()Returns a new RecordList that is a copy of this RecordList.intCounts the number of records in this list that pass the specified filter.ensureCapacity(int minCapacity) Increases the capacity of thisRecordListto allow it to hold the specified number of elements if needed.Returns a new list with the records the filter allows; the records are shared, not copied.intReturns the index of the first record at or afterfromthat the filter allows, or -1 if none; a negativefromstarts at 0.intReturns the index of the last record at or beforefromthat the filter allows, or -1 if none; afromof -1 or past the end starts at the last record.voidPerforms the given action for each record in this list.fromArrayValue(ArrayValue arrayValue) Replaces this list's contents with the array's elements, which must be records; a null array leaves the list empty.static RecordListfromBinary(byte[] bytes) Creates a list from bytes produced bytoBinary().static RecordListfromBinary(DataInput input) Reads a list in binary format from the input, then closes the input if it isCloseable.static RecordListfromBinary(InputStream inputStream) Reads a list in binary format from the stream, then closes the stream.fromRecord(Record source) Loads this instance's state from a record and returnsthis(for fluid API call chaining).get(int index) Returns the record at the specified position in this list.intReturns the number of records in this list -- an alias forsize().Returns a list of records.longReturns the estimated memory used by this list in bytes, counting the first record's field names once for all records.Returns a multi-dimensional, ArrayValue of ArrayValues of all the values in this list.getValuesAsArray(FieldPath fieldPath, boolean includeNulls, boolean flattenArrayValues) Returns an ArrayValue of all the values matching the fieldPath in this list.getValuesAsArray(String fieldPath, boolean includeNulls, boolean flattenArrayValues) Returns an ArrayValue of all the values matching the fieldPath in this list.booleanisEmpty()Returns true if this list contains no records.booleanReturns true if this list contains at least one record.iterator()Returns an iterator over the records in this list.move(int oldIndex, int newIndex) Moves the index field at theoldIndexto thenewIndex, shifting any existing elements at or afternewIndexto the right.Returns a parallel Stream of the records in this list.Replaces the record at the specified position in this list with a new record.intsize()Returns the number of records in this list.sort(RecordComparator comparator) Sorts this list in place with the comparator; the sort is stable.sort(RecordComparator comparator, boolean cacheFieldIndexes) stream()Returns a sequential Stream of the records in this list.sublist(int fromIndex, boolean cloneRecords) sublist(int fromIndex, int toIndex, boolean cloneRecords) Returns a new list with the records fromfromIndex(inclusive) totoIndex(exclusive), cloning each record ifcloneRecordsis true.Returns a new array holding these records themselves (not copies), which become children of that array.byte[]toBinary()Serializes the records to bytes in the binary format read byfromBinary(byte[]).voidtoBinary(DataOutput output) Writes the records to the output in binary format, then closes the output if it isCloseable.voidtoBinary(OutputStream outputStream) Writes the records to the stream in binary format, then closes the stream.toRecord()Converts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.toString()Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
spliterator
-
Field Details
-
log
public static final Logger log
-
-
Constructor Details
-
RecordList
public RecordList() -
RecordList
public RecordList(int initialCapacity) -
RecordList
-
RecordList
Creates a list of all records read from the reader, which is opened if needed and closed afterwards.
-
-
Method Details
-
ensureCapacity
Increases the capacity of thisRecordListto allow it to hold the specified number of elements if needed. -
iterator
Returns an iterator over the records in this list. -
clone
Returns a new RecordList that is a copy of this RecordList. -
getRecords
Returns a list of records. -
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 fromincludeNulls- whether to include null values in the resultflattenArrayValues- 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 fromincludeNulls- whether to include null values in the resultflattenArrayValues- whether to flatten array values (add elements individually instead of as nested arrays)- Returns:
- an ArrayValue containing the collected values
-
forEach
Performs the given action for each record in this list. -
stream
Returns a sequential Stream of the records in this list. -
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 forsize(). -
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
Returns the record at the specified position in this list. -
add
Appends all the specified records to the end of this list. -
addAll
Appends all the records in the specifiedrecordListto the end of this list. -
addAll
Appends all the records in the specified collection to the end of this list. -
add
Inserts a record at the specified position in this list, shifting any record at or afterindexto the right. -
set
Replaces the record at the specified position in this list with a new record. -
move
Moves the index field at theoldIndexto thenewIndex, shifting any existing elements at or afternewIndexto the right. -
addAll
Writes all the records in the specified reader to the end of this list. -
sublist
Returns a new list with the records fromfromIndex(inclusive) totoIndex(exclusive), cloning each record ifcloneRecordsis true. -
sublist
-
clear
public void clear() -
sort
-
sort
Sorts this list in place with the comparator; the sort is stable. -
findFirst
Returns the index of the first record at or afterfromthat the filter allows, or -1 if none; a negativefromstarts at 0. -
findLast
Returns the index of the last record at or beforefromthat the filter allows, or -1 if none; afromof -1 or past the end starts at the last record. -
findAll
Returns a new list with the records the filter allows; the records are shared, not copied. -
count
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
-
toRecord
Description copied from interface:RecordSerializableConverts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.- Specified by:
toRecordin interfaceRecordSerializable
-
fromRecord
Description copied from interface:RecordSerializableLoads this instance's state from a record and returnsthis(for fluid API call chaining). For fluid API call chaining, the overridden method should change the declared return type to its class.- Specified by:
fromRecordin interfaceRecordSerializable- Parameters:
source-- Returns:
- this instance.
-
toBinary
public byte[] toBinary()Serializes the records to bytes in the binary format read byfromBinary(byte[]). -
toBinary
Writes the records to the stream in binary format, then closes the stream. -
toBinary
Writes the records to the output in binary format, then closes the output if it isCloseable. -
fromBinary
Creates a list from bytes produced bytoBinary(). -
fromBinary
Reads a list in binary format from the stream, then closes the stream. -
fromBinary
Reads a list in binary format from the input, then closes the input if it isCloseable. -
toArrayValue
Returns a new array holding these records themselves (not copies), which become children of that array. -
fromArrayValue
Replaces this list's contents with the array's elements, which must be records; a null array leaves the list empty. -
toDataReader
-