com.landawn.abacus.DataSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abacus-android Show documentation
Show all versions of abacus-android Show documentation
A general and simple library for Android
/*
* 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;
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 com.landawn.abacus.exception.UncheckedIOException;
import com.landawn.abacus.util.BiIterator;
import com.landawn.abacus.util.ImmutableList;
import com.landawn.abacus.util.ListMultimap;
import com.landawn.abacus.util.Multimap;
import com.landawn.abacus.util.NoCachingNoUpdating.DisposableObjArray;
import com.landawn.abacus.util.Pair;
import com.landawn.abacus.util.Properties;
import com.landawn.abacus.util.Sheet;
import com.landawn.abacus.util.TriIterator;
import com.landawn.abacus.util.Triple;
import com.landawn.abacus.util.Try;
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.Function;
// import com.landawn.abacus.util.function.Function;
import com.landawn.abacus.util.function.IntFunction;
import com.landawn.abacus.util.stream.Collector;
import com.landawn.abacus.util.stream.Stream;
/**
*
* @since 0.8
*
* @author Haiyang Li
*
* @see com.landawn.abacus.util.DataSetUtil
* @see com.landawn.abacus.util.Build.DataSetBuilder
* @see com.landawn.abacus.util.JdbcUtil
* @see com.landawn.abacus.util.CSVUtil
* @see com.landawn.abacus.util.function.IntFunction
* @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)
*/
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.
*/
ImmutableList columnNameList();
/**
* Method getColumnName.
*
* @param columnIndex
* @return
*/
String getColumnName(int columnIndex);
/**
* Method getColumnIndex.
*
* @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
*/
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 columnName
* @param func
*/
void renameColumn(String columnName, Try.Function func) throws E;
/**
*
* @param columnNames
* @param func
*/
void renameColumns(Collection columnNames, Try.Function func) throws E;
/**
*
* @param func
*/
void renameColumns(Try.Function func) throws E;
void moveColumn(String columnName, int newPosition);
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 columnNameA
* @param columnNameB
*/
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 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.
*
* @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);
/**
*
* @param rowIndex
* @param columnIndex
* @return
*/
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 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 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.
*
* @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.
*
* @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 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 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);
/**
*
* @param columnIndex
* @return
*/
boolean isNull(int columnIndex);
/**
*
* @param columnName
* @return
*/
boolean isNull(String columnName);
/**
* Method set.
*
* @param columnIndex
* @param value
*/
void set(int columnIndex, Object value);
/**
* Method set.
*
* @param columnName
* @param value
*/
void set(String columnName, Object value);
/**
* Must NOT modify the returned list.
*
* @param columnIndex
* @return
*/
ImmutableList getColumn(int columnIndex);
/**
* Must NOT modify the returned list.
*
* @param columnName
* @return
*/
ImmutableList getColumn(String columnName);
List copyOfColumn(String columnName);
/**
* Method addColumn.
*
* @param columnName
* @param column
*/
void addColumn(String columnName, List> column);
/**
* Method addColumn.
*
* @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 newColumnName
* @param fromColumnName
* @param func
*/
void addColumn(String newColumnName, String fromColumnName, Try.Function func) throws E;
/**
* Generate the new column values from the specified column by the specified Function
.
*
* @param columnIndex
* @param newColumnName
* @param fromColumnName
* @param func
*/
void addColumn(int columnIndex, String newColumnName, String fromColumnName, Try.Function func) throws E;
/**
* Generate the new column values from the specified columns by the specified Function
.
* @param newColumnName
* @param fromColumnNames
* @param func DON't cache or update the input parameter {@code DisposableObjArray} or its values(Array)
*/
void addColumn(String newColumnName, Collection fromColumnNames, Try.Function super DisposableObjArray, ?, E> func)
throws E;
/**
* Generate the new column values from the specified columns by the specified Function
.
*
* @param columnIndex
* @param newColumnName
* @param fromColumnNames
* @param func DON't cache or update the input parameter {@code DisposableObjArray} or its values(Array)
*/
void addColumn(int columnIndex, String newColumnName, Collection fromColumnNames,
Try.Function super DisposableObjArray, ?, E> func) throws E;
/**
* Generate the new column values from the specified columns by the specified Function
.
* @param newColumnName
* @param fromColumnNames
* @param func
*/
void addColumn(String newColumnName, Tuple2 fromColumnNames, Try.BiFunction, ?, ?, E> func) throws E;
/**
* Generate the new column values from the specified columns by the specified Function
.
*
* @param columnIndex
* @param newColumnName
* @param fromColumnNames
* @param func
*/
void addColumn(int columnIndex, String newColumnName, Tuple2 fromColumnNames, Try.BiFunction, ?, ?, E> func)
throws E;
/**
* Generate the new column values from the specified columns by the specified Function
.
* @param newColumnName
* @param fromColumnNames
* @param func
*/
void addColumn(String newColumnName, Tuple3 fromColumnNames, Try.TriFunction, ?, ?, ?, E> func) throws E;
/**
* Generate the new column values from the specified columns by the specified Function
.
*
* @param columnIndex
* @param newColumnName
* @param fromColumnNames
* @param func
*/
void addColumn(int columnIndex, String newColumnName, Tuple3 fromColumnNames,
Try.TriFunction, ?, ?, ?, E> func) throws E;
/**
* Remove the column with the specified columnName from this DataSet.
*
* @param columnName
*/
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 filter column name filter
* @throws E
*/
void removeColumns(Try.Predicate filter) throws E;
/**
* Remove the column(s) whose name matches the specified {@code filter}
*
* @param filter column name filter
* @throws E
* @deprecated replaced by {@code removeColumns}.
*/
@Deprecated
void removeColumnsIf(Try.Predicate filter) throws E;
/**
* Update the values of the specified column by the specified Try.Function.
*
* @param columnName
* @param func
*/
void updateColumn(String columnName, Try.Function func) throws E;
/**
* Update the values of the specified columns one by one with the specified Try.Function.
*
* @param columnNames
* @param func
*/
void updateColumns(Collection columnNames, Try.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
* @return
*/
void combineColumns(Collection columnNames, String newColumnName, Class> newColumnClass);
/**
*
* @param columnNames
* @param newColumnName
* @param combineFunc DON't cache or update the input parameter {@code DisposableObjArray} or its values(Array)
* @throws E
*/
void combineColumns(Collection columnNames, String newColumnName, Try.Function super DisposableObjArray, ?, E> combineFunc)
throws E;
void combineColumns(Tuple2 columnNames, String newColumnName, Try.BiFunction, ?, ?, E> combineFunc) throws E;
void combineColumns(Tuple3 columnNames, String newColumnName, Try.TriFunction, ?, ?, ?, E> combineFunc)
throws E;
/**
*
* @param columnNameFilter
* @param newColumnName
* @param newColumnClass it can be Object[]/List/Set/Map/Entity
* @throws E
*/
void combineColumns(Try.Predicate columnNameFilter, String newColumnName, Class> newColumnClass) throws E;
/**
*
* @param columnNameFilter
* @param newColumnName
* @param combineFunc DON't cache or update the input parameter {@code DisposableObjArray} or its values(Array)
* @throws E
* @throws E2
*/
void combineColumns(Try.Predicate columnNameFilter, String newColumnName,
Try.Function super DisposableObjArray, ?, E2> combineFunc) throws E, E2;
void divideColumn(String columnName, Collection newColumnNames, Try.Function, E> divideFunc) throws E;
void divideColumn(String columnName, Collection newColumnNames, Try.BiConsumer output) throws E;
void divideColumn(String columnName, Tuple2 newColumnNames, Try.BiConsumer, E> output)
throws E;
void divideColumn(String columnName, Tuple3 newColumnNames,
Try.BiConsumer, E> output) throws E;
/**
*
* @param row can be Object[]/List/Map/Entity with getter/setter methods
*/
void addRow(Object row);
/**
*
* @param row can be Object[]/List/Map/Entity with getter/setter methods
*/
void addRow(int rowIndex, Object row);
/**
*
* @param rowIndex
*/
void removeRow(int rowIndex);
/**
*
* @param indices
*/
void removeRows(int... indices);
/**
*
* @param inclusiveFromRowIndex
* @param exclusiveToRowIndex
*/
void removeRowRange(int inclusiveFromRowIndex, int exclusiveToRowIndex);
/**
* Update the values in the specified row with the specified Try.Function.
*
* @param rowIndex
* @param func
*/
void updateRow(int rowIndex, Try.Function, ?, E> func) throws E;
/**
* Update the values in the specified rows one by one with the specified Try.Function.
*
* @param indices
* @param func
*/
void updateRows(int[] indices, Try.Function, ?, E> func) throws E;
/**
* Update all the values in this DataSet with the specified Try.Function.
*
* @param func
*/
void updateAll(Try.Function, ?, E> func) throws E;
/**
* Replace all the values in this DataSet with the specified new value if it matches the specified condition.
*
* @param func
* @param newValue
*/
void replaceIf(Try.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);
/**
*
* @param rowNum
* @return
*/
Object[] getRow(int rowNum);
/**
*
* @param rowClass it can be Object[]/List/Set/Map/Entity
* @param rowNum
* @return
*/
T getRow(Class extends T> rowClass, int rowNum);
/**
*
* @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);
/**
*
* @param rowSupplier it can be Object[]/List/Set/Map/Entity
* @param rowNum
* @return
*/
T getRow(IntFunction extends T> rowSupplier, int rowNum);
/**
*
* @param rowSupplier it can be Object[]/List/Set/Map/Entity
* @param columnNames
* @param rowNum
* @return
*/
T getRow(IntFunction extends T> rowSupplier, Collection columnNames, int rowNum);
/**
*
* @return {@code Optional