@Test public void testPutAt() { try { array.putAt(10001, 1, "K"); assertTrue("Failed to detect row out of bounds", false); } catch (ArrayIndexOutOfBoundsException ae) { assertTrue(true); } try { array.putAt(1, 10001, "K"); assertTrue("Failed to detect col out of bounds", false); } catch (ArrayIndexOutOfBoundsException ae) { assertTrue(true); } array.putAt(10, 100, "C"); array.putAt(30, 140, "D"); assertEquals("Returned element is wrong", "C", array.getAt(10, 100)); assertEquals("Returned element is wrong", "D", array.getAt(30, 140)); array.putAt(10, 100, "Z"); assertEquals("The overwritten value of a cell is wrong", array.getAt(10, 100), "Z"); }
@Override public void putAt(int row, int col, T value) throws ArrayIndexOutOfBoundsException { if (row>this.row || col>column){ throw new ArrayIndexOutOfBoundsException(); } else{ IndexNode rowNode = checkForIndex(rowLinkedList,row); IndexNode colNode = checkForIndex(colLinkedList, col); if (rowNode==null){ rowLinkedList.add(row); rowNode = checkForIndex(rowLinkedList,row); } if (colNode==null){ colLinkedList.add(col); colNode = checkForIndex(colLinkedList, col); } ArrayNode<T> arrayNode = insertInRow(row,col,value,rowNode); insertInCol(row,col,colNode,arrayNode); } }
SparseArray2DImpl implements ISparseArray2D<T> { @Override public void putAt(int row, int col, T value) throws ArrayIndexOutOfBoundsException { if (row>this.row || col>column){ throw new ArrayIndexOutOfBoundsException(); } else{ IndexNode rowNode = checkForIndex(rowLinkedList,row); IndexNode colNode = checkForIndex(colLinkedList, col); if (rowNode==null){ rowLinkedList.add(row); rowNode = checkForIndex(rowLinkedList,row); } if (colNode==null){ colLinkedList.add(col); colNode = checkForIndex(colLinkedList, col); } ArrayNode<T> arrayNode = insertInRow(row,col,value,rowNode); insertInCol(row,col,colNode,arrayNode); } } }
SparseArray2DImpl implements ISparseArray2D<T> { @Override public void putAt(int row, int col, T value) throws ArrayIndexOutOfBoundsException { if (row>this.row || col>column){ throw new ArrayIndexOutOfBoundsException(); } else{ IndexNode rowNode = checkForIndex(rowLinkedList,row); IndexNode colNode = checkForIndex(colLinkedList, col); if (rowNode==null){ rowLinkedList.add(row); rowNode = checkForIndex(rowLinkedList,row); } if (colNode==null){ colLinkedList.add(col); colNode = checkForIndex(colLinkedList, col); } ArrayNode<T> arrayNode = insertInRow(row,col,value,rowNode); insertInCol(row,col,colNode,arrayNode); } } SparseArray2DImpl(int row, int column); }
SparseArray2DImpl implements ISparseArray2D<T> { @Override public void putAt(int row, int col, T value) throws ArrayIndexOutOfBoundsException { if (row>this.row || col>column){ throw new ArrayIndexOutOfBoundsException(); } else{ IndexNode rowNode = checkForIndex(rowLinkedList,row); IndexNode colNode = checkForIndex(colLinkedList, col); if (rowNode==null){ rowLinkedList.add(row); rowNode = checkForIndex(rowLinkedList,row); } if (colNode==null){ colLinkedList.add(col); colNode = checkForIndex(colLinkedList, col); } ArrayNode<T> arrayNode = insertInRow(row,col,value,rowNode); insertInCol(row,col,colNode,arrayNode); } } SparseArray2DImpl(int row, int column); @Override void putAt(int row, int col, T value); @Override T removeAt(int row, int col); @Override T getAt(int row, int col); @Override List<T> getRowFor(int row); @Override List<T> getColumnFor(int col); }
SparseArray2DImpl implements ISparseArray2D<T> { @Override public void putAt(int row, int col, T value) throws ArrayIndexOutOfBoundsException { if (row>this.row || col>column){ throw new ArrayIndexOutOfBoundsException(); } else{ IndexNode rowNode = checkForIndex(rowLinkedList,row); IndexNode colNode = checkForIndex(colLinkedList, col); if (rowNode==null){ rowLinkedList.add(row); rowNode = checkForIndex(rowLinkedList,row); } if (colNode==null){ colLinkedList.add(col); colNode = checkForIndex(colLinkedList, col); } ArrayNode<T> arrayNode = insertInRow(row,col,value,rowNode); insertInCol(row,col,colNode,arrayNode); } } SparseArray2DImpl(int row, int column); @Override void putAt(int row, int col, T value); @Override T removeAt(int row, int col); @Override T getAt(int row, int col); @Override List<T> getRowFor(int row); @Override List<T> getColumnFor(int col);  }