Class Grid


  • class Grid
    extends java.lang.Object
    This class represents a grid of elements. Complex elements (which span over few cells of a grid) are stored as duplicates. For example if element with width = 2, height = 3 added to a grid, grid will store it as 6 elements each having width = height = 1.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  Grid.Builder
      This class is used to properly initialize starting values for grid.
      private static class  Grid.CellPlacementHelper
      This class is used to place cells on grid.
      private static class  Grid.ColumnCellComparator
      This comparator sorts cells so ones with both fixed row and column positions would go first, then cells with fixed column and then all other cells.
      private static class  Grid.CssGridCell  
      (package private) static class  Grid.GridOrder  
      private static class  Grid.RowCellComparator
      This comparator sorts cells so ones with both fixed row and column positions would go first, then cells with fixed row and then all other cells.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int columnOffset
      Column start offset, it is not zero only if there are cells with negative indexes.
      private java.util.List<GridCell> itemsWithoutPlace  
      private int rowOffset
      Row start offset, it is not zero only if there are cells with negative indexes.
      private GridCell[][] rows
      Cells container.
      private java.util.List<java.util.Collection<GridCell>> uniqueCells
      Unique grid cells cached values.
    • Constructor Summary

      Constructors 
      Constructor Description
      Grid​(int initialRowsCount, int initialColumnsCount, int columnOffset, int rowOffset)
      Creates new grid instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addCell​(GridCell cell)
      Add cell in the grid, checking that it would fit and initializing it bottom left corner (x, y).
      (package private) int collapseNullLines​(Grid.GridOrder order, int minSize)
      Deletes all null rows/columns depending on the given values.
      private int determineNullLinesStart​(Grid.GridOrder order)  
      (package private) int getColumnOffset()
      get column start offset or grid "zero column" position.
      (package private) int getNumberOfColumns()
      Gets the current number of rows of grid.
      (package private) int getNumberOfRows()
      Gets the current number of rows of grid.
      (package private) int getRowOffset()
      get row start offset or grid "zero row" position.
      (package private) GridCell[][] getRows()
      Get internal matrix of cells.
      (package private) java.util.Collection<GridCell> getUniqueGridCells​(Grid.GridOrder iterationOrder)
      Get all unique cells in the grid.
      (package private) void resize​(int height, int width)
      Resize grid if needed, so it would have given number of rows/columns.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • rows

        private GridCell[][] rows
        Cells container.
      • rowOffset

        private int rowOffset
        Row start offset, it is not zero only if there are cells with negative indexes. Such cells should not be covered by templates, so the offset represents row from which template values should be considered.
      • columnOffset

        private int columnOffset
        Column start offset, it is not zero only if there are cells with negative indexes. Such cells should not be covered by templates, so the offset represents column from which template values should be considered.
      • uniqueCells

        private final java.util.List<java.util.Collection<GridCell>> uniqueCells
        Unique grid cells cached values. first value of array contains unique cells in order from left to right and the second value contains cells in order from top to bottom.
      • itemsWithoutPlace

        private final java.util.List<GridCell> itemsWithoutPlace
    • Constructor Detail

      • Grid

        Grid​(int initialRowsCount,
             int initialColumnsCount,
             int columnOffset,
             int rowOffset)
        Creates new grid instance.
        Parameters:
        initialRowsCount - initial number of row for the grid
        initialColumnsCount - initial number of columns for the grid
        columnOffset - actual start(zero) position of columns, from where template should be applied
        rowOffset - actual start(zero) position of rows, from where template should be applied
    • Method Detail

      • getRows

        final GridCell[][] getRows()
        Get internal matrix of cells.
        Returns:
        matrix of cells.
      • getNumberOfRows

        final int getNumberOfRows()
        Gets the current number of rows of grid.
        Returns:
        the number of rows
      • getNumberOfColumns

        final int getNumberOfColumns()
        Gets the current number of rows of grid.
        Returns:
        the number of columns
      • getRowOffset

        int getRowOffset()
        get row start offset or grid "zero row" position.
        Returns:
        row start offset if there are negative indexes, 0 otherwise
      • getColumnOffset

        int getColumnOffset()
        get column start offset or grid "zero column" position.
        Returns:
        column start offset if there are negative indexes, 0 otherwise
      • getUniqueGridCells

        java.util.Collection<GridCell> getUniqueGridCells​(Grid.GridOrder iterationOrder)
        Get all unique cells in the grid. Internally big cells (height * width > 1) are stored in multiple quantities For example, cell with height = 2 and width = 2 will have 4 instances on a grid (width * height) to simplify internal grid processing. This method counts such cells as one and returns a list of unique cells. The result is cached since grid can't be changed after creation.
        Parameters:
        iterationOrder - if {GridOrder.ROW} the order of cells is from left to right, top to bottom if {GridOrder.COLUMN} the order of cells is from top to bottom, left to right
        Returns:
        collection of unique grid cells.
      • resize

        final void resize​(int height,
                          int width)
        Resize grid if needed, so it would have given number of rows/columns.
        Parameters:
        height - new grid height
        width - new grid width
      • collapseNullLines

        int collapseNullLines​(Grid.GridOrder order,
                              int minSize)
        Deletes all null rows/columns depending on the given values. If resulting grid size is less than provided minSize than some null lines will be preserved.
        Parameters:
        order - which null lines to remove - Grid.GridOrder.ROW to remove rows Grid.GridOrder.COLUMN to remove columns
        minSize - minimal size of the resulting grid
        Returns:
        the number of left lines in given order
      • addCell

        private void addCell​(GridCell cell)
        Add cell in the grid, checking that it would fit and initializing it bottom left corner (x, y).
        Parameters:
        cell - cell to and in the grid
      • determineNullLinesStart

        private int determineNullLinesStart​(Grid.GridOrder order)