Class ObservableMatrix<T>

java.lang.Object
eu.hansolo.toolbox.observables.ObservableMatrix<T>

public class ObservableMatrix<T> extends Object
  • Constructor Details

    • ObservableMatrix

      public ObservableMatrix(Class<T> type, int cols, int rows)
    • ObservableMatrix

      public ObservableMatrix(Class<T> type, int cols, int rows, boolean resizeMatrixWhenInnerRowOrColIsRemoved)
    • ObservableMatrix

      public ObservableMatrix(ObservableMatrix<T> copyFromMatrix)
  • Method Details

    • getType

      public Class<T> getType()
      Returns the type of the matrix elements
      Returns:
      the type of the matrix elements
    • getItemAt

      public T getItemAt(int x, int y)
      Returns the given item in the matrix at the given position defined by x and y
      Parameters:
      x - Column used to return item
      y - Row used to return item
      Returns:
      the given item in the matrix at the given position defined by x and y
    • setItemAt

      public void setItemAt(int x, int y, T item)
      Sets the given item in the matrix at the given position defined by x and y
      Parameters:
      x - Column where the given item will be inserted
      y - Row where the given item will be inserted
      item -
    • setItemAt

      public void setItemAt(int x, int y, T item, boolean notify)
    • removeItemAt

      public void removeItemAt(int x, int y)
      Removes item at position defined by x and y Item will be set to null
      Parameters:
      x - Column where the item will be set to null
      y - Column where the item will be set to null
    • removeItemAt

      public void removeItemAt(int x, int y, boolean notify)
    • removeItem

      public void removeItem(T item)
      If item is found in matrix it's position in the matrix will be set to null
      Parameters:
      item - Item to remove from matrix
    • removeItem

      public void removeItem(T item, boolean notify)
    • contains

      public boolean contains(T item)
      Returns true if the given item will be found in the matrix
      Parameters:
      item -
      Returns:
      true if the given item will be found in the matrix
    • getIndicesOf

      public int[] getIndicesOf(T item)
      Returns the indices of the given item as an array of int[], where [0] contains the column and [1] contains the row of the item In case the item was not found the method will return [-1, -1]
      Parameters:
      item -
      Returns:
      the indices of the given item as an array of in[]
    • getMatrix

      public AtomicReference<T>[][] getMatrix()
      Returns the 2-dimensional array of type
      Returns:
      the 2-dimensional array of type
    • getAllItems

      public List<AtomicReference<T>> getAllItems()
      Returns all items in matrix that are non null as list
      Returns:
      all items in matrix that are non null as list
    • stream

      public Stream<AtomicReference<T>> stream()
      Returns all items in matrix as stream
      Returns:
      all items in matrix as stream
    • reset

      public void reset()
    • getCol

      public List<T> getCol(int col)
      Get all items in column specified by index as list
      Parameters:
      col - index of column to return as list
      Returns:
      all items in column specified by index as list
    • getRow

      public List<T> getRow(int row)
      Get all items in row specified by index as list
      Parameters:
      row - index of row to return as list
      Returns:
      all items in row specified by index as list
    • isColEmpty

      public boolean isColEmpty(int col)
      Returns true if all items in given column index equals null
      Parameters:
      col -
      Returns:
      true if all items in given column index equals null
    • isRowEmpty

      public boolean isRowEmpty(int row)
      Returns true if all items in given row index equals null
      Parameters:
      row -
      Returns:
      true if all items in given row index equals null
    • getNoOfCols

      public int getNoOfCols()
      Returns the number of columns in the matrix
      Returns:
      the number of columsn of the matrix
    • setCols

      public void setCols(int cols)
      Sets the number of columsn in the matrix. Existing entries will be copied to the new matrix. If the number of columns is smaller than the old one, all items in columns outside of the new matrix will be lost.
      Parameters:
      cols -
    • setCols

      public void setCols(int cols, boolean notify)
    • addCol

      public void addCol(int at, Supplier<T> itemSupplier)
      Adds a column at the given position in the matrix and fills it with the items from the itemSupplier
      Parameters:
      at - position of where to add the new column
      itemSupplier - supplier of items
    • addCol

      public void addCol(int at, Supplier<T> itemSupplier, boolean notify)
    • addCol

      public void addCol(int at, List<T> items)
    • addCol

      public void addCol(int at, List<T> items, boolean notify)
    • addNullCol

      public void addNullCol(int at)
    • addNullCol

      public void addNullCol(int at, boolean notify)
    • removeCol

      public void removeCol(int at)
      Removes col at given index
      Parameters:
      at - index of col that should be removed
    • removeCol

      public void removeCol(int at, boolean notify)
    • addRow

      public void addRow(int at, Supplier<T> itemSupplier)
      Adds a row at the given position in the matrix and fills it with the items from the itemSupplier
      Parameters:
      at - position of where to add the new row
      itemSupplier - supplier of items
    • addRow

      public void addRow(int at, Supplier<T> itemSupplier, boolean notify)
    • addRow

      public void addRow(int at, List<T> items)
    • addRow

      public void addRow(int at, List<T> items, boolean notify)
    • addNullRow

      public void addNullRow(int at)
    • addNullRow

      public void addNullRow(int at, boolean notify)
    • removeRow

      public void removeRow(int at)
      Removes row at given index
      Parameters:
      at - index of row that should be removed
    • removeRow

      public void removeRow(int at, boolean notify)
    • getNoOfRows

      public int getNoOfRows()
      Returns the number of rows in the matrix
      Returns:
      the number of rows in the matrix
    • setRows

      public void setRows(int rows)
      Sets the number of rows in the matrix. Existing entries will be copied to the new matrix. If the new number of rows is smaller than the old one, all items in rows outside the new matrix will be lost.
      Parameters:
      rows -
    • setRows

      public void setRows(int rows, boolean notify)
    • getAllColumns

      public List<List<T>> getAllColumns()
    • getAllEmptyColumns

      public List<Integer> getAllEmptyColumns()
    • getAllRows

      public List<List<T>> getAllRows()
    • getAllEmptyRows

      public List<Integer> getAllEmptyRows()
    • mirrorColumns

      public void mirrorColumns()
    • mirrorColumns

      public void mirrorColumns(boolean notify)
    • mirrorRows

      public void mirrorRows()
    • mirrorRows

      public void mirrorRows(boolean notify)
    • getColsMirrored

      public boolean getColsMirrored()
    • getRowsMirrored

      public boolean getRowsMirrored()
    • getResizeMatrixWhenInnerRowOrColIsRemoved

      public boolean getResizeMatrixWhenInnerRowOrColIsRemoved()
    • setResizeMatrixWhenInnerRowOrColIsRemoved

      public void setResizeMatrixWhenInnerRowOrColIsRemoved(boolean resize)
    • isEmpty

      public boolean isEmpty()
    • addMatrixChangeObserver

      public void addMatrixChangeObserver(EvtType type, EvtObserver<MatrixChangeEvt<T>> observer)
    • removeMatrixChangeObserver

      public void removeMatrixChangeObserver(EvtType type, EvtObserver<MatrixChangeEvt<T>> observer)
    • removeAllMatrixChangeObservers

      public void removeAllMatrixChangeObservers()
    • fireMatrixChangeEvt

      public void fireMatrixChangeEvt(MatrixChangeEvt<T> evt)
    • addMatrixItemChangeObserver

      public void addMatrixItemChangeObserver(EvtType type, EvtObserver<MatrixItemChangeEvt<T>> observer)
    • removeMatrixItemChangeObserver

      public void removeMatrixItemChangeObserver(EvtType type, EvtObserver<MatrixItemChangeEvt<T>> observer)
    • removeAllMatrixItemChangeObservers

      public void removeAllMatrixItemChangeObservers()
    • fireMatrixItemChangeEvt

      public void fireMatrixItemChangeEvt(MatrixItemChangeEvt<T> evt)
    • toString

      public String toString()
      Overrides:
      toString in class Object