Class Sheet<R,C,E>

java.lang.Object
com.landawn.abacus.util.Sheet<R,C,E>
Type Parameters:
R -
C -
E -
All Implemented Interfaces:
Cloneable

public final class Sheet<R,C,E> extends Object implements Cloneable
  • R = Row, C = Column, H = Horizontal, V = Vertical.
  • Since:
    0.8
    Author:
    Haiyang Li
    • Constructor Details

      • Sheet

        public Sheet()
      • Sheet

        public Sheet(Collection<R> rowKeySet, Collection<C> columnKeySet)
        Parameters:
        rowKeySet -
        columnKeySet -
      • Sheet

        public Sheet(Collection<R> rowKeySet, Collection<C> columnKeySet, Object[][] rows)
        Parameters:
        rowKeySet -
        columnKeySet -
        rows -
    • Method Details

      • rows

        public static <R, C, E> Sheet<R,C,E> rows(Collection<R> rowKeySet, Collection<C> columnKeySet, Object[][] rows)
        Type Parameters:
        R -
        C -
        E -
        Parameters:
        rowKeySet -
        columnKeySet -
        rows -
        Returns:
      • rows

        public static <R, C, E> Sheet<R,C,E> rows(Collection<R> rowKeySet, Collection<C> columnKeySet, Collection<? extends Collection<? extends E>> rows)
        Type Parameters:
        R -
        C -
        E -
        Parameters:
        rowKeySet -
        columnKeySet -
        rows -
        Returns:
      • columns

        public static <R, C, E> Sheet<R,C,E> columns(Collection<R> rowKeySet, Collection<C> columnKeySet, Object[][] columns)
        Type Parameters:
        R -
        C -
        E -
        Parameters:
        rowKeySet -
        columnKeySet -
        columns -
        Returns:
      • columns

        public static <R, C, E> Sheet<R,C,E> columns(Collection<R> rowKeySet, Collection<C> columnKeySet, Collection<? extends Collection<? extends E>> columns)
        Type Parameters:
        R -
        C -
        E -
        Parameters:
        rowKeySet -
        columnKeySet -
        columns -
        Returns:
      • rowKeySet

        public Set<R> rowKeySet()
        Row key set.
        Returns:
      • columnKeySet

        public Set<C> columnKeySet()
        Column key set.
        Returns:
      • get

        public E get(R rowKey, C columnKey)
        Parameters:
        rowKey -
        columnKey -
        Returns:
      • get

        public E get(int rowIndex, int columnIndex)
        Parameters:
        rowIndex -
        columnIndex -
        Returns:
      • get

        @Beta public E get(IntPair point)
        Parameters:
        point -
        Returns:
      • put

        public E put(R rowKey, C columnKey, E value) throws IllegalArgumentException
        Parameters:
        rowKey -
        columnKey -
        value -
        Returns:
        Throws:
        IllegalArgumentException - the illegal argument exception
      • put

        public E put(int rowIndex, int columnIndex, E value)
        Parameters:
        rowIndex -
        columnIndex -
        value -
        Returns:
      • put

        @Beta public E put(IntPair point, E value)
        Parameters:
        point -
        value -
        Returns:
      • putAll

        public void putAll(Sheet<? extends R,? extends C,? extends E> source) throws IllegalArgumentException
        Parameters:
        source -
        Throws:
        IllegalArgumentException - the illegal argument exception
      • remove

        public E remove(R rowKey, C columnKey)
        Parameters:
        rowKey -
        columnKey -
        Returns:
      • remove

        public E remove(int rowIndex, int columnIndex)
        Parameters:
        rowIndex -
        columnIndex -
        Returns:
      • remove

        @Beta public E remove(IntPair point)
        Parameters:
        point -
        Returns:
      • contains

        public boolean contains(R rowKey, C columnKey)
        Parameters:
        rowKey -
        columnKey -
        Returns:
      • containsValue

        public boolean containsValue(Object value)
        Parameters:
        value -
        Returns:
      • getRow

        public ImmutableList<E> getRow(R rowKey)
        Gets the row.
        Parameters:
        rowKey -
        Returns:
      • setRow

        public void setRow(R rowKey, Collection<? extends E> row)
        Sets the row.
        Parameters:
        rowKey -
        row -
      • addRow

        public void addRow(R rowKey, Collection<? extends E> row)
        Adds the row.
        Parameters:
        rowKey -
        row -
      • addRow

        public void addRow(int rowIndex, R rowKey, Collection<? extends E> row)
        Adds the row.
        Parameters:
        rowIndex -
        rowKey -
        row -
      • updateRow

        public <X extends Exception> void updateRow(R rowKey, Throwables.Function<? super E,? extends E,X> func) throws X
        Type Parameters:
        X -
        Parameters:
        rowKey -
        func -
        Throws:
        X - the x
      • removeRow

        public void removeRow(R rowKey)
        Removes the row.
        Parameters:
        rowKey -
      • moveRow

        public void moveRow(R rowKey, int newRowIndex)
        Move the specified row to the new position.
        Parameters:
        rowKey -
        newRowIndex -
      • swapRows

        public void swapRows(R rowKeyA, R rowKeyB)
        Swap the positions of the two specified rows.
        Parameters:
        rowKeyA -
        rowKeyB -
      • renameRow

        public void renameRow(R rowKey, R newRowKey)
        Parameters:
        rowKey -
        newRowKey -
      • containsRow

        public boolean containsRow(R rowKey)
        Parameters:
        rowKey -
        Returns:
      • row

        public Map<C,E> row(R rowKey)
        Parameters:
        rowKey -
        Returns:
      • rowMap

        public Map<R,Map<C,E>> rowMap()
        Returns:
      • getColumn

        public ImmutableList<E> getColumn(C columnKey)
        Gets the column.
        Parameters:
        columnKey -
        Returns:
      • setColumn

        public void setColumn(C columnKey, Collection<? extends E> column)
        Sets the column.
        Parameters:
        columnKey -
        column -
      • addColumn

        public void addColumn(C columnKey, Collection<? extends E> column)
        Adds the column.
        Parameters:
        columnKey -
        column -
      • addColumn

        public void addColumn(int columnIndex, C columnKey, Collection<? extends E> column)
        Adds the column.
        Parameters:
        columnIndex -
        columnKey -
        column -
      • updateColumn

        public <X extends Exception> void updateColumn(C columnKey, Throwables.Function<? super E,? extends E,X> func) throws X
        Type Parameters:
        X -
        Parameters:
        columnKey -
        func -
        Throws:
        X - the x
      • removeColumn

        public void removeColumn(C columnKey)
        Removes the column.
        Parameters:
        columnKey -
      • moveColumn

        public void moveColumn(C columnKey, int newColumnIndex)
        Move the specified column to the new position.
        Parameters:
        columnKey -
        newColumnIndex -
      • swapColumns

        public void swapColumns(C columnKeyA, C columnKeyB)
        Swap the positions of the two specified columns.
        Parameters:
        columnKeyA -
        columnKeyB -
      • renameColumn

        public void renameColumn(C columnKey, C newColumnKey)
        Parameters:
        columnKey -
        newColumnKey -
      • containsColumn

        public boolean containsColumn(C columnKey)
        Parameters:
        columnKey -
        Returns:
      • column

        public Map<R,E> column(C columnKey)
        Parameters:
        columnKey -
        Returns:
      • columnMap

        public Map<C,Map<R,E>> columnMap()
        Returns:
      • rowLength

        public int rowLength()
        Returns the size of row key set.
        Returns:
      • columnLength

        public int columnLength()
        Returns the size of column key set.
        Returns:
      • updateAll

        public <X extends Exception> void updateAll(Throwables.Function<? super E,? extends E,X> func) throws X
        Type Parameters:
        X -
        Parameters:
        func -
        Throws:
        X - the x
      • updateAll

        public <X extends Exception> void updateAll(Throwables.IntBiFunction<? extends E,X> func) throws X
        Update all elements based on points.
        Type Parameters:
        X -
        Parameters:
        func -
        Throws:
        X - the x
      • updateAll

        public <X extends Exception> void updateAll(Throwables.TriFunction<? super R,? super C,? super E,? extends E,X> func) throws X
        Update all elements based on points.
        Type Parameters:
        X -
        Parameters:
        func -
        Throws:
        X - the x
      • replaceIf

        public <X extends Exception> void replaceIf(Throwables.Predicate<? super E,X> predicate, E newValue) throws X
        Type Parameters:
        X -
        Parameters:
        predicate -
        newValue -
        Throws:
        X - the x
      • replaceIf

        public <X extends Exception> void replaceIf(Throwables.IntBiPredicate<X> predicate, E newValue) throws X
        Replace elements by Predicate.test(i, j) based on points
        Type Parameters:
        X -
        Parameters:
        predicate -
        newValue -
        Throws:
        X - the x
      • replaceIf

        public <X extends Exception> void replaceIf(Throwables.TriPredicate<? super R,? super C,? super E,X> predicate, E newValue) throws X
        Replace elements by Predicate.test(i, j) based on points
        Type Parameters:
        X -
        Parameters:
        predicate -
        newValue -
        Throws:
        X - the x
      • sortByRow

        public void sortByRow()
      • sortByRow

        public void sortByRow(Comparator<? super R> cmp)
      • sortByColumn

        public void sortByColumn()
      • sortByColumn

        public void sortByColumn(Comparator<? super C> cmp)
      • copy

        public Sheet<R,C,E> copy()
        Returns:
      • copy

        public Sheet<R,C,E> copy(Collection<R> rowKeySet, Collection<C> columnKeySet)
        Parameters:
        rowKeySet -
        columnKeySet -
        Returns:
      • clone

        public Sheet<R,C,E> clone()
        Deeply copy each element in this Sheet by Serialization/Deserialization.
        Returns:
      • clone

        public Sheet<R,C,E> clone(boolean freeze)
        Deeply copy each element in this Sheet by Serialization/Deserialization.
        Parameters:
        freeze -
        Returns:
      • merge

        public <E2, E3, X extends Exception> Sheet<R,C,E3> merge(Sheet<? extends R,? extends C,? extends E2> b, Throwables.BiFunction<? super E,? super E2,? extends E3,X> mergeFunction) throws X
        Type Parameters:
        E2 -
        E3 -
        X -
        Parameters:
        b -
        mergeFunction -
        Returns:
        Throws:
        X - the x
      • transpose

        public Sheet<C,R,E> transpose()
        Returns:
      • freeze

        public void freeze()
        Freeze.
      • isFrozen

        public boolean isFrozen()
        Returns:
      • clear

        public void clear()
        Clear.
      • size

        public int size()
        Returns the count of non-null values.
        Returns:
      • trimToSize

        public void trimToSize()
        Trim to size.
      • forEachH

        public <X extends Exception> void forEachH(Throwables.TriConsumer<? super R,? super C,? super E,X> action) throws X
        For each H.
        Type Parameters:
        X -
        Parameters:
        action -
        Throws:
        X - the x
      • forEachV

        public <X extends Exception> void forEachV(Throwables.TriConsumer<? super R,? super C,? super E,X> action) throws X
        For each V.
        Type Parameters:
        X -
        Parameters:
        action -
        Throws:
        X - the x
      • forEachNonNullH

        public <X extends Exception> void forEachNonNullH(Throwables.TriConsumer<? super R,? super C,? super E,X> action) throws X
        For each H.
        Type Parameters:
        X -
        Parameters:
        action -
        Throws:
        X - the x
      • forEachNonNullV

        public <X extends Exception> void forEachNonNullV(Throwables.TriConsumer<? super R,? super C,? super E,X> action) throws X
        For each V.
        Type Parameters:
        X -
        Parameters:
        action -
        Throws:
        X - the x
      • cellsH

        public Stream<Sheet.Cell<R,C,E>> cellsH()
        Returns:
        a stream of Cells based on the order of row.
      • cellsH

        public Stream<Sheet.Cell<R,C,E>> cellsH(int rowIndex)
        Parameters:
        rowIndex -
        Returns:
      • cellsH

        public Stream<Sheet.Cell<R,C,E>> cellsH(int fromRowIndex, int toRowIndex)
        Parameters:
        fromRowIndex -
        toRowIndex -
        Returns:
        a stream of Cells based on the order of row.
      • cellsV

        public Stream<Sheet.Cell<R,C,E>> cellsV()
        Returns:
        a stream of Cells based on the order of column.
      • cellsV

        public Stream<Sheet.Cell<R,C,E>> cellsV(int columnIndex)
        Parameters:
        columnIndex -
        Returns:
      • cellsV

        public Stream<Sheet.Cell<R,C,E>> cellsV(int fromColumnIndex, int toColumnIndex)
        Parameters:
        fromColumnIndex -
        toColumnIndex -
        Returns:
        a stream of Cells based on the order of column.
      • cellsR

        public Stream<Stream<Sheet.Cell<R,C,E>>> cellsR()
        Returns:
        a stream based on the order of row.
      • cellsR

        public Stream<Stream<Sheet.Cell<R,C,E>>> cellsR(int fromRowIndex, int toRowIndex)
        Parameters:
        fromRowIndex -
        toRowIndex -
        Returns:
        a stream based on the order of row.
      • cellsC

        public Stream<Stream<Sheet.Cell<R,C,E>>> cellsC()
        Returns:
        a stream based on the order of column.
      • cellsC

        public Stream<Stream<Sheet.Cell<R,C,E>>> cellsC(int fromColumnIndex, int toColumnIndex)
        Parameters:
        fromColumnIndex -
        toColumnIndex -
        Returns:
        a stream based on the order of column.
      • pointsH

        public Stream<IntPair> pointsH()
        Returns:
      • pointsH

        public Stream<IntPair> pointsH(int rowIndex)
        Parameters:
        rowIndex -
        Returns:
      • pointsH

        public Stream<IntPair> pointsH(int fromRowIndex, int toRowIndex)
        Parameters:
        fromRowIndex -
        toRowIndex -
        Returns:
      • pointsV

        public Stream<IntPair> pointsV()
        Returns:
      • pointsV

        public Stream<IntPair> pointsV(int columnIndex)
        Parameters:
        columnIndex -
        Returns:
      • pointsV

        public Stream<IntPair> pointsV(int fromColumnIndex, int toColumnIndex)
        Parameters:
        fromColumnIndex -
        toColumnIndex -
        Returns:
      • pointsR

        public Stream<Stream<IntPair>> pointsR()
        Returns:
      • pointsR

        public Stream<Stream<IntPair>> pointsR(int fromRowIndex, int toRowIndex)
        Parameters:
        fromRowIndex -
        toRowIndex -
        Returns:
      • pointsC

        public Stream<Stream<IntPair>> pointsC()
        Returns:
      • pointsC

        public Stream<Stream<IntPair>> pointsC(int fromColumnIndex, int toColumnIndex)
        Parameters:
        fromColumnIndex -
        toColumnIndex -
        Returns:
      • streamH

        public Stream<E> streamH()
        Returns:
        a stream based on the order of row.
      • streamH

        public Stream<E> streamH(int rowIndex)
        Parameters:
        rowIndex -
        Returns:
      • streamH

        public Stream<E> streamH(int fromRowIndex, int toRowIndex)
        Parameters:
        fromRowIndex -
        toRowIndex -
        Returns:
        a stream based on the order of row.
      • streamV

        public Stream<E> streamV()
        Returns:
        a stream based on the order of column.
      • streamV

        public Stream<E> streamV(int columnIndex)
        Parameters:
        columnIndex -
        Returns:
      • streamV

        public Stream<E> streamV(int fromColumnIndex, int toColumnIndex)
        Parameters:
        fromColumnIndex -
        toColumnIndex -
        Returns:
        a stream based on the order of column.
      • streamR

        public Stream<Stream<E>> streamR()
        Returns:
        a stream based on the order of row.
      • streamR

        public Stream<Stream<E>> streamR(int fromRowIndex, int toRowIndex)
        Parameters:
        fromRowIndex -
        toRowIndex -
        Returns:
        a stream based on the order of row.
      • streamC

        public Stream<Stream<E>> streamC()
        Returns:
        a stream based on the order of column.
      • streamC

        public Stream<Stream<E>> streamC(int fromColumnIndex, int toColumnIndex)
        Parameters:
        fromColumnIndex -
        toColumnIndex -
        Returns:
        a stream based on the order of column.
      • rows

        public Stream<Pair<R,Stream<E>>> rows()
        Returns:
        a stream based on the order of row.
      • rows

        public Stream<Pair<R,Stream<E>>> rows(int fromRowIndex, int toRowIndex)
        Parameters:
        fromRowIndex -
        toRowIndex -
        Returns:
        a stream based on the order of row.
      • columns

        public Stream<Pair<C,Stream<E>>> columns()
        Returns:
        a stream based on the order of column.
      • columns

        public Stream<Pair<C,Stream<E>>> columns(int fromColumnIndex, int toColumnIndex)
        Parameters:
        fromColumnIndex -
        toColumnIndex -
        Returns:
        a stream based on the order of column.
      • toDataSetH

        public DataSet toDataSetH()
        To data set H.
        Returns:
        a DataSet based on row.
      • toDataSetV

        public DataSet toDataSetV()
        To data set V.
        Returns:
        a DataSet based on column.
      • toArrayH

        public Object[][] toArrayH()
        To array H.
        Returns:
        a 2D array based on row.
      • toArrayH

        public <T> T[][] toArrayH(Class<T> cls)
        To array H.
        Type Parameters:
        T -
        Parameters:
        cls -
        Returns:
        a 2D array based on row.
      • toArrayV

        public Object[][] toArrayV()
        To array V.
        Returns:
        a 2D array based on column.
      • toArrayV

        public <T> T[][] toArrayV(Class<T> cls)
        To array V.
        Type Parameters:
        T -
        Parameters:
        cls -
        Returns:
        a 2D array based on column.
      • apply

        public <T, X extends Exception> T apply(Throwables.Function<? super Sheet<R,C,E>,T,X> func) throws X
        Type Parameters:
        T -
        X -
        Parameters:
        func -
        Returns:
        Throws:
        X - the x
      • accept

        public <X extends Exception> void accept(Throwables.Consumer<? super Sheet<R,C,E>,X> action) throws X
        Type Parameters:
        X -
        Parameters:
        action -
        Throws:
        X - the x
      • println

        public void println() throws UncheckedIOException
        Throws:
        UncheckedIOException - the unchecked IO exception
      • println

        public void println(Collection<R> rowKeySet, Collection<C> columnKeySet) throws UncheckedIOException
        Parameters:
        rowKeySet -
        columnKeySet -
        Throws:
        UncheckedIOException - the unchecked IO exception
      • println

        public <W extends Writer> W println(W outputWriter) throws UncheckedIOException
        Type Parameters:
        W -
        Parameters:
        outputWriter -
        Returns:
        Throws:
        UncheckedIOException - the unchecked IO exception
      • println

        public <W extends Writer> W println(W outputWriter, Collection<R> rowKeySet, Collection<C> columnKeySet) throws UncheckedIOException
        Type Parameters:
        W -
        Parameters:
        outputWriter -
        rowKeySet -
        columnKeySet -
        Returns:
        Throws:
        UncheckedIOException - the unchecked IO exception
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
        Returns:
      • equals

        public boolean equals(Object obj)
        Overrides:
        equals in class Object
        Parameters:
        obj -
        Returns:
      • toString

        public String toString()
        Overrides:
        toString in class Object
        Returns: