@Test public void testSet() { GameMatrix matrix = new CachedGameMatrixImpl(); byte value = matrix.get(0, 0); assertEquals(GameMatrix.UNSET, value); matrix.set(0,0,(byte)4); value = matrix.get(0, 0); assertEquals(4, value); }
@Override public void set(final int row, final int column, final byte value) { assert validValue(value); byte oldValue = super.get(row, column); assert validValue(oldValue); if (oldValue != UNSET) { int bitMask = 1 << oldValue; rowFree[row] |= bitMask; columnFree[column] |= bitMask; blockFree[row / BLOCK_SIZE][column / BLOCK_SIZE] |= bitMask; setCount--; assert setCount >= 0; } if (value != UNSET) { assert (getFreeMask(row, column) & (1 << value)) != 0 : "Passed value " + value + " is already used, would destroy class invariant"; int bitMask = ~(1 << value); rowFree[row] &= bitMask; columnFree[column] &= bitMask; blockFree[row / BLOCK_SIZE][column / BLOCK_SIZE] &= bitMask; setCount++; assert setCount <= TOTAL_FIELDS; } super.set(row, column, value); }
CachedGameMatrixImpl extends GameMatrixImpl implements Cloneable { @Override public void set(final int row, final int column, final byte value) { assert validValue(value); byte oldValue = super.get(row, column); assert validValue(oldValue); if (oldValue != UNSET) { int bitMask = 1 << oldValue; rowFree[row] |= bitMask; columnFree[column] |= bitMask; blockFree[row / BLOCK_SIZE][column / BLOCK_SIZE] |= bitMask; setCount--; assert setCount >= 0; } if (value != UNSET) { assert (getFreeMask(row, column) & (1 << value)) != 0 : "Passed value " + value + " is already used, would destroy class invariant"; int bitMask = ~(1 << value); rowFree[row] &= bitMask; columnFree[column] &= bitMask; blockFree[row / BLOCK_SIZE][column / BLOCK_SIZE] &= bitMask; setCount++; assert setCount <= TOTAL_FIELDS; } super.set(row, column, value); } }
CachedGameMatrixImpl extends GameMatrixImpl implements Cloneable { @Override public void set(final int row, final int column, final byte value) { assert validValue(value); byte oldValue = super.get(row, column); assert validValue(oldValue); if (oldValue != UNSET) { int bitMask = 1 << oldValue; rowFree[row] |= bitMask; columnFree[column] |= bitMask; blockFree[row / BLOCK_SIZE][column / BLOCK_SIZE] |= bitMask; setCount--; assert setCount >= 0; } if (value != UNSET) { assert (getFreeMask(row, column) & (1 << value)) != 0 : "Passed value " + value + " is already used, would destroy class invariant"; int bitMask = ~(1 << value); rowFree[row] &= bitMask; columnFree[column] &= bitMask; blockFree[row / BLOCK_SIZE][column / BLOCK_SIZE] &= bitMask; setCount++; assert setCount <= TOTAL_FIELDS; } super.set(row, column, value); } CachedGameMatrixImpl(); }
CachedGameMatrixImpl extends GameMatrixImpl implements Cloneable { @Override public void set(final int row, final int column, final byte value) { assert validValue(value); byte oldValue = super.get(row, column); assert validValue(oldValue); if (oldValue != UNSET) { int bitMask = 1 << oldValue; rowFree[row] |= bitMask; columnFree[column] |= bitMask; blockFree[row / BLOCK_SIZE][column / BLOCK_SIZE] |= bitMask; setCount--; assert setCount >= 0; } if (value != UNSET) { assert (getFreeMask(row, column) & (1 << value)) != 0 : "Passed value " + value + " is already used, would destroy class invariant"; int bitMask = ~(1 << value); rowFree[row] &= bitMask; columnFree[column] &= bitMask; blockFree[row / BLOCK_SIZE][column / BLOCK_SIZE] &= bitMask; setCount++; assert setCount <= TOTAL_FIELDS; } super.set(row, column, value); } CachedGameMatrixImpl(); @Override int getFreeMask(final int row, final int column); @Override void set(final int row, final int column, final byte value); @Override int getSetCount(); @Override Object clone(); }
CachedGameMatrixImpl extends GameMatrixImpl implements Cloneable { @Override public void set(final int row, final int column, final byte value) { assert validValue(value); byte oldValue = super.get(row, column); assert validValue(oldValue); if (oldValue != UNSET) { int bitMask = 1 << oldValue; rowFree[row] |= bitMask; columnFree[column] |= bitMask; blockFree[row / BLOCK_SIZE][column / BLOCK_SIZE] |= bitMask; setCount--; assert setCount >= 0; } if (value != UNSET) { assert (getFreeMask(row, column) & (1 << value)) != 0 : "Passed value " + value + " is already used, would destroy class invariant"; int bitMask = ~(1 << value); rowFree[row] &= bitMask; columnFree[column] &= bitMask; blockFree[row / BLOCK_SIZE][column / BLOCK_SIZE] &= bitMask; setCount++; assert setCount <= TOTAL_FIELDS; } super.set(row, column, value); } CachedGameMatrixImpl(); @Override int getFreeMask(final int row, final int column); @Override void set(final int row, final int column, final byte value); @Override int getSetCount(); @Override Object clone();  }