code: @SuppressWarnings("unchecked")
      static <V> DenseImmutableGrid<V> create(Grid<? extends V> grid) {
          if (grid instanceof DenseGrid) {
              return new DenseImmutableGrid<V>((DenseGrid<V>) grid);
          }
          int rowCount = grid.rowCount();
          int columnCount = grid.columnCount();
          validateCounts(rowCount, columnCount);
          V[] values = (V[]) new Object[rowCount * columnCount];
          for (Cell<? extends V> cell : grid.cells()) {
              values[cell.getRow() * columnCount + cell.getColumn()] = cell.getValue();
          }
          return new DenseImmutableGrid<V>(rowCount, columnCount, grid.size(), values);
      }
docs: Creates a {@code DenseImmutableGrid} copying from another grid.
  
  @param <V> the type of the value
  @param grid  the grid to copy, not null
  @return the mutable grid, not null