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.util.RowDataSet Maven / Gradle / Ivy
Go to download
A general programming library in Java/Android. It's easy to learn and simple to use with concise and powerful APIs.
/*
* Copyright (c) 2015, Haiyang Li.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.landawn.abacus.util;
import java.io.File;
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.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.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import java.util.stream.Collector;
import com.landawn.abacus.annotation.SuppressFBWarnings;
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.ParserFactory;
import com.landawn.abacus.parser.ParserUtil;
import com.landawn.abacus.parser.ParserUtil.EntityInfo;
import com.landawn.abacus.parser.ParserUtil.PropInfo;
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.Fn.Fnn;
import com.landawn.abacus.util.NoCachingNoUpdating.DisposableObjArray;
import com.landawn.abacus.util.Throwables.BiFunction;
import com.landawn.abacus.util.Throwables.Predicate;
import com.landawn.abacus.util.Throwables.TriConsumer;
import com.landawn.abacus.util.Throwables.TriFunction;
import com.landawn.abacus.util.Throwables.TriPredicate;
import com.landawn.abacus.util.Tuple.Tuple2;
import com.landawn.abacus.util.Tuple.Tuple3;
import com.landawn.abacus.util.u.Optional;
import com.landawn.abacus.util.function.IndexedConsumer;
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.
*
* @author Haiyang Li
* @since 0.8
*/
public class RowDataSet implements DataSet, Cloneable {
static final char PROP_NAME_SEPARATOR = '.';
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);
List _columnNameList;
List> _columnList;
Map _columnIndexMap;
int[] _columnIndexes;
int _currentRowNum = 0;
boolean _isFrozen = false;
Properties _properties;
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), "Dupliated column names: {}", columnNameList);
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;
// }
/**
* Column name list.
*
* @return
*/
@Override
public ImmutableList columnNameList() {
// return _columnNameList;
return ImmutableList.of(_columnNameList);
}
/**
* Gets the column name.
*
* @param columnIndex
* @return
*/
@Override
public String getColumnName(final int columnIndex) {
return _columnNameList.get(columnIndex);
}
/**
* Gets the column index.
*
* @param columnName
* @return
*/
@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;
}
/**
* Gets the column indexes.
*
* @param columnNames
* @return
*/
@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;
}
/**
*
* @param columnName
* @return true, if successful
*/
@Override
public boolean containsColumn(final String columnName) {
return getColumnIndex(columnName) >= 0;
}
/**
* Contains all columns.
*
* @param columnNames
* @return true, if successful
*/
@Override
public boolean containsAllColumns(final Collection columnNames) {
for (String columnName : columnNames) {
if (!containsColumn(columnName)) {
return false;
}
}
return true;
}
/**
*
* @param columnName
* @param newColumnName
*/
@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++;
}
/**
*
* @param oldNewNames
*/
@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());
}
}
/**
*
* @param
* @param columnName
* @param func
* @throws E the e
*/
@Override
public void renameColumn(final String columnName, final Throwables.Function func) throws E {
renameColumn(columnName, func.apply(columnName));
}
/**
*
* @param
* @param columnNames
* @param func
* @throws E the e
*/
@Override
public void renameColumns(final Collection columnNames, final Throwables.Function func) throws E {
checkColumnName(columnNames);
final Map map = N.newHashMap(columnNames.size());
for (String columnName : columnNames) {
map.put(columnName, func.apply(columnName));
}
renameColumns(map);
}
/**
*
* @param
* @param func
* @throws E the e
*/
@Override
public void renameColumns(final Throwables.Function func) throws E {
renameColumns(_columnNameList, func);
}
/**
*
* @param columnName
* @param newPosition
*/
@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++;
}
/**
*
* @param columnNameNewPositionMap
*/
@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, (Comparator>) (o1, o2) -> 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(), _columnNameList.remove(currentColumnIndex));
_columnList.add(entry.getValue(), _columnList.remove(currentColumnIndex));
_columnIndexMap = null;
}
}
modCount++;
}
/**
*
* @param columnNameA
* @param columnNameB
*/
@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++;
}
/**
*
* @param rowIndex
* @param newRowIndex
*/
@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++;
}
/**
*
* @param rowIndexA
* @param rowIndexB
*/
@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++;
}
/**
*
* @param
* @param rowIndex
* @param columnIndex
* @return
*/
@Override
public T get(final int rowIndex, final int columnIndex) {
return (T) _columnList.get(columnIndex).get(rowIndex);
}
/**
*
* @param
* @param targetType
* @param rowIndex
* @param columnIndex
* @return
*/
@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;
}
/**
*
* @param rowIndex
* @param columnIndex
* @param element
*/
@Override
public void set(final int rowIndex, final int columnIndex, final Object element) {
checkFrozen();
_columnList.get(columnIndex).set(rowIndex, element);
modCount++;
}
/**
* Checks if is null.
*
* @param rowIndex
* @param columnIndex
* @return true, if is null
*/
@Override
public boolean isNull(final int rowIndex, final int columnIndex) {
return get(rowIndex, columnIndex) == null;
}
/**
*
* @param
* @param columnIndex
* @return
*/
@SuppressWarnings("unchecked")
@Override
public T get(final int columnIndex) {
return (T) _columnList.get(columnIndex).get(_currentRowNum);
}
/**
*
* @param
* @param targetType
* @param columnIndex
* @return
*/
@Override
public T get(final Class targetType, final int columnIndex) {
T rt = get(columnIndex);
return (rt == null) ? N.defaultValueOf(targetType) : rt;
}
/**
*
* @param
* @param columnName
* @return
*/
@SuppressWarnings("unchecked")
@Override
public T get(final String columnName) {
return (T) get(checkColumnName(columnName));
}
/**
*
* @param
* @param targetType
* @param columnName
* @return
*/
@Override
public T get(final Class targetType, final String columnName) {
return get(targetType, checkColumnName(columnName));
}
/**
* Gets the or default.
*
* @param
* @param columnIndex
* @param defaultValue
* @return
*/
@Override
public T getOrDefault(int columnIndex, T defaultValue) {
return columnIndex < 0 ? defaultValue : (T) get(columnIndex);
}
/**
* Gets the or default.
*
* @param
* @param columnName
* @param defaultValue
* @return
*/
@Override
public T getOrDefault(final String columnName, T defaultValue) {
return getOrDefault(getColumnIndex(columnName), defaultValue);
}
/**
* Gets the boolean.
*
* @param columnIndex
* @return
*/
@Override
public boolean getBoolean(final int columnIndex) {
Boolean rt = get(boolean.class, columnIndex);
return (rt == null) ? false : rt;
}
/**
* Gets the boolean.
*
* @param columnName
* @return
*/
@Override
public boolean getBoolean(final String columnName) {
return getBoolean(checkColumnName(columnName));
}
/**
* Gets the char.
*
* @param columnIndex
* @return
*/
@Override
public char getChar(final int columnIndex) {
Character rt = get(columnIndex);
return (rt == null) ? 0 : rt;
}
/**
* Gets the char.
*
* @param columnName
* @return
*/
@Override
public char getChar(final String columnName) {
return getChar(checkColumnName(columnName));
}
/**
* Gets the byte.
*
* @param columnIndex
* @return
*/
@Override
public byte getByte(final int columnIndex) {
Number rt = get(columnIndex);
return (rt == null) ? 0 : rt.byteValue();
}
/**
* Gets the byte.
*
* @param columnName
* @return
*/
@Override
public byte getByte(final String columnName) {
return getByte(checkColumnName(columnName));
}
/**
* Gets the short.
*
* @param columnIndex
* @return
*/
@Override
public short getShort(final int columnIndex) {
Number rt = get(columnIndex);
return (rt == null) ? 0 : rt.shortValue();
}
/**
* Gets the short.
*
* @param columnName
* @return
*/
@Override
public short getShort(final String columnName) {
return getShort(checkColumnName(columnName));
}
/**
* Gets the int.
*
* @param columnIndex
* @return
*/
@Override
public int getInt(final int columnIndex) {
Number rt = get(columnIndex);
return (rt == null) ? 0 : rt.intValue();
}
/**
* Gets the int.
*
* @param columnName
* @return
*/
@Override
public int getInt(final String columnName) {
return getInt(checkColumnName(columnName));
}
/**
* Gets the long.
*
* @param columnIndex
* @return
*/
@Override
public long getLong(final int columnIndex) {
Number rt = get(columnIndex);
return (rt == null) ? 0L : rt.longValue();
}
/**
* Gets the long.
*
* @param columnName
* @return
*/
@Override
public long getLong(final String columnName) {
return getLong(checkColumnName(columnName));
}
/**
* Gets the float.
*
* @param columnIndex
* @return
*/
@Override
public float getFloat(final int columnIndex) {
Number rt = get(columnIndex);
return (rt == null) ? 0f : rt.floatValue();
}
/**
* Gets the float.
*
* @param columnName
* @return
*/
@Override
public float getFloat(final String columnName) {
return getFloat(checkColumnName(columnName));
}
/**
* Gets the double.
*
* @param columnIndex
* @return
*/
@Override
public double getDouble(final int columnIndex) {
Number rt = get(columnIndex);
return (rt == null) ? 0d : rt.doubleValue();
}
/**
* Gets the double.
*
* @param columnName
* @return
*/
@Override
public double getDouble(final String columnName) {
return getDouble(checkColumnName(columnName));
}
/**
* Checks if is null.
*
* @param columnIndex
* @return true, if is null
*/
@Override
public boolean isNull(final int columnIndex) {
return get(columnIndex) == null;
}
/**
* Checks if is null.
*
* @param columnName
* @return true, if is null
*/
@Override
public boolean isNull(final String columnName) {
return get(columnName) == null;
}
/**
*
* @param columnIndex
* @param value
*/
@Override
public void set(final int columnIndex, final Object value) {
checkFrozen();
_columnList.get(columnIndex).set(_currentRowNum, value);
modCount++;
}
/**
*
* @param columnName
* @param value
*/
@Override
public void set(final String columnName, final Object value) {
set(checkColumnName(columnName), value);
}
/**
* Gets the column.
*
* @param
* @param columnIndex
* @return
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public ImmutableList getColumn(final int columnIndex) {
// return (List) _columnList.get(columnIndex);
return ImmutableList.of((List) _columnList.get(columnIndex));
}
/**
* Gets the column.
*
* @param
* @param columnName
* @return
*/
@SuppressWarnings("unchecked")
@Override
public ImmutableList getColumn(final String columnName) {
return getColumn(checkColumnName(columnName));
}
/**
* Copy of column.
*
* @param
* @param columnName
* @return
*/
@SuppressWarnings("rawtypes")
@Override
public List copyOfColumn(final String columnName) {
return new ArrayList<>((List) _columnList.get(checkColumnName(columnName)));
}
/**
* Adds the column.
*
* @param columnName
* @param column
*/
@Override
public void addColumn(final String columnName, final List> column) {
addColumn(_columnList.size(), columnName, column);
}
/**
* Adds the column.
*
* @param columnIndex
* @param columnName
* @param 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++;
}
/**
* Adds the column.
*
* @param
* @param
* @param newColumnName
* @param fromColumnName
* @param func
* @throws E the e
*/
@Override
public void addColumn(String newColumnName, String fromColumnName, Throwables.Function func) throws E {
addColumn(_columnList.size(), newColumnName, fromColumnName, func);
}
/**
* Adds the column.
*
* @param
* @param
* @param columnIndex
* @param newColumnName
* @param fromColumnName
* @param func
* @throws E the e
*/
@Override
public void addColumn(int columnIndex, final String newColumnName, String fromColumnName, Throwables.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 Throwables.Function mapper2 = (Throwables.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++;
}
/**
* Adds the column.
*
* @param
* @param newColumnName
* @param fromColumnNames
* @param func
* @throws E the e
*/
@Override
public void addColumn(String newColumnName, Collection fromColumnNames,
Throwables.Function super DisposableObjArray, ?, E> func) throws E {
addColumn(_columnList.size(), newColumnName, fromColumnNames, func);
}
/**
* Adds the column.
*
* @param
* @param columnIndex
* @param newColumnName
* @param fromColumnNames
* @param func
* @throws E the e
*/
@Override
public void addColumn(int columnIndex, final String newColumnName, Collection fromColumnNames,
Throwables.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 Throwables.Function mapper2 = (Throwables.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++;
}
/**
* Update column index.
*
* @param columnIndex
* @param newColumnName
*/
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;
}
}
/**
* Adds the column.
*
* @param
* @param newColumnName
* @param fromColumnNames
* @param func
* @throws E the e
*/
@Override
public void addColumn(String newColumnName, Tuple2 fromColumnNames, Throwables.BiFunction, ?, ?, E> func) throws E {
addColumn(_columnList.size(), newColumnName, fromColumnNames, func);
}
/**
* Adds the column.
*
* @param
* @param columnIndex
* @param newColumnName
* @param fromColumnNames
* @param func
* @throws E the e
*/
@Override
public void addColumn(int columnIndex, final String newColumnName, Tuple2 fromColumnNames,
Throwables.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 Throwables.BiFunction mapper2 = (Throwables.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++;
}
/**
* Adds the column.
*
* @param
* @param newColumnName
* @param fromColumnNames
* @param func
* @throws E the e
*/
@Override
public void addColumn(String newColumnName, Tuple3 fromColumnNames, TriFunction, ?, ?, ?, E> func)
throws E {
addColumn(_columnList.size(), newColumnName, fromColumnNames, func);
}
/**
* Adds the column.
*
* @param
* @param columnIndex
* @param newColumnName
* @param fromColumnNames
* @param func
* @throws E the e
*/
@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 Throwables.TriFunction mapper2 = (Throwables.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++;
}
/**
* Removes the column.
*
* @param
* @param columnName
* @return
*/
@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;
}
/**
* Removes the columns.
*
* @param columnNames
*/
@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++;
}
/**
* Removes the columns.
*
* @param
* @param filter
* @throws E the e
*/
@Override
public void removeColumns(Predicate filter) throws E {
removeColumns(N.filter(_columnNameList, filter));
}
// /**
// * Removes the columns if.
// *
// * @param
// * @param filter
// * @throws E the e
// */
// @Deprecated
// @Override
// public void removeColumnsIf(Predicate filter) throws E {
// removeColumns(filter);
// }
/**
*
* @param columnName
* @param targetType
*/
@Override
public void convertColumn(final String columnName, final Class> targetType) {
checkFrozen();
convertColumnType(checkColumnName(columnName), targetType);
}
/**
*
* @param columnTargetTypes
*/
@Override
public void convertColumns(final Map> columnTargetTypes) {
checkFrozen();
checkColumnName(columnTargetTypes.keySet());
for (Map.Entry> entry : columnTargetTypes.entrySet()) {
convertColumnType(checkColumnName(entry.getKey()), entry.getValue());
}
}
/**
*
* @param
* @param
* @param columnName
* @param func
* @throws E the e
*/
@Override
public void updateColumn(final String columnName, final Throwables.Function, ?, E> func) throws E {
checkFrozen();
final Throwables.Function func2 = (Throwables.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++;
}
/**
*
* @param
* @param
* @param columnNames
* @param func
* @throws E the e
*/
@Override
public void updateColumns(final Collection columnNames, final Throwables.Function, ?, E> func) throws E {
checkColumnName(columnNames);
final Throwables.Function func2 = (Throwables.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++;
}
/**
* Convert column type.
*
* @param columnIndex
* @param targetType
*/
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++;
}
/**
*
* @param columnNames
* @param newColumnName
* @param newColumnClass
*/
@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);
}
/**
*
* @param
* @param columnNames
* @param newColumnName
* @param combineFunc
* @throws E the e
*/
@Override
public void combineColumns(Collection columnNames, final String newColumnName,
Throwables.Function super DisposableObjArray, ?, E> combineFunc) throws E {
addColumn(newColumnName, columnNames, combineFunc);
removeColumns(columnNames);
}
/**
*
* @param
* @param columnNameFilter
* @param newColumnName
* @param newColumnClass
* @throws E the e
*/
@Override
public void combineColumns(Throwables.Predicate columnNameFilter, final String newColumnName, Class> newColumnClass)
throws E {
combineColumns(N.filter(_columnNameList, columnNameFilter), newColumnName, newColumnClass);
}
/**
*
* @param
* @param
* @param columnNameFilter
* @param newColumnName
* @param combineFunc
* @throws E the e
* @throws E2 the e2
*/
@Override
public void combineColumns(Throwables.Predicate columnNameFilter, final String newColumnName,
Throwables.Function super DisposableObjArray, ?, E2> combineFunc) throws E, E2 {
combineColumns(N.filter(_columnNameList, columnNameFilter), newColumnName, combineFunc);
}
/**
*
* @param
* @param columnNames
* @param newColumnName
* @param combineFunc
* @throws E the e
*/
@Override
public void combineColumns(Tuple2 columnNames, final String newColumnName,
Throwables.BiFunction, ?, ?, E> combineFunc) throws E {
addColumn(newColumnName, columnNames, combineFunc);
removeColumns(Arrays.asList(columnNames._1, columnNames._2));
}
/**
*
* @param
* @param columnNames
* @param newColumnName
* @param combineFunc
* @throws E the e
*/
@Override
public void combineColumns(Tuple3 columnNames, final String newColumnName,
Throwables.TriFunction, ?, ?, ?, E> combineFunc) throws E {
addColumn(newColumnName, columnNames, combineFunc);
removeColumns(Arrays.asList(columnNames._1, columnNames._2, columnNames._3));
}
/**
*
* @param
* @param
* @param columnName
* @param newColumnNames
* @param divideFunc
* @throws E the e
*/
@Override
public void divideColumn(final String columnName, Collection newColumnNames,
Throwables.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)) {
throw new IllegalArgumentException("Column names: " + N.intersection(_columnNameList, newColumnNames) + " already are included in this data set.");
}
@SuppressWarnings("rawtypes")
final Throwables.Function, E> divideFunc2 = (Throwables.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++;
}
/**
*
* @param
* @param
* @param columnName
* @param newColumnNames
* @param output
* @throws E the e
*/
@Override
public void divideColumn(final String columnName, Collection newColumnNames, Throwables.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)) {
throw new IllegalArgumentException("Column names: " + N.intersection(_columnNameList, newColumnNames) + " already are included in this data set.");
}
@SuppressWarnings("rawtypes")
final Throwables.BiConsumer output2 = (Throwables.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++;
}
/**
*
* @param
* @param
* @param columnName
* @param newColumnNames
* @param output
* @throws E the e
*/
@Override
public void divideColumn(final String columnName, final Tuple2 newColumnNames,
final Throwables.BiConsumer, E> output) throws E {
checkFrozen();
final int columnIndex = this.checkColumnName(columnName);
this.checkNewColumnName(newColumnNames._1);
this.checkNewColumnName(newColumnNames._2);
@SuppressWarnings("rawtypes")
final Throwables.BiConsumer, E> output2 = (Throwables.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++;
}
/**
*
* @param
* @param
* @param columnName
* @param newColumnNames
* @param output
* @throws E the e
*/
@Override
public void divideColumn(final String columnName, final Tuple3 newColumnNames,
final Throwables.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 Throwables.BiConsumer, E> output2 = (Throwables.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++;
}
/**
* Adds the row.
*
* @param row
*/
@Override
public void addRow(final Object row) {
addRow(size(), row);
}
/**
* Adds the row.
*
* @param rowIndex
* @param 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)) {
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 EntityInfo entityInfo = ParserUtil.getEntityInfo(rowClass);
final Object[] a = new Object[this._columnNameList.size()];
PropInfo propInfo = null;
int idx = 0;
for (String columnName : this._columnNameList) {
propInfo = entityInfo.getPropInfo(columnName);
if (propInfo == null) {
throw new IllegalArgumentException("Column (" + columnName + ") is not found in entity (" + rowClass + ")");
}
a[idx++] = propInfo.getPropValue(row);
}
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++;
}
/**
* Removes the row.
*
* @param rowIndex
*/
@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++;
}
/**
* Removes the rows.
*
* @param indices
*/
@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++;
}
/**
* Removes the row range.
*
* @param inclusiveFromRowIndex
* @param exclusiveToRowIndex
*/
@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++;
}
/**
*
* @param
* @param rowIndex
* @param func
* @throws E the e
*/
@Override
public void updateRow(int rowIndex, Throwables.Function, ?, E> func) throws E {
checkFrozen();
this.checkRowNum(rowIndex);
final Throwables.Function func2 = (Throwables.Function) func;
for (List column : _columnList) {
column.set(rowIndex, func2.apply(column.get(rowIndex)));
}
modCount++;
}
/**
*
* @param
* @param indices
* @param func
* @throws E the e
*/
@Override
public void updateRows(int[] indices, Throwables.Function, ?, E> func) throws E {
checkFrozen();
for (int rowIndex : indices) {
this.checkRowNum(rowIndex);
}
final Throwables.Function func2 = (Throwables.Function) func;
for (List column : _columnList) {
for (int rowIndex : indices) {
column.set(rowIndex, func2.apply(column.get(rowIndex)));
}
}
modCount++;
}
/**
*
* @param
* @param func
* @throws E the e
*/
@Override
public void updateAll(Throwables.Function, ?, E> func) throws E {
checkFrozen();
final Throwables.Function func2 = (Throwables.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++;
}
/**
*
* @param
* @param predicate
* @param newValue
* @throws E the e
*/
@Override
public void replaceIf(Throwables.Predicate, E> predicate, Object newValue) throws E {
checkFrozen();
@SuppressWarnings("rawtypes")
final Throwables.Predicate Predicate2 = (Throwables.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++;
}
/**
* Current row num.
*
* @return
*/
@Override
public int currentRowNum() {
return _currentRowNum;
}
/**
*
* @param rowNum
* @return
*/
@Override
public DataSet absolute(final int rowNum) {
checkRowNum(rowNum);
_currentRowNum = rowNum;
return this;
}
/**
* Gets the row.
*
* @param rowNum
* @return
*/
@SuppressWarnings("unchecked")
@Override
public Object[] getRow(final int rowNum) {
return getRow(Object[].class, rowNum);
}
/**
* Gets the row.
*
* @param
* @param rowClass
* @param rowNum
* @return
*/
@Override
public T getRow(final Class extends T> rowClass, final int rowNum) {
return getRow(rowClass, _columnNameList, rowNum);
}
/**
* Gets the row.
*
* @param
* @param rowClass
* @param columnNames
* @param rowNum
* @return
*/
@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 EntityInfo entityInfo = rowType.isEntity() ? ParserUtil.getEntityInfo(rowClass) : null;
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) : N.newHashSet(columnCount));
} else if (intConstructor == null) {
result = ClassUtil.invokeConstructor(constructor);
} else {
result = ClassUtil.invokeConstructor(intConstructor, columnCount);
}
} else if (rowType.isMap()) {
if (isAbstractRowClass) {
result = N.newHashMap(columnCount);
} else if (intConstructor == null) {
result = ClassUtil.invokeConstructor(constructor);
} else {
result = ClassUtil.invokeConstructor(intConstructor, columnCount);
}
} else if (rowType.isEntity()) {
result = entityInfo.createEntityResult();
} else {
throw new IllegalArgumentException(
"Unsupported row type: " + ClassUtil.getCanonicalClassName(rowClass) + ". Only Array, List/Set, Map and entity class are supported");
}
getRow(rowType, entityInfo, result, checkColumnName(columnNames), columnNames, rowNum);
return entityInfo == null ? (T) result : entityInfo.finishEntityResult(result);
}
/**
* Gets the row.
* @param rowNum
* @param rowSupplier
*
* @param
* @return
*/
@Override
public T getRow(int rowNum, IntFunction extends T> rowSupplier) {
return getRow(_columnNameList, rowNum, rowSupplier);
}
/**
* Gets the row.
* @param columnNames
* @param rowNum
* @param rowSupplier
*
* @param
* @return
*/
@Override
public T getRow(Collection columnNames, int rowNum, IntFunction extends T> rowSupplier) {
checkRowNum(rowNum);
final T row = rowSupplier.apply(columnNames.size());
getRow(N.typeOf(row.getClass()), null, row, checkColumnName(columnNames), columnNames, rowNum);
return row;
}
@Override
public Optional firstRow() {
return firstRow(Object[].class);
}
/**
*
* @param
* @param rowClass
* @return
*/
@Override
public Optional firstRow(final Class extends T> rowClass) {
return firstRow(rowClass, _columnNameList);
}
/**
*
* @param
* @param rowClass
* @param columnNames
* @return
*/
@Override
public Optional firstRow(final Class extends T> rowClass, final Collection columnNames) {
return size() == 0 ? (Optional) Optional.empty() : Optional.of(getRow(rowClass, columnNames, 0));
}
/**
*
* @param
* @param rowSupplier
* @return
*/
@Override
public Optional firstRow(IntFunction extends T> rowSupplier) {
return firstRow(_columnNameList, rowSupplier);
}
/**
*
* @param columnNames
* @param rowSupplier
* @param
* @return
*/
@Override
public Optional firstRow(Collection columnNames, IntFunction extends T> rowSupplier) {
if (size() == 0) {
return Optional.empty();
}
final T row = getRow(columnNames, 0, rowSupplier);
return Optional.of(row);
}
@Override
public Optional lastRow() {
return lastRow(Object[].class);
}
/**
*
* @param
* @param rowClass
* @return
*/
@Override
public Optional lastRow(final Class extends T> rowClass) {
return lastRow(rowClass, _columnNameList);
}
/**
*
* @param
* @param rowClass
* @param columnNames
* @return
*/
@Override
public Optional lastRow(final Class extends T> rowClass, final Collection