com.landawn.abacus.util.DataSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abacus-common Show documentation
Show all versions of abacus-common Show documentation
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.OutputStream;
import java.io.Writer;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.stream.Collector;
import com.landawn.abacus.annotation.Beta;
import com.landawn.abacus.exception.UncheckedIOException;
import com.landawn.abacus.util.NoCachingNoUpdating.DisposableObjArray;
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.stream.Stream;
/**
*
* @author Haiyang Li
* @see com.landawn.abacus.util.DataSetUtil
* @see com.landawn.abacus.util.Build.DataSetBuilder
* @see com.landawn.abacus.jdbc.JdbcUtil
* @see com.landawn.abacus.util.CSVUtil
* @see com.landawn.abacus.util.Fn.Factory
* @see com.landawn.abacus.util.Clazz
* @see com.landawn.abacus.util.N#newEmptyDataSet()
* @see com.landawn.abacus.util.N#newEmptyDataSet(Collection)
* @see com.landawn.abacus.util.N#newDataSet(Map)
* @see com.landawn.abacus.util.N#newDataSet(Collection)
* @see com.landawn.abacus.util.N#newDataSet(Collection, Collection)
* @see com.landawn.abacus.util.N#newDataSet(String, String, Map)
* @since 0.8
*/
public interface DataSet {
// /**
// * Returns the entity name associated with the query.
// *
// * @return
// */
// String entityName();
//
// /**
// * Returns the target entity class associated with the query.
// *
// * @return
// */
// Class entityClass();
/**
* Return the column name list in this DataSet.
*
* @return
*/
ImmutableList columnNameList();
/**
*
* @param columnIndex
* @return
*/
String getColumnName(int columnIndex);
/**
*
* @param columnName
* @return -1 if the specified columnName
is not found
*/
int getColumnIndex(String columnName);
/**
* -1 is set to the element in the returned array if the mapping column name is not included in this DataSet
.
*
* @param columnNames
* @return
*/
int[] getColumnIndexes(Collection columnNames);
/**
*
* @param columnName
* @return true, if successful
*/
boolean containsColumn(String columnName);
/**
* Check if this DataSet
contains all the specified columns.
*
* @param columnNames
* @return true
if all the specified columns are included in the this DataSet
*/
boolean containsAllColumns(Collection columnNames);
/**
*
* @param columnName
* @param newColumnName
*/
void renameColumn(String columnName, String newColumnName);
/**
*
* @param oldNewNames
*/
void renameColumns(Map oldNewNames);
/**
*
* @param
* @param columnName
* @param func
* @throws E the e
*/
void renameColumn(String columnName, Throwables.Function func) throws E;
/**
*
* @param
* @param columnNames
* @param func
* @throws E the e
*/
void renameColumns(Collection columnNames, Throwables.Function func) throws E;
/**
*
* @param
* @param func
* @throws E the e
*/
void renameColumns(Throwables.Function func) throws E;
/**
*
* @param columnName
* @param newPosition
*/
void moveColumn(String columnName, int newPosition);
/**
*
* @param columnNameNewPositionMap
*/
void moveColumns(Map columnNameNewPositionMap);
/**
* Swap the positions of the two specified columns.
*
* @param columnNameA
* @param columnNameB
*/
void swapColumns(String columnNameA, String columnNameB);
/**
* Move the specified row to the new position.
*
* @param rowIndex
* @param newRowIndex
*/
void moveRow(int rowIndex, int newRowIndex);
/**
* Swap the positions of the two specified rows.
*
* @param rowIndexA
* @param rowIndexB
*/
void swapRows(int rowIndexA, int rowIndexB);
/**
* There is NO underline auto-conversion from column value to target type: {@code T}.
* So the column values must be the type which is assignable to target type.
*
* @param
* @param rowIndex
* @param columnIndex
* @return
*/
T get(int rowIndex, int columnIndex);
/**
* There is NO underline auto-conversion from column value to target type: {@code T}.
* So the column values must be the type which is assignable to target type.
*
*
* Node: To follow one of general design rules in {@code Abacus}, if there is a conversion behind when the source value is not assignable to the target type, put the {@code targetType} to last parameter of the method.
* Otherwise, put the {@code targetTpye} to the first parameter of the method.
*
* @param
* @param targetType
* @param rowIndex
* @param columnIndex
* @return
* @deprecated may be misused because it implies there is an underline auto-conversion from column values to target return type but actually there is not.
*/
@Deprecated
T get(Class targetType, int rowIndex, int columnIndex);
/**
*
* @param rowIndex
* @param columnIndex
* @param element
*/
void set(int rowIndex, int columnIndex, Object element);
/**
* Checks if is null.
*
* @param rowIndex
* @param columnIndex
* @return true, if is null
*/
boolean isNull(int rowIndex, int columnIndex);
/**
*
* There is NO underline auto-conversion from column value to target type: {@code T}.
* So the column values must be the type which is assignable to target type.
*
* @param
* @param columnIndex
* @return
*/
T get(int columnIndex);
/**
*
* There is NO underline auto-conversion from column value to target type: {@code T}.
* So the column values must be the type which is assignable to target type.
*
* @param
* @param columnName
* @return
*/
T get(String columnName);
/**
* There is NO underline auto-conversion from column value to target type: {@code T}.
* So the column values must be the type which is assignable to target type.
*
*
* Node: To follow one of general design rules in {@code Abacus}, if there is a conversion behind when the source value is not assignable to the target type, put the {@code targetType} to last parameter of the method.
* Otherwise, put the {@code targetTpye} to the first parameter of the method.
*
* @param
* @param targetType
* @param columnIndex
* @return
* @deprecated may be misused because it implies there is an underline auto-conversion from column values to target return type but actually there is not.
*/
@Deprecated
T get(Class targetType, int columnIndex);
/**
*
* There is NO underline auto-conversion from column value to target type: {@code T}.
* So the column values must be the type which is assignable to target type.
*
*
* Node: To follow one of general design rules in {@code Abacus}, if there is a conversion behind when the source value is not assignable to the target type, put the {@code targetType} to last parameter of the method.
* Otherwise, put the {@code targetTpye} to the first parameter of the method.
*
* @param
* @param targetType
* @param columnName
* @return
* @deprecated may be misused because it implies there is an underline auto-conversion from column values to target return type but actually there is not.
*/
@Deprecated
T get(Class targetType, String columnName);
/**
* Returns the value from the current row and specified column if the specified {@code columnIndex} is equal or bigger than zero,
* or the specified {@code defaultValue} otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code T}.
* So the column values must be the type which is assignable to target type.
*
* @param
* @param columnIndex
* @param defaultValue
* @return
* @deprecated
*/
@Deprecated
T getOrDefault(int columnIndex, T defaultValue);
/**
* Returns the value from the current row and specified column if the specified {@code columnName} exists,
* or the specified {@code defaultValue} otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code T}.
* So the column values must be the type which is assignable to target type.
*
* @param
* @param columnName
* @param defaultValue
* @return
* @deprecated
*/
@Deprecated
T getOrDefault(String columnName, T defaultValue);
/**
* Return default value (false) if the property is null.
*
* There is NO underline auto-conversion from column value to target type: {@code Boolean}.
* So the column values must be the type which is assignable to target type.
*
* @param columnIndex
* @return
*/
boolean getBoolean(int columnIndex);
/**
* Return default value (false) if the property is null.
*
* There is NO underline auto-conversion from column value to target type: {@code Boolean}.
* So the column values must be the type which is assignable to target type.
*
* @param columnName
* @return
*/
boolean getBoolean(String columnName);
/**
* Return default value (0) if the property is null.
*
* There is NO underline auto-conversion from column value to target type: {@code Character}.
* So the column values must be the type which is assignable to target type.
*
* @param columnIndex
* @return
*/
char getChar(int columnIndex);
/**
* Return default value (0) if the property is null.
*
* There is NO underline auto-conversion from column value to target type: {@code Character}.
* So the column values must be the type which is assignable to target type.
*
* @param columnName
* @return
*/
char getChar(String columnName);
/**
* Return default value (0) if the property is null. Return Number.byteValue() otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code Byte}.
* So the column values must be the type which is assignable to target type, or {@code Number}.
*
* @param columnIndex
* @return
*/
byte getByte(int columnIndex);
/**
* Return default value (0) if the property is null. Return Number.byteValue() otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code Byte}.
* So the column values must be the type which is assignable to target type, or {@code Number}.
*
* @param columnName
* @return
*/
byte getByte(String columnName);
/**
* Return default value (0) if the property is null. Return Number.shortValue() otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code Short}.
* So the column values must be the type which is assignable to target type, or {@code Number}.
*
* @param columnIndex
* @return
*/
short getShort(int columnIndex);
/**
* Return default value (0) if the property is null. Return Number.shortValue() otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code Short}.
* So the column values must be the type which is assignable to target type, or {@code Number}.
*
* @param columnName
* @return
*/
short getShort(String columnName);
/**
* Return default value (0) if the property is null. Return Number.intValue() otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code Integer}.
* So the column values must be the type which is assignable to target type, or {@code Number}.
*
* @param columnIndex
* @return
*/
int getInt(int columnIndex);
/**
* Return default value (0) if the property is null. Return Number.intValue() otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code Integer}.
* So the column values must be the type which is assignable to target type, or {@code Number}.
*
* @param columnName
* @return
*/
int getInt(String columnName);
/**
* Return default value (0) if the property is null. Return Number.longValue() otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code Long}.
* So the column values must be the type which is assignable to target type, or {@code Number}.
*
* @param columnIndex
* @return
*/
long getLong(int columnIndex);
/**
* Return default value (0) if the property is null. Return Number.longValue() otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code Long}.
* So the column values must be the type which is assignable to target type, or {@code Number}.
*
* @param columnName
* @return
*/
long getLong(String columnName);
/**
* Return default value (0f) if the property is null. Return Number.floatValue() otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code Float}.
* So the column values must be the type which is assignable to target type, or {@code Number}.
*
* @param columnIndex
* @return
*/
float getFloat(int columnIndex);
/**
* Return default value (0f) if the property is null. Return Number.floatValue() otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code Float}.
* So the column values must be the type which is assignable to target type, or {@code Number}.
*
* @param columnName
* @return
*/
float getFloat(String columnName);
/**
* Return default value (0d) if the property is null. Return Number.doubleValue() otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code Double}.
* So the column values must be the type which is assignable to target type, or {@code Number}.
*
* @param columnIndex
* @return
*/
double getDouble(int columnIndex);
/**
* Return default value (0d) if the property is null. Return Number.doubleValue() otherwise.
*
* There is NO underline auto-conversion from column value to target type: {@code Double}.
* So the column values must be the type which is assignable to target type, or {@code Number}.
*
* @param columnName
* @return
*/
double getDouble(String columnName);
/**
* Checks if is null.
*
* @param columnIndex
* @return true, if is null
*/
boolean isNull(int columnIndex);
/**
* Checks if is null.
*
* @param columnName
* @return true, if is null
*/
boolean isNull(String columnName);
/**
*
* @param columnIndex
* @param value
*/
void set(int columnIndex, Object value);
/**
*
* @param columnName
* @param value
*/
void set(String columnName, Object value);
/**
* Must NOT modify the returned list.
*
* @param
* @param columnIndex
* @return
*/
ImmutableList getColumn(int columnIndex);
/**
* Must NOT modify the returned list.
*
* @param
* @param columnName
* @return
*/
ImmutableList getColumn(String columnName);
/**
* Copy of column.
*
* @param
* @param columnName
* @return
*/
List copyOfColumn(String columnName);
/**
*
* @param columnName
* @param column
*/
void addColumn(String columnName, List> column);
/**
*
* @param columnIndex position to add.
* @param columnName
* @param column
*/
void addColumn(int columnIndex, String columnName, List> column);
/**
* Generate the new column values from the specified column by the specified Function
.
*
* @param
* @param
* @param newColumnName
* @param fromColumnName
* @param func
* @throws E the e
*/
void addColumn(String newColumnName, String fromColumnName, Throwables.Function func) throws E;
/**
* Generate the new column values from the specified column by the specified Function
.
*
* @param
* @param
* @param columnIndex
* @param newColumnName
* @param fromColumnName
* @param func
* @throws E the e
*/
void addColumn(int columnIndex, String newColumnName, String fromColumnName, Throwables.Function func) throws E;
/**
* Generate the new column values from the specified columns by the specified Function
.
*
* @param
* @param newColumnName
* @param fromColumnNames
* @param func DON't cache or update the input parameter {@code DisposableObjArray} or its values(Array)
* @throws E the e
*/
void addColumn(String newColumnName, Collection fromColumnNames, Throwables.Function super DisposableObjArray, ?, E> func)
throws E;
/**
* Generate the new column values from the specified columns by the specified Function
.
*
* @param
* @param columnIndex
* @param newColumnName
* @param fromColumnNames
* @param func DON't cache or update the input parameter {@code DisposableObjArray} or its values(Array)
* @throws E the e
*/
void addColumn(int columnIndex, String newColumnName, Collection fromColumnNames,
Throwables.Function super DisposableObjArray, ?, E> func) throws E;
/**
* Generate the new column values from the specified columns by the specified Function
.
*
* @param
* @param newColumnName
* @param fromColumnNames
* @param func
* @throws E the e
*/
void addColumn(String newColumnName, Tuple2 fromColumnNames, Throwables.BiFunction, ?, ?, E> func) throws E;
/**
* Generate the new column values from the specified columns by the specified Function
.
*
* @param
* @param columnIndex
* @param newColumnName
* @param fromColumnNames
* @param func
* @throws E the e
*/
void addColumn(int columnIndex, String newColumnName, Tuple2 fromColumnNames, Throwables.BiFunction, ?, ?, E> func)
throws E;
/**
* Generate the new column values from the specified columns by the specified Function
.
*
* @param
* @param newColumnName
* @param fromColumnNames
* @param func
* @throws E the e
*/
void addColumn(String newColumnName, Tuple3 fromColumnNames, Throwables.TriFunction, ?, ?, ?, E> func)
throws E;
/**
* Generate the new column values from the specified columns by the specified Function
.
*
* @param
* @param columnIndex
* @param newColumnName
* @param fromColumnNames
* @param func
* @throws E the e
*/
void addColumn(int columnIndex, String newColumnName, Tuple3 fromColumnNames,
Throwables.TriFunction, ?, ?, ?, E> func) throws E;
/**
* Remove the column with the specified columnName from this DataSet.
*
* @param
* @param columnName
* @return
*/
List removeColumn(String columnName);
/**
* Remove the column(s) with the specified columnNames from this DataSet.
*
* @param columnNames
*/
void removeColumns(Collection columnNames);
/**
* Remove the column(s) whose name matches the specified {@code filter}.
*
* @param
* @param filter column name filter
* @throws E the e
*/
void removeColumns(Throwables.Predicate filter) throws E;
// /**
// * Remove the column(s) whose name matches the specified {@code filter}.
// *
// * @param
// * @param filter column name filter
// * @throws E the e
// * @deprecated replaced by {@code removeColumns}.
// */
// @Deprecated
// void removeColumnsIf(Throwables.Predicate filter) throws E;
/**
* Update the values of the specified column by the specified Try.Function.
*
* @param
* @param
* @param columnName
* @param func
* @throws E the e
*/
void updateColumn(String columnName, Throwables.Function, ?, E> func) throws E;
/**
* Update the values of the specified columns one by one with the specified Try.Function.
*
* @param
* @param
* @param columnNames
* @param func
* @throws E the e
*/
void updateColumns(Collection columnNames, Throwables.Function, ?, E> func) throws E;
/**
* Convert the specified column to target type.
*
* @param columnName
* @param targetType
*/
void convertColumn(String columnName, Class> targetType);
/**
* Convert the specified columns to target types.
*
* @param columnTargetTypes
*/
void convertColumns(Map> columnTargetTypes);
//
// /**
// * convert the specified columns to target types.
// *
// * @param targetColumnTypes fill the element with null
if don't wan to convert the target column.
// */
// void convertColumn(Class>[] targetColumnTypes);
//
/**
*
* @param columnNames
* @param newColumnName
* @param newColumnClass it can be Object[]/List/Set/Map/Entity
*/
void combineColumns(Collection columnNames, String newColumnName, Class> newColumnClass);
/**
*
* @param
* @param columnNames
* @param newColumnName
* @param combineFunc DON't cache or update the input parameter {@code DisposableObjArray} or its values(Array)
* @throws E the e
*/
void combineColumns(Collection columnNames, String newColumnName,
Throwables.Function super DisposableObjArray, ?, E> combineFunc) throws E;
/**
*
* @param
* @param columnNames
* @param newColumnName
* @param combineFunc
* @throws E the e
*/
void combineColumns(Tuple2 columnNames, String newColumnName, Throwables.BiFunction, ?, ?, E> combineFunc) throws E;
/**
*
* @param
* @param columnNames
* @param newColumnName
* @param combineFunc
* @throws E the e
*/
void combineColumns(Tuple3 columnNames, String newColumnName,
Throwables.TriFunction, ?, ?, ?, E> combineFunc) throws E;
/**
*
* @param
* @param columnNameFilter
* @param newColumnName
* @param newColumnClass it can be Object[]/List/Set/Map/Entity
* @throws E the e
*/
void combineColumns(Throwables.Predicate columnNameFilter, String newColumnName, Class> newColumnClass) throws E;
/**
*
* @param
* @param
* @param columnNameFilter
* @param newColumnName
* @param combineFunc DON't cache or update the input parameter {@code DisposableObjArray} or its values(Array)
* @throws E the e
* @throws E2 the e2
*/
void combineColumns(Throwables.Predicate columnNameFilter, String newColumnName,
Throwables.Function super DisposableObjArray, ?, E2> combineFunc) throws E, E2;
/**
*
* @param
* @param
* @param columnName
* @param newColumnNames
* @param divideFunc
* @throws E the e
*/
void divideColumn(String columnName, Collection newColumnNames, Throwables.Function, E> divideFunc)
throws E;
/**
*
* @param
* @param
* @param columnName
* @param newColumnNames
* @param output
* @throws E the e
*/
void divideColumn(String columnName, Collection newColumnNames, Throwables.BiConsumer output) throws E;
/**
*
* @param
* @param
* @param columnName
* @param newColumnNames
* @param output
* @throws E the e
*/
void divideColumn(String columnName, Tuple2 newColumnNames,
Throwables.BiConsumer, E> output) throws E;
/**
*
* @param
* @param
* @param columnName
* @param newColumnNames
* @param output
* @throws E the e
*/
void divideColumn(String columnName, Tuple3 newColumnNames,
Throwables.BiConsumer, E> output) throws E;
/**
* Adds the row.
*
* @param row can be Object[]/List/Map/Entity with getter/setter methods
*/
void addRow(Object row);
/**
* Adds the row.
*
* @param rowIndex
* @param row can be Object[]/List/Map/Entity with getter/setter methods
*/
void addRow(int rowIndex, Object row);
/**
* Removes the row.
*
* @param rowIndex
*/
void removeRow(int rowIndex);
/**
* Removes the rows.
*
* @param indices
*/
void removeRows(int... indices);
/**
* Removes the row range.
*
* @param inclusiveFromRowIndex
* @param exclusiveToRowIndex
*/
void removeRowRange(int inclusiveFromRowIndex, int exclusiveToRowIndex);
/**
* Update the values in the specified row with the specified Try.Function.
*
* @param
* @param rowIndex
* @param func
* @throws E the e
*/
void updateRow(int rowIndex, Throwables.Function, ?, E> func) throws E;
/**
* Update the values in the specified rows one by one with the specified Try.Function.
*
* @param
* @param indices
* @param func
* @throws E the e
*/
void updateRows(int[] indices, Throwables.Function, ?, E> func) throws E;
/**
* Update all the values in this DataSet with the specified Try.Function.
*
* @param
* @param func
* @throws E the e
*/
void updateAll(Throwables.Function, ?, E> func) throws E;
/**
* Replace all the values in this DataSet with the specified new value if it matches the specified condition.
*
* @param
* @param func
* @param newValue
* @throws E the e
*/
void replaceIf(Throwables.Predicate, E> func, Object newValue) throws E;
/**
* Returns the current row number.
*
* @return
*/
int currentRowNum();
/**
* Move the cursor to the specified row.
*
* @param rowNum
* @return this object itself.
*/
DataSet absolute(int rowNum);
/**
* Gets the row.
*
* @param rowNum
* @return
*/
Object[] getRow(int rowNum);
/**
* Gets the row.
*
* @param
* @param rowClass it can be Object[]/List/Set/Map/Entity
* @param rowNum
* @return
*/
T getRow(Class extends T> rowClass, int rowNum);
/**
* Gets the row.
*
* @param
* @param rowClass it can be Object[]/List/Set/Map/Entity
* @param columnNames
* @param rowNum
* @return
*/
T getRow(Class extends T> rowClass, Collection columnNames, int rowNum);
/**
* Gets the row.
* @param rowNum
* @param rowSupplier it can be Object[]/List/Set/Map/Entity
*
* @param
* @return
*/
T getRow(int rowNum, IntFunction extends T> rowSupplier);
/**
* Gets the row.
* @param columnNames
* @param rowNum
* @param rowSupplier it can be Object[]/List/Set/Map/Entity
*
* @param
* @return
*/
T getRow(Collection columnNames, int rowNum, IntFunction extends T> rowSupplier);
/**
*
* @return {@code Optional