Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.landawn.abacus.core.RowDataSet Maven / Gradle / Ivy
/*
* Copyright (c) 2015, Haiyang Li. All rights reserved.
*/
package com.landawn.abacus.core;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.Callable;
import com.landawn.abacus.DataSet;
import com.landawn.abacus.DirtyMarker;
import com.landawn.abacus.PaginatedDataSet;
import com.landawn.abacus.exception.UncheckedIOException;
import com.landawn.abacus.parser.JSONParser;
import com.landawn.abacus.parser.JSONSerializationConfig;
import com.landawn.abacus.parser.JSONSerializationConfig.JSC;
import com.landawn.abacus.parser.KryoParser;
import com.landawn.abacus.parser.Parser;
import com.landawn.abacus.parser.ParserFactory;
import com.landawn.abacus.parser.XMLConstants;
import com.landawn.abacus.parser.XMLParser;
import com.landawn.abacus.parser.XMLSerializationConfig;
import com.landawn.abacus.parser.XMLSerializationConfig.XSC;
import com.landawn.abacus.type.Type;
import com.landawn.abacus.util.Array;
import com.landawn.abacus.util.ArrayHashMap;
import com.landawn.abacus.util.ArrayHashSet;
import com.landawn.abacus.util.BiIterator;
import com.landawn.abacus.util.BufferedJSONWriter;
import com.landawn.abacus.util.BufferedWriter;
import com.landawn.abacus.util.BufferedXMLWriter;
import com.landawn.abacus.util.ClassUtil;
import com.landawn.abacus.util.Comparators;
import com.landawn.abacus.util.DateTimeFormat;
import com.landawn.abacus.util.Fn;
import com.landawn.abacus.util.IOUtil;
import com.landawn.abacus.util.ImmutableList;
import com.landawn.abacus.util.Indexed;
import com.landawn.abacus.util.Iterables;
import com.landawn.abacus.util.ListMultimap;
import com.landawn.abacus.util.Multimap;
import com.landawn.abacus.util.Multiset;
import com.landawn.abacus.util.N;
import com.landawn.abacus.util.NoCachingNoUpdating.DisposableObjArray;
import com.landawn.abacus.util.Objectory;
import com.landawn.abacus.util.Pair;
import com.landawn.abacus.util.Properties;
import com.landawn.abacus.util.Sheet;
import com.landawn.abacus.util.StringUtil;
import com.landawn.abacus.util.TriIterator;
import com.landawn.abacus.util.Triple;
import com.landawn.abacus.util.Try;
import com.landawn.abacus.util.Try.BiFunction;
import com.landawn.abacus.util.Try.Predicate;
import com.landawn.abacus.util.Try.TriConsumer;
import com.landawn.abacus.util.Try.TriFunction;
import com.landawn.abacus.util.Try.TriPredicate;
import com.landawn.abacus.util.Tuple.Tuple2;
import com.landawn.abacus.util.Tuple.Tuple3;
import com.landawn.abacus.util.WD;
import com.landawn.abacus.util.Wrapper;
import com.landawn.abacus.util.u.Optional;
import com.landawn.abacus.util.function.BiConsumer;
import com.landawn.abacus.util.function.Consumer;
import com.landawn.abacus.util.function.Function;
import com.landawn.abacus.util.function.IndexedConsumer;
import com.landawn.abacus.util.function.IntFunction;
import com.landawn.abacus.util.function.Supplier;
import com.landawn.abacus.util.stream.Collector;
import com.landawn.abacus.util.stream.Collectors;
import com.landawn.abacus.util.stream.IntStream;
import com.landawn.abacus.util.stream.ObjIteratorEx;
import com.landawn.abacus.util.stream.Stream;
/**
* It's a row DataSet from logic aspect. But each column is stored in a list.
*
* @since 0.8
*
* @author Haiyang Li
*/
public class RowDataSet implements DataSet, Cloneable {
static final String NULL_STRING = "null".intern();
static final char[] NULL_CHAR_ARRAY = NULL_STRING.toCharArray();
static final String TRUE = Boolean.TRUE.toString().intern();
static final char[] TRUE_CHAR_ARRAY = TRUE.toCharArray();
static final String FALSE = Boolean.FALSE.toString().intern();
static final char[] FALSE_CHAR_ARRAY = FALSE.toCharArray();
static final Set> SUPPORTED_COUNT_COLUMN_TYPES = N.asSet((Class>) int.class, Integer.class, long.class, Long.class, float.class, Float.class,
double.class, Double.class);
/**
* Field CACHED_PROP_NAMES. (value is ""cachedPropNames"")
*/
public static final String CACHED_PROP_NAMES = "cachedPropNames";
private static final String ROW = "row";
private static final JSONParser jsonParser = ParserFactory.createJSONParser();
private static final XMLParser xmlParser = ParserFactory.isXMLAvailable() ? ParserFactory.createXMLParser() : null;
private static final KryoParser kryoParser = ParserFactory.isKryoAvailable() ? ParserFactory.createKryoParser() : null;
private static final JSONSerializationConfig jsc = JSC.create().setDateTimeFormat(DateTimeFormat.ISO_8601_TIMESTAMP);
private static final XMLSerializationConfig xsc = XSC.create().setDateTimeFormat(DateTimeFormat.ISO_8601_TIMESTAMP);
private static final Type strType = N.typeOf(String.class);
@SuppressWarnings("rawtypes")
private static final Comparator MULTI_COLUMN_COMPARATOR = new Comparator() {
private final Comparator naturalOrder = Comparators.naturalOrder();
@Override
public int compare(final Object[] o1, final Object[] o2) {
int rt = 0;
for (int i = 0, len = o1.length; i < len; i++) {
rt = naturalOrder.compare((Comparable) o1[i], (Comparable) o2[i]);
if (rt != 0) {
return rt;
}
}
return rt;
}
};
// For Kryo
private List _columnNameList;
private List> _columnList;
private Map _columnIndexMap;
private int[] _columnIndexes;
private int _currentRowNum = 0;
private boolean _isFrozen = false;
private Properties _properties;
private transient int modCount = 0;
// For Kryo
protected RowDataSet() {
}
public RowDataSet(final List columnNameList, final List> columnList) {
this(columnNameList, columnList, null);
}
public RowDataSet(final List columnNameList, final List> columnList, final Properties properties) {
N.checkArgNotNull(columnNameList);
N.checkArgNotNull(columnList);
N.checkArgument(N.hasDuplicates(columnNameList) == false, "Dupliated column names: {}", columnList);
N.checkArgument(columnNameList.size() == columnList.size(), "the size of column name list: {} is different from the size of column list: {}",
columnNameList.size(), columnList.size());
final int size = columnList.size() == 0 ? 0 : columnList.get(0).size();
for (List column : columnList) {
N.checkArgument(column.size() == size, "All columns in the specified 'columnList' must have same size.");
}
this._columnNameList = columnNameList;
this._columnList = columnList;
this._properties = properties;
}
// @Override
// public String entityName() {
// return _entityName;
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public Class entityClass() {
// return (Class) _entityClass;
// }
@Override
public ImmutableList columnNameList() {
// return _columnNameList;
return ImmutableList.of(_columnNameList);
}
@Override
public String getColumnName(final int columnIndex) {
return _columnNameList.get(columnIndex);
}
@Override
public int getColumnIndex(final String columnName) {
if (_columnIndexMap == null) {
_columnIndexMap = new HashMap<>();
int i = 0;
for (String e : _columnNameList) {
_columnIndexMap.put(e, i++);
}
}
Integer columnIndex = _columnIndexMap.get(columnName);
if (columnIndex == null /* && NameUtil.isCanonicalName(_entityName, columnName)*/) {
columnIndex = _columnIndexMap.get(NameUtil.getSimpleName(columnName));
}
return (columnIndex == null) ? -1 : columnIndex;
}
@Override
public int[] getColumnIndexes(final Collection columnNames) {
int[] columnIndexes = new int[columnNames.size()];
int i = 0;
for (String columnName : columnNames) {
columnIndexes[i++] = getColumnIndex(columnName);
}
return columnIndexes;
}
@Override
public boolean containsColumn(final String columnName) {
return getColumnIndex(columnName) >= 0;
}
@Override
public boolean containsAllColumns(final Collection columnNames) {
for (String columnName : columnNames) {
if (containsColumn(columnName) == false) {
return false;
}
}
return true;
}
@Override
public void renameColumn(final String columnName, final String newColumnName) {
checkFrozen();
int idx = checkColumnName(columnName);
if (columnName.equals(newColumnName)) {
// ignore.
} else {
if (_columnNameList.contains(newColumnName)) {
throw new IllegalArgumentException("The new property name is already included: " + _columnNameList + ". ");
}
if (_columnIndexMap != null) {
_columnIndexMap.put(newColumnName, _columnIndexMap.remove(_columnNameList.get(idx)));
}
_columnNameList.set(idx, newColumnName);
}
modCount++;
}
@Override
public void renameColumns(final Map oldNewNames) {
checkFrozen();
if (N.hasDuplicates(oldNewNames.values())) {
throw new IllegalArgumentException("Duplicated new column names: " + oldNewNames.values());
}
for (Map.Entry entry : oldNewNames.entrySet()) {
checkColumnName(entry.getKey());
if (_columnNameList.contains(entry.getValue()) && !entry.getKey().equals(entry.getValue())) {
throw new IllegalArgumentException("The new property name is already included: " + _columnNameList + ". ");
}
}
for (Map.Entry entry : oldNewNames.entrySet()) {
renameColumn(entry.getKey(), entry.getValue());
}
}
@Override
public void renameColumn(final String columnName, final Try.Function func) throws E {
renameColumn(columnName, func.apply(columnName));
}
@Override
public void renameColumns(final Collection columnNames, final Try.Function func) throws E {
checkColumnName(columnNames);
final Map map = N.newHashMap(N.initHashCapacity(columnNames.size()));
for (String columnName : columnNames) {
map.put(columnName, func.apply(columnName));
}
renameColumns(map);
}
@Override
public void renameColumns(final Try.Function func) throws E {
renameColumns(_columnNameList, func);
}
@Override
public void moveColumn(final String columnName, int newPosition) {
checkFrozen();
int idx = checkColumnName(columnName);
if (newPosition < 0 || newPosition >= _columnNameList.size()) {
throw new IllegalArgumentException("The new column index must be >= 0 and < " + _columnNameList.size());
}
if (idx == newPosition) {
// ignore.
} else {
_columnNameList.add(newPosition, _columnNameList.remove(idx));
_columnList.add(newPosition, _columnList.remove(idx));
_columnIndexMap = null;
_columnIndexes = null;
}
modCount++;
}
@Override
public void moveColumns(Map columnNameNewPositionMap) {
checkFrozen();
final List> entries = new ArrayList<>(columnNameNewPositionMap.size());
for (Map.Entry entry : columnNameNewPositionMap.entrySet()) {
checkColumnName(entry.getKey());
if (entry.getValue().intValue() < 0 || entry.getValue().intValue() >= _columnNameList.size()) {
throw new IllegalArgumentException("The new column index must be >= 0 and < " + _columnNameList.size());
}
entries.add(entry);
}
N.sort(entries, new Comparator>() {
@Override
public int compare(Map.Entry o1, Map.Entry o2) {
return Integer.compare(o1.getValue(), o2.getValue());
}
});
for (Map.Entry entry : entries) {
int currentColumnIndex = checkColumnName(entry.getKey());
if (currentColumnIndex == entry.getValue().intValue()) {
// ignore.
} else {
_columnNameList.add(entry.getValue().intValue(), _columnNameList.remove(currentColumnIndex));
_columnList.add(entry.getValue().intValue(), _columnList.remove(currentColumnIndex));
_columnIndexMap = null;
}
}
modCount++;
}
@Override
public void swapColumns(String columnNameA, String columnNameB) {
checkFrozen();
int columnIndexA = checkColumnName(columnNameA);
int columnIndexB = checkColumnName(columnNameB);
if (columnNameA.equals(columnNameB)) {
return;
}
final String tmpColumnNameA = _columnNameList.get(columnIndexA);
_columnNameList.set(columnIndexA, _columnNameList.get(columnIndexB));
_columnNameList.set(columnIndexB, tmpColumnNameA);
final List tmpColumnA = _columnList.get(columnIndexA);
_columnList.set(columnIndexA, _columnList.get(columnIndexB));
_columnList.set(columnIndexB, tmpColumnA);
if (N.notNullOrEmpty(_columnIndexMap)) {
_columnIndexMap.put(columnNameA, columnIndexB);
_columnIndexMap.put(columnNameB, columnIndexA);
}
modCount++;
}
@Override
public void moveRow(int rowIndex, int newRowIndex) {
checkFrozen();
this.checkRowNum(rowIndex);
this.checkRowNum(newRowIndex);
if (rowIndex == newRowIndex) {
return;
}
for (List column : _columnList) {
column.add(newRowIndex, column.remove(rowIndex));
}
modCount++;
}
@Override
public void swapRows(int rowIndexA, int rowIndexB) {
checkFrozen();
this.checkRowNum(rowIndexA);
this.checkRowNum(rowIndexB);
if (rowIndexA == rowIndexB) {
return;
}
Object tmp = null;
for (List column : _columnList) {
tmp = column.get(rowIndexA);
column.set(rowIndexA, column.get(rowIndexB));
column.set(rowIndexB, tmp);
}
modCount++;
}
@Override
public T get(final int rowIndex, final int columnIndex) {
return (T) _columnList.get(columnIndex).get(rowIndex);
}
@Override
public T get(final Class targetType, final int rowIndex, final int columnIndex) {
T rt = (T) _columnList.get(columnIndex).get(rowIndex);
return (rt == null) ? N.defaultValueOf(targetType) : rt;
}
@Override
public void set(final int rowIndex, final int columnIndex, final Object element) {
checkFrozen();
_columnList.get(columnIndex).set(rowIndex, element);
modCount++;
}
@Override
public boolean isNull(final int rowIndex, final int columnIndex) {
return get(rowIndex, columnIndex) == null;
}
@SuppressWarnings("unchecked")
@Override
public T get(final int columnIndex) {
return (T) _columnList.get(columnIndex).get(_currentRowNum);
}
@Override
public T get(final Class targetType, final int columnIndex) {
T rt = get(columnIndex);
return (rt == null) ? N.defaultValueOf(targetType) : rt;
}
@SuppressWarnings("unchecked")
@Override
public T get(final String columnName) {
return (T) get(checkColumnName(columnName));
}
@Override
public T get(final Class targetType, final String columnName) {
return get(targetType, checkColumnName(columnName));
}
@Override
public T getOrDefault(int columnIndex, T defaultValue) {
return columnIndex < 0 ? defaultValue : (T) get(columnIndex);
}
@Override
public T getOrDefault(final String columnName, T defaultValue) {
return getOrDefault(getColumnIndex(columnName), defaultValue);
}
@Override
public boolean getBoolean(final int columnIndex) {
Boolean rt = get(boolean.class, columnIndex);
return (rt == null) ? false : rt;
}
@Override
public boolean getBoolean(final String columnName) {
return getBoolean(checkColumnName(columnName));
}
@Override
public char getChar(final int columnIndex) {
Character rt = get(columnIndex);
return (rt == null) ? 0 : rt;
}
@Override
public char getChar(final String columnName) {
return getChar(checkColumnName(columnName));
}
@Override
public byte getByte(final int columnIndex) {
Number rt = get(columnIndex);
return (rt == null) ? 0 : rt.byteValue();
}
@Override
public byte getByte(final String columnName) {
return getByte(checkColumnName(columnName));
}
@Override
public short getShort(final int columnIndex) {
Number rt = get(columnIndex);
return (rt == null) ? 0 : rt.shortValue();
}
@Override
public short getShort(final String columnName) {
return getShort(checkColumnName(columnName));
}
@Override
public int getInt(final int columnIndex) {
Number rt = get(columnIndex);
return (rt == null) ? 0 : rt.intValue();
}
@Override
public int getInt(final String columnName) {
return getInt(checkColumnName(columnName));
}
@Override
public long getLong(final int columnIndex) {
Number rt = get(columnIndex);
return (rt == null) ? 0L : rt.longValue();
}
@Override
public long getLong(final String columnName) {
return getLong(checkColumnName(columnName));
}
@Override
public float getFloat(final int columnIndex) {
Number rt = get(columnIndex);
return (rt == null) ? 0f : rt.floatValue();
}
@Override
public float getFloat(final String columnName) {
return getFloat(checkColumnName(columnName));
}
@Override
public double getDouble(final int columnIndex) {
Number rt = get(columnIndex);
return (rt == null) ? 0d : rt.doubleValue();
}
@Override
public double getDouble(final String columnName) {
return getDouble(checkColumnName(columnName));
}
@Override
public boolean isNull(final int columnIndex) {
return get(columnIndex) == null;
}
@Override
public boolean isNull(final String columnName) {
return get(columnName) == null;
}
@Override
public void set(final int columnIndex, final Object value) {
checkFrozen();
_columnList.get(columnIndex).set(_currentRowNum, value);
modCount++;
}
@Override
public void set(final String columnName, final Object value) {
set(checkColumnName(columnName), value);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public ImmutableList getColumn(final int columnIndex) {
// return (List) _columnList.get(columnIndex);
return ImmutableList.of((List) _columnList.get(columnIndex));
}
@SuppressWarnings("unchecked")
@Override
public ImmutableList getColumn(final String columnName) {
return getColumn(checkColumnName(columnName));
}
@SuppressWarnings("rawtypes")
@Override
public List copyOfColumn(final String columnName) {
return new ArrayList<>((List) _columnList.get(checkColumnName(columnName)));
}
@Override
public void addColumn(final String columnName, final List> column) {
addColumn(_columnList.size(), columnName, column);
}
@Override
public void addColumn(final int columnIndex, final String columnName, final List> column) {
checkFrozen();
if (columnIndex < 0 || columnIndex > _columnNameList.size()) {
throw new IllegalArgumentException("Invalid column index: " + columnIndex + ". It must be >= 0 and <= " + _columnNameList.size());
}
if (containsColumn(columnName)) {
throw new IllegalArgumentException("Column(" + columnName + ") is already included in this DataSet.");
}
if (N.notNullOrEmpty(column) && column.size() != size()) {
throw new IllegalArgumentException("The specified column size[" + column.size() + "] must be same as the this DataSet size[" + size() + "]. ");
}
_columnNameList.add(columnIndex, columnName);
if (N.isNullOrEmpty(column)) {
_columnList.add(columnIndex, N.repeat(null, size()));
} else {
_columnList.add(columnIndex, new ArrayList<>(column));
}
updateColumnIndex(columnIndex, columnName);
modCount++;
}
@Override
public void addColumn(String newColumnName, String fromColumnName, Try.Function func) throws E {
addColumn(_columnList.size(), newColumnName, fromColumnName, func);
}
@Override
public void addColumn(int columnIndex, final String newColumnName, String fromColumnName, Try.Function func) throws E {
checkFrozen();
if (columnIndex < 0 || columnIndex > _columnNameList.size()) {
throw new IllegalArgumentException("Invalid column index: " + columnIndex + ". It must be >= 0 and <= " + _columnNameList.size());
}
if (containsColumn(newColumnName)) {
throw new IllegalArgumentException("Column(" + newColumnName + ") is already included in this DataSet.");
}
final List newColumn = new ArrayList<>(size());
final Try.Function mapper2 = (Try.Function) func;
final List column = _columnList.get(checkColumnName(fromColumnName));
for (Object val : column) {
newColumn.add(mapper2.apply(val));
}
_columnNameList.add(columnIndex, newColumnName);
_columnList.add(columnIndex, newColumn);
updateColumnIndex(columnIndex, newColumnName);
modCount++;
}
@Override
public void addColumn(String newColumnName, Collection fromColumnNames, Try.Function super DisposableObjArray, ?, E> func)
throws E {
addColumn(_columnList.size(), newColumnName, fromColumnNames, func);
}
@Override
public void addColumn(int columnIndex, final String newColumnName, Collection fromColumnNames,
Try.Function super DisposableObjArray, ?, E> func) throws E {
checkFrozen();
if (containsColumn(newColumnName)) {
throw new IllegalArgumentException("Column(" + newColumnName + ") is already included in this DataSet.");
}
final int size = size();
final int[] fromColumnIndexes = checkColumnName(fromColumnNames);
final Try.Function mapper2 = (Try.Function) func;
final List newColumn = new ArrayList<>(size);
final Object[] row = new Object[fromColumnIndexes.length];
final DisposableObjArray disposableArray = DisposableObjArray.wrap(row);
for (int rowIndex = 0; rowIndex < size; rowIndex++) {
for (int i = 0, len = fromColumnIndexes.length; i < len; i++) {
row[i] = _columnList.get(fromColumnIndexes[i]).get(rowIndex);
}
newColumn.add(mapper2.apply(disposableArray));
}
_columnNameList.add(columnIndex, newColumnName);
_columnList.add(columnIndex, newColumn);
updateColumnIndex(columnIndex, newColumnName);
modCount++;
}
private void updateColumnIndex(int columnIndex, final String newColumnName) {
if (_columnIndexMap != null && columnIndex == _columnIndexMap.size()) {
_columnIndexMap.put(newColumnName, columnIndex);
} else {
_columnIndexMap = null;
}
if (_columnIndexes != null && columnIndex == _columnIndexes.length) {
_columnIndexes = N.copyOf(_columnIndexes, _columnIndexes.length + 1);
_columnIndexes[columnIndex] = columnIndex;
} else {
_columnIndexes = null;
}
}
@Override
public void addColumn(String newColumnName, Tuple2 fromColumnNames, Try.BiFunction, ?, ?, E> func) throws E {
addColumn(_columnList.size(), newColumnName, fromColumnNames, func);
}
@Override
public void addColumn(int columnIndex, final String newColumnName, Tuple2 fromColumnNames,
Try.BiFunction, ?, ?, E> func) throws E {
checkFrozen();
if (containsColumn(newColumnName)) {
throw new IllegalArgumentException("Column(" + newColumnName + ") is already included in this DataSet.");
}
final int size = size();
final List column1 = _columnList.get(checkColumnName(fromColumnNames._1));
final List column2 = _columnList.get(checkColumnName(fromColumnNames._2));
@SuppressWarnings("rawtypes")
final Try.BiFunction mapper2 = (Try.BiFunction) func;
final List newColumn = new ArrayList<>(size());
for (int rowIndex = 0; rowIndex < size; rowIndex++) {
newColumn.add(mapper2.apply(column1.get(rowIndex), column2.get(rowIndex)));
}
_columnNameList.add(columnIndex, newColumnName);
_columnList.add(columnIndex, newColumn);
updateColumnIndex(columnIndex, newColumnName);
modCount++;
}
@Override
public void addColumn(String newColumnName, Tuple3 fromColumnNames, TriFunction, ?, ?, ?, E> func)
throws E {
addColumn(_columnList.size(), newColumnName, fromColumnNames, func);
}
@Override
public void addColumn(int columnIndex, final String newColumnName, Tuple3 fromColumnNames,
TriFunction, ?, ?, ?, E> func) throws E {
checkFrozen();
if (containsColumn(newColumnName)) {
throw new IllegalArgumentException("Column(" + newColumnName + ") is already included in this DataSet.");
}
final int size = size();
final List column1 = _columnList.get(checkColumnName(fromColumnNames._1));
final List column2 = _columnList.get(checkColumnName(fromColumnNames._2));
final List column3 = _columnList.get(checkColumnName(fromColumnNames._3));
@SuppressWarnings("rawtypes")
final Try.TriFunction mapper2 = (Try.TriFunction) func;
final List newColumn = new ArrayList<>(size());
for (int rowIndex = 0; rowIndex < size; rowIndex++) {
newColumn.add(mapper2.apply(column1.get(rowIndex), column2.get(rowIndex), column3.get(rowIndex)));
}
_columnNameList.add(columnIndex, newColumnName);
_columnList.add(columnIndex, newColumn);
updateColumnIndex(columnIndex, newColumnName);
modCount++;
}
@SuppressWarnings("rawtypes")
@Override
public List removeColumn(final String columnName) {
checkFrozen();
final int columnIndex = checkColumnName(columnName);
_columnIndexMap = null;
_columnIndexes = null;
_columnNameList.remove(columnIndex);
final List removedColumn = _columnList.remove(columnIndex);
modCount++;
return (List) removedColumn;
}
@Override
public void removeColumns(final Collection columnNames) {
checkFrozen();
final int[] columnIndexes = checkColumnName(columnNames);
N.sort(columnIndexes);
for (int i = 0, len = columnIndexes.length; i < len; i++) {
_columnNameList.remove(columnIndexes[i] - i);
_columnList.remove(columnIndexes[i] - i);
}
_columnIndexMap = null;
_columnIndexes = null;
modCount++;
}
@Override
public void removeColumns(Predicate filter) throws E {
removeColumns(N.filter(_columnNameList, filter));
}
@Deprecated
@Override
public void removeColumnsIf(Predicate filter) throws E {
removeColumns(filter);
}
@Override
public void convertColumn(final String columnName, final Class> targetType) {
checkFrozen();
convertColumnType(checkColumnName(columnName), targetType);
}
@Override
public void convertColumns(final Map> columnTargetTypes) {
checkFrozen();
checkColumnName(columnTargetTypes.keySet());
for (Map.Entry> entry : columnTargetTypes.entrySet()) {
convertColumnType(checkColumnName(entry.getKey()), entry.getValue());
}
}
@Override
public void updateColumn(final String columnName, final Try.Function func) throws E {
checkFrozen();
final Try.Function func2 = (Try.Function) func;
final List column = _columnList.get(checkColumnName(columnName));
for (int i = 0, len = size(); i < len; i++) {
column.set(i, func2.apply(column.get(i)));
}
modCount++;
}
@Override
public void updateColumns(final Collection columnNames, final Try.Function, ?, E> func) throws E {
checkColumnName(columnNames);
final Try.Function func2 = (Try.Function) func;
for (String columnName : columnNames) {
final List column = _columnList.get(checkColumnName(columnName));
for (int i = 0, len = size(); i < len; i++) {
column.set(i, func2.apply(column.get(i)));
}
}
modCount++;
}
private void convertColumnType(final int columnIndex, final Class> targetType) {
final List column = _columnList.get(columnIndex);
Object newValue = null;
for (int i = 0, len = size(); i < len; i++) {
newValue = N.convert(column.get(i), targetType);
column.set(i, newValue);
}
modCount++;
}
@Override
public void combineColumns(final Collection columnNames, final String newColumnName, final Class> newColumnClass) {
checkFrozen();
final List newColumn = toList(newColumnClass, columnNames, 0, size());
removeColumns(columnNames);
addColumn(newColumnName, newColumn);
}
@Override
public void combineColumns(Collection columnNames, final String newColumnName,
Try.Function super DisposableObjArray, ?, E> combineFunc) throws E {
addColumn(newColumnName, columnNames, combineFunc);
removeColumns(columnNames);
}
@Override
public void combineColumns(Try.Predicate columnNameFilter, final String newColumnName, Class> newColumnClass) throws E {
combineColumns(N.filter(_columnNameList, columnNameFilter), newColumnName, newColumnClass);
}
@Override
public void combineColumns(Try.Predicate columnNameFilter, final String newColumnName,
Try.Function super DisposableObjArray, ?, E2> combineFunc) throws E, E2 {
combineColumns(N.filter(_columnNameList, columnNameFilter), newColumnName, combineFunc);
}
@Override
public void combineColumns(Tuple2 columnNames, final String newColumnName, Try.BiFunction, ?, ?, E> combineFunc)
throws E {
addColumn(newColumnName, columnNames, combineFunc);
removeColumns(Arrays.asList(columnNames._1, columnNames._2));
}
@Override
public void combineColumns(Tuple3 columnNames, final String newColumnName,
Try.TriFunction, ?, ?, ?, E> combineFunc) throws E {
addColumn(newColumnName, columnNames, combineFunc);
removeColumns(Arrays.asList(columnNames._1, columnNames._2, columnNames._3));
}
@Override
public void divideColumn(final String columnName, Collection newColumnNames,
Try.Function, E> divideFunc) throws E {
checkFrozen();
final int columnIndex = this.checkColumnName(columnName);
if (N.isNullOrEmpty(newColumnNames)) {
throw new IllegalArgumentException("New column names can't be null or empty.");
}
if (N.disjoint(_columnNameList, newColumnNames) == false) {
throw new IllegalArgumentException("Column names: " + N.intersection(_columnNameList, newColumnNames) + " already are included in this data set.");
}
@SuppressWarnings("rawtypes")
final Try.Function, E> divideFunc2 = (Try.Function) divideFunc;
final int newColumnsLen = newColumnNames.size();
final List> newColumns = new ArrayList<>(newColumnsLen);
for (int i = 0; i < newColumnsLen; i++) {
newColumns.add(new ArrayList<>(size()));
}
final List column = _columnList.get(columnIndex);
for (Object val : column) {
final List newVals = divideFunc2.apply(val);
for (int i = 0; i < newColumnsLen; i++) {
newColumns.get(i).add(newVals.get(i));
}
}
_columnNameList.remove(columnIndex);
_columnNameList.addAll(columnIndex, newColumnNames);
_columnList.remove(columnIndex);
_columnList.addAll(columnIndex, newColumns);
_columnIndexMap = null;
_columnIndexes = null;
modCount++;
}
@Override
public void divideColumn(final String columnName, Collection newColumnNames, Try.BiConsumer output)
throws E {
checkFrozen();
final int columnIndex = this.checkColumnName(columnName);
if (N.isNullOrEmpty(newColumnNames)) {
throw new IllegalArgumentException("New column names can't be null or empty.");
}
if (N.disjoint(_columnNameList, newColumnNames) == false) {
throw new IllegalArgumentException("Column names: " + N.intersection(_columnNameList, newColumnNames) + " already are included in this data set.");
}
@SuppressWarnings("rawtypes")
final Try.BiConsumer output2 = (Try.BiConsumer) output;
final int newColumnsLen = newColumnNames.size();
final List> newColumns = new ArrayList<>(newColumnsLen);
for (int i = 0; i < newColumnsLen; i++) {
newColumns.add(new ArrayList<>(size()));
}
final List column = _columnList.get(columnIndex);
final Object[] tmp = new Object[newColumnsLen];
for (Object val : column) {
output2.accept(val, tmp);
for (int i = 0; i < newColumnsLen; i++) {
newColumns.get(i).add(tmp[i]);
}
}
_columnNameList.remove(columnIndex);
_columnNameList.addAll(columnIndex, newColumnNames);
_columnList.remove(columnIndex);
_columnList.addAll(columnIndex, newColumns);
_columnIndexMap = null;
_columnIndexes = null;
modCount++;
}
@Override
public void divideColumn(final String columnName, final Tuple2 newColumnNames,
final Try.BiConsumer, E> output) throws E {
checkFrozen();
final int columnIndex = this.checkColumnName(columnName);
this.checkNewColumnName(newColumnNames._1);
this.checkNewColumnName(newColumnNames._2);
@SuppressWarnings("rawtypes")
final Try.BiConsumer, E> output2 = (Try.BiConsumer) output;
final List newColumn1 = new ArrayList<>(size());
final List newColumn2 = new ArrayList<>(size());
final List column = _columnList.get(columnIndex);
final Pair tmp = new Pair<>();
for (Object val : column) {
output2.accept(val, tmp);
newColumn1.add(tmp.left);
newColumn2.add(tmp.right);
}
_columnNameList.remove(columnIndex);
_columnNameList.addAll(columnIndex, Arrays.asList(newColumnNames._1, newColumnNames._2));
_columnList.remove(columnIndex);
_columnList.addAll(columnIndex, Arrays.asList(newColumn1, newColumn2));
_columnIndexMap = null;
_columnIndexes = null;
modCount++;
}
@Override
public void divideColumn(final String columnName, final Tuple3 newColumnNames,
final Try.BiConsumer, E> output) throws E {
checkFrozen();
final int columnIndex = this.checkColumnName(columnName);
this.checkNewColumnName(newColumnNames._1);
this.checkNewColumnName(newColumnNames._2);
this.checkNewColumnName(newColumnNames._3);
@SuppressWarnings("rawtypes")
final Try.BiConsumer, E> output2 = (Try.BiConsumer) output;
final List newColumn1 = new ArrayList<>(size());
final List newColumn2 = new ArrayList<>(size());
final List newColumn3 = new ArrayList<>(size());
final List column = _columnList.get(columnIndex);
final Triple tmp = new Triple<>();
for (Object val : column) {
output2.accept(val, tmp);
newColumn1.add(tmp.left);
newColumn2.add(tmp.middle);
newColumn3.add(tmp.right);
}
_columnNameList.remove(columnIndex);
_columnNameList.addAll(columnIndex, Arrays.asList(newColumnNames._1, newColumnNames._2, newColumnNames._3));
_columnList.remove(columnIndex);
_columnList.addAll(columnIndex, Arrays.asList(newColumn1, newColumn2, newColumn3));
_columnIndexMap = null;
_columnIndexes = null;
modCount++;
}
@Override
public void addRow(final Object row) {
addRow(size(), row);
}
@Override
public void addRow(final int rowIndex, final Object row) {
checkFrozen();
if ((rowIndex < 0) || (rowIndex > size())) {
throw new IllegalArgumentException("Invalid row index: " + rowIndex + ". It must be >= 0 and <= " + size());
}
final Class> rowClass = row.getClass();
final Type> rowType = N.typeOf(rowClass);
if (rowType.isObjectArray()) {
final Object[] a = (Object[]) row;
if (a.length < this._columnNameList.size()) {
throw new IllegalArgumentException(
"The size of array (" + a.length + ") is less than the size of column (" + this._columnNameList.size() + ")");
}
if (rowIndex == size()) {
for (int i = 0, len = this._columnNameList.size(); i < len; i++) {
_columnList.get(i).add(a[i]);
}
} else {
for (int i = 0, len = this._columnNameList.size(); i < len; i++) {
_columnList.get(i).add(rowIndex, a[i]);
}
}
} else if (rowType.isCollection()) {
final Collection c = (Collection) row;
if (c.size() < this._columnNameList.size()) {
throw new IllegalArgumentException(
"The size of collection (" + c.size() + ") is less than the size of column (" + this._columnNameList.size() + ")");
}
final Iterator it = c.iterator();
if (rowIndex == size()) {
for (int i = 0, len = this._columnNameList.size(); i < len; i++) {
_columnList.get(i).add(it.next());
}
} else {
for (int i = 0, len = this._columnNameList.size(); i < len; i++) {
_columnList.get(i).add(rowIndex, it.next());
}
}
} else if (rowType.isMap()) {
final Map map = (Map) row;
final Object[] a = new Object[this._columnNameList.size()];
int idx = 0;
for (String columnName : this._columnNameList) {
a[idx] = map.get(columnName);
if (a[idx] == null && map.containsKey(columnName) == false) {
throw new IllegalArgumentException("Column (" + columnName + ") is not found in map (" + map.keySet() + ")");
}
idx++;
}
if (rowIndex == size()) {
for (int i = 0, len = this._columnNameList.size(); i < len; i++) {
_columnList.get(i).add(a[i]);
}
} else {
for (int i = 0, len = this._columnNameList.size(); i < len; i++) {
_columnList.get(i).add(rowIndex, a[i]);
}
}
} else if (rowType.isEntity()) {
final Object[] a = new Object[this._columnNameList.size()];
Method propGetMethod = null;
int idx = 0;
for (String columnName : this._columnNameList) {
propGetMethod = ClassUtil.getPropGetMethod(rowClass, columnName);
if (propGetMethod == null) {
throw new IllegalArgumentException("Column (" + columnName + ") is not found in entity (" + rowClass + ")");
}
a[idx++] = ClassUtil.getPropValue(row, propGetMethod);
}
if (rowIndex == size()) {
for (int i = 0, len = this._columnNameList.size(); i < len; i++) {
_columnList.get(i).add(a[i]);
}
} else {
for (int i = 0, len = this._columnNameList.size(); i < len; i++) {
_columnList.get(i).add(rowIndex, a[i]);
}
}
} else {
throw new IllegalArgumentException(
"Unsupported row type: " + ClassUtil.getCanonicalClassName(rowClass) + ". Only Array, List/Set, Map and entity class are supported");
}
modCount++;
}
@Override
public void removeRow(final int rowIndex) {
checkFrozen();
this.checkRowNum(rowIndex);
for (int i = 0, len = this._columnList.size(); i < len; i++) {
_columnList.get(i).remove(rowIndex);
}
modCount++;
}
@Override
@SafeVarargs
public final void removeRows(int... indices) {
checkFrozen();
for (int rowIndex : indices) {
this.checkRowNum(rowIndex);
}
for (int i = 0, len = this._columnList.size(); i < len; i++) {
N.deleteAll(_columnList.get(i), indices);
}
modCount++;
}
@Override
public void removeRowRange(int inclusiveFromRowIndex, int exclusiveToRowIndex) {
checkFrozen();
this.checkRowIndex(inclusiveFromRowIndex, exclusiveToRowIndex);
for (int i = 0, len = this._columnList.size(); i < len; i++) {
_columnList.get(i).subList(inclusiveFromRowIndex, exclusiveToRowIndex).clear();
}
modCount++;
}
@Override
public void updateRow(int rowIndex, Try.Function, ?, E> func) throws E {
checkFrozen();
this.checkRowNum(rowIndex);
final Try.Function func2 = (Try.Function) func;
for (List column : _columnList) {
column.set(rowIndex, func2.apply(column.get(rowIndex)));
}
modCount++;
}
@Override
public void updateRows(int[] indices, Try.Function, ?, E> func) throws E {
checkFrozen();
for (int rowIndex : indices) {
this.checkRowNum(rowIndex);
}
final Try.Function func2 = (Try.Function) func;
for (List column : _columnList) {
for (int rowIndex : indices) {
column.set(rowIndex, func2.apply(column.get(rowIndex)));
}
}
modCount++;
}
@Override
public void updateAll(Try.Function, ?, E> func) throws E {
checkFrozen();
final Try.Function func2 = (Try.Function) func;
final int size = size();
for (List column : _columnList) {
for (int i = 0; i < size; i++) {
column.set(i, func2.apply(column.get(i)));
}
}
modCount++;
}
@Override
public void replaceIf(Try.Predicate, E> predicate, Object newValue) throws E {
checkFrozen();
@SuppressWarnings("rawtypes")
final Try.Predicate Predicate2 = (Try.Predicate) predicate;
final int size = size();
Object val = null;
for (List column : _columnList) {
for (int i = 0; i < size; i++) {
val = column.get(i);
column.set(i, Predicate2.test(val) ? newValue : val);
}
}
modCount++;
}
@Override
public int currentRowNum() {
return _currentRowNum;
}
@Override
public DataSet absolute(final int rowNum) {
checkRowNum(rowNum);
_currentRowNum = rowNum;
return this;
}
@SuppressWarnings("unchecked")
@Override
public Object[] getRow(final int rowNum) {
return getRow(Object[].class, rowNum);
}
@Override
public T getRow(final Class extends T> rowClass, final int rowNum) {
return getRow(rowClass, _columnNameList, rowNum);
}
@SuppressWarnings("unchecked")
@Override
public T getRow(final Class extends T> rowClass, final Collection columnNames, final int rowNum) {
checkRowNum(rowNum);
final Type> rowType = N.typeOf(rowClass);
final boolean isAbstractRowClass = Modifier.isAbstract(rowClass.getModifiers());
final Constructor> intConstructor = isAbstractRowClass ? null : ClassUtil.getDeclaredConstructor(rowClass, int.class);
final Constructor> constructor = isAbstractRowClass ? null : ClassUtil.getDeclaredConstructor(rowClass);
final int columnCount = columnNames.size();
Object result = null;
if (rowType.isObjectArray()) {
result = N.newArray(rowClass.getComponentType(), columnCount);
} else if (rowType.isList() || rowType.isSet()) {
if (isAbstractRowClass) {
result = (rowType.isList() ? new ArrayList<>(columnCount) : new HashSet<>(N.initHashCapacity(columnCount)));
} else {
if (intConstructor == null) {
result = ClassUtil.invokeConstructor(constructor);
} else {
result = ClassUtil.invokeConstructor(intConstructor, columnCount);
}
}
} else if (rowType.isMap()) {
if (isAbstractRowClass) {
result = new HashMap<>(N.initHashCapacity(columnCount));
} else {
if (intConstructor == null) {
result = ClassUtil.invokeConstructor(constructor);
} else {
result = ClassUtil.invokeConstructor(intConstructor, N.initHashCapacity(columnCount));
}
}
} else if (rowType.isEntity()) {
result = N.newInstance(rowClass);
} else {
throw new IllegalArgumentException(
"Unsupported row type: " + ClassUtil.getCanonicalClassName(rowClass) + ". Only Array, List/Set, Map and entity class are supported");
}
getRow(rowType, result, checkColumnName(columnNames), columnNames, rowNum);
return (T) result;
}
@Override
public T getRow(IntFunction extends T> rowSupplier, int rowNum) {
return getRow(rowSupplier, _columnNameList, rowNum);
}
@Override
public T getRow(IntFunction extends T> rowSupplier, Collection columnNames, int rowNum) {
checkRowNum(rowNum);
final T row = rowSupplier.apply(columnNames.size());
getRow(N.typeOf(row.getClass()), row, checkColumnName(columnNames), columnNames, rowNum);
return row;
}
@Override
public Optional firstRow() {
return firstRow(Object[].class);
}
@Override
public Optional firstRow(final Class extends T> rowClass) {
return firstRow(rowClass, _columnNameList);
}
@Override
public Optional firstRow(final Class extends T> rowClass, final Collection columnNames) {
return size() == 0 ? (Optional) Optional.empty() : Optional.of(getRow(rowClass, columnNames, 0));
}
@Override
public Optional firstRow(IntFunction extends T> rowSupplier) {
return firstRow(rowSupplier, _columnNameList);
}
@Override
public Optional firstRow(IntFunction extends T> rowSupplier, Collection columnNames) {
if (size() == 0) {
return Optional.empty();
}
final T row = rowSupplier.apply(columnNames.size());
getRow(N.typeOf(row.getClass()), row, checkColumnName(columnNames), columnNames, 0);
return Optional.of(row);
}
@Override
public Optional lastRow() {
return lastRow(Object[].class);
}
@Override
public Optional lastRow(final Class extends T> rowClass) {
return lastRow(rowClass, _columnNameList);
}
@Override
public Optional lastRow(final Class extends T> rowClass, final Collection columnNames) {
return size() == 0 ? (Optional) Optional.empty() : Optional.of(getRow(rowClass, columnNames, size() - 1));
}
@SuppressWarnings("deprecation")
private void getRow(final Type> rowType, final Object output, int[] columnIndexes, final Collection columnNames, final int rowNum) {
checkRowNum(rowNum);
if (columnIndexes == null) {
columnIndexes = checkColumnName(columnNames);
}
final int columnCount = columnIndexes.length;
if (rowType.isObjectArray()) {
final Object[] result = (Object[]) output;
for (int i = 0; i < columnCount; i++) {
result[i] = _columnList.get(columnIndexes[i]).get(rowNum);
}
} else if (rowType.isCollection()) {
final Collection result = (Collection) output;
for (int i = 0; i < columnCount; i++) {
result.add(_columnList.get(columnIndexes[i]).get(rowNum));
}
} else if (rowType.isMap()) {
final Map result = (Map) output;
for (int i = 0; i < columnCount; i++) {
result.put(_columnNameList.get(columnIndexes[i]), _columnList.get(columnIndexes[i]).get(rowNum));
}
} else if (rowType.isEntity()) {
final boolean ignoreUnknownProperty = columnNames == _columnNameList;
Object result = output;
String propName = null;
Object propValue = null;
for (int i = 0; i < columnCount; i++) {
propName = _columnNameList.get(columnIndexes[i]);
propValue = _columnList.get(columnIndexes[i]).get(rowNum);
ClassUtil.setPropValue(result, propName, propValue, ignoreUnknownProperty);
}
if (result instanceof DirtyMarker) {
((DirtyMarker) result).markDirty(false);
}
} else {
throw new IllegalArgumentException(
"Unsupported row type: " + rowType.clazz().getCanonicalName() + ". Only Array, Collection, Map and entity class are supported");
}
}
@Override
public Optional lastRow(IntFunction extends T> rowSupplier) {
return lastRow(rowSupplier, _columnNameList);
}
@Override
public Optional lastRow(IntFunction extends T> rowSupplier, Collection columnNames) {
if (size() == 0) {
return Optional.empty();
}
final T row = rowSupplier.apply(columnNames.size());
getRow(N.typeOf(row.getClass()), row, checkColumnName(columnNames), columnNames, size() - 1);
return Optional.of(row);
}
@Override
public BiIterator iterator(final String columnNameA, final String columnNameB) {
return iterator(columnNameA, columnNameB, 0, size());
}
@Override
public BiIterator iterator(final String columnNameA, final String columnNameB, final int fromRowIndex, final int toRowIndex) {
this.checkRowIndex(fromRowIndex, toRowIndex);
final List columnA = _columnList.get(checkColumnName(columnNameA));
final List columnB = _columnList.get(checkColumnName(columnNameB));
final IndexedConsumer> output = new IndexedConsumer>() {
private final int expectedModCount = modCount;
@Override
public void accept(int rowIndex, Pair output) {
if (modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
output.set((A) columnA.get(rowIndex), (B) columnB.get(rowIndex));
}
};
return BiIterator.generate(fromRowIndex, toRowIndex, output);
}
@Override
public TriIterator iterator(final String columnNameA, final String columnNameB, final String columnNameC) {
return iterator(columnNameA, columnNameB, columnNameC, 0, size());
}
@Override
public TriIterator iterator(final String columnNameA, final String columnNameB, final String columnNameC, final int fromRowIndex,
final int toRowIndex) {
this.checkRowIndex(fromRowIndex, toRowIndex);
final List columnA = _columnList.get(checkColumnName(columnNameA));
final List columnB = _columnList.get(checkColumnName(columnNameB));
final List columnC = _columnList.get(checkColumnName(columnNameC));
final IndexedConsumer> output = new IndexedConsumer>() {
private final int expectedModCount = modCount;
@Override
public void accept(int rowIndex, Triple output) {
if (modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
output.set((A) columnA.get(rowIndex), (B) columnB.get(rowIndex), (C) columnC.get(rowIndex));
}
};
return TriIterator.generate(fromRowIndex, toRowIndex, output);
}
@Override
public void forEach(final Try.Consumer super DisposableObjArray, E> action) throws E {
forEach(this._columnNameList, action);
}
@Override
public void forEach(final Collection columnNames, final Try.Consumer super DisposableObjArray, E> action) throws E {
forEach(columnNames, 0, size(), action);
}
@Override
public void forEach(final int fromRowIndex, final int toRowIndex, final Try.Consumer super DisposableObjArray, E> action) throws E {
forEach(this._columnNameList, fromRowIndex, toRowIndex, action);
}
@Override
public void forEach(final Collection columnNames, final int fromRowIndex, final int toRowIndex,
final Try.Consumer super DisposableObjArray, E> action) throws E {
final int[] columnIndexes = checkColumnName(columnNames);
checkRowIndex(fromRowIndex < toRowIndex ? fromRowIndex : (toRowIndex == -1 ? 0 : toRowIndex), fromRowIndex < toRowIndex ? toRowIndex : fromRowIndex);
N.checkArgNotNull(action);
if (size() == 0) {
return;
}
final int columnCount = columnIndexes.length;
final Object[] row = new Object[columnCount];
final DisposableObjArray disposableArray = DisposableObjArray.wrap(row);
if (fromRowIndex <= toRowIndex) {
for (int rowIndex = fromRowIndex; rowIndex < toRowIndex; rowIndex++) {
for (int i = 0; i < columnCount; i++) {
row[i] = _columnList.get(columnIndexes[i]).get(rowIndex);
}
action.accept(disposableArray);
}
} else {
for (int rowIndex = N.min(size() - 1, fromRowIndex); rowIndex > toRowIndex; rowIndex--) {
for (int i = 0; i < columnCount; i++) {
row[i] = _columnList.get(columnIndexes[i]).get(rowIndex);
}
action.accept(disposableArray);
}
}
}
@Override
public void forEach(Tuple2 columnNames, Try.BiConsumer, ?, E> action) throws E {
forEach(columnNames, 0, size(), action);
}
@Override
public void forEach(Tuple2 columnNames, int fromRowIndex, int toRowIndex, Try.BiConsumer, ?, E> action) throws E {
final List column1 = _columnList.get(checkColumnName(columnNames._1));
final List column2 = _columnList.get(checkColumnName(columnNames._2));
checkRowIndex(fromRowIndex < toRowIndex ? fromRowIndex : (toRowIndex == -1 ? 0 : toRowIndex), fromRowIndex < toRowIndex ? toRowIndex : fromRowIndex);
N.checkArgNotNull(action);
if (size() == 0) {
return;
}
@SuppressWarnings("rawtypes")
final Try.BiConsumer action2 = (Try.BiConsumer) action;
if (fromRowIndex <= toRowIndex) {
for (int rowIndex = fromRowIndex; rowIndex < toRowIndex; rowIndex++) {
action2.accept(column1.get(rowIndex), column2.get(rowIndex));
}
} else {
for (int rowIndex = N.min(size() - 1, fromRowIndex); rowIndex > toRowIndex; rowIndex--) {
action2.accept(column1.get(rowIndex), column2.get(rowIndex));
}
}
}
@Override
public void forEach(Tuple3 columnNames, TriConsumer, ?, ?, E> action) throws E {
forEach(columnNames, 0, size(), action);
}
@Override
public void forEach(Tuple3 columnNames, int fromRowIndex, int toRowIndex, TriConsumer, ?, ?, E> action)
throws E {
final List column1 = _columnList.get(checkColumnName(columnNames._1));
final List column2 = _columnList.get(checkColumnName(columnNames._2));
final List column3 = _columnList.get(checkColumnName(columnNames._3));
checkRowIndex(fromRowIndex < toRowIndex ? fromRowIndex : (toRowIndex == -1 ? 0 : toRowIndex), fromRowIndex < toRowIndex ? toRowIndex : fromRowIndex);
N.checkArgNotNull(action);
if (size() == 0) {
return;
}
@SuppressWarnings("rawtypes")
final Try.TriConsumer action2 = (Try.TriConsumer) action;
if (fromRowIndex <= toRowIndex) {
for (int rowIndex = fromRowIndex; rowIndex < toRowIndex; rowIndex++) {
action2.accept(column1.get(rowIndex), column2.get(rowIndex), column3.get(rowIndex));
}
} else {
for (int rowIndex = N.min(size() - 1, fromRowIndex); rowIndex > toRowIndex; rowIndex--) {
action2.accept(column1.get(rowIndex), column2.get(rowIndex), column3.get(rowIndex));
}
}
}
@SuppressWarnings("unchecked")
@Override
public List toList() {
return toList(Object[].class);
}
@SuppressWarnings("unchecked")
@Override
public List toList(final int fromRowIndex, final int toRowIndex) {
return toList(Object[].class, fromRowIndex, toRowIndex);
}
@Override
public List toList(final Class extends T> rowClass) {
return toList(rowClass, 0, size());
}
@Override
public List toList(final Class extends T> rowClass, final int fromRowIndex, final int toRowIndex) {
return toList(rowClass, this._columnNameList, fromRowIndex, toRowIndex);
}
@SuppressWarnings("unchecked")
@Override
public List toList(final Class extends T> rowClass, final Collection