@Test public void testGetAt() { try { array.getAt(10001, 1); assertTrue( "You failed to throw the exception properly for row out of bounds", false); } catch (ArrayIndexOutOfBoundsException ae) { assertTrue(true); } try { array.getAt(1, 10001); assertTrue( "You failed to throw the exception properly for column out of bounds", false); } catch (ArrayIndexOutOfBoundsException ae) { assertTrue(true); } assertEquals("You did not return null from an empty array", null, array.getAt(1000, 1000)); array.putAt(10, 100, "C"); array.putAt(10, 150, "L"); array.putAt(30, 150, "D"); array.putAt(150, 10, "X"); array.putAt(10, 20, "Z"); array.putAt(5, 150, "Y"); assertEquals("You failed to return a correct entry", "C", array.getAt(10, 100)); assertEquals("You did not return null for an empty cell", null, array.getAt(50, 50)); assertEquals("You failed to return a correct entry", "D", array.getAt(30, 150)); assertEquals("You did not return null for non-existent cell", null, array.getAt(100, 10)); assertEquals("You failed to return a correct entry", "X", array.getAt(150, 10)); assertEquals("Insert at head of row failed", "Z", array.getAt(10, 20)); assertEquals("Insert at head of col failed", "Y", array.getAt(5, 150)); List<String> list = array.getRowFor(10); assertEquals("Row count wrong after inserts", 3,list.size()); assertEquals("Element order wrong", "Z", list.get(0)); assertEquals("ELement order wrong", "C", list.get(1)); assertEquals("Element order wrong", "L", list.get(2)); list = array.getColumnFor(150); assertEquals("Col count wrong after inserts", 3, list.size()); assertEquals("Element order wrong", "Y", list.get(0)); assertEquals("ELement order wrong", "L", list.get(1)); assertEquals("Element order wrong", "D", list.get(2)); }
@Override public T getAt(int row, int col) throws ArrayIndexOutOfBoundsException { if (row>this.row || col>column){ throw new ArrayIndexOutOfBoundsException(); } else{ IndexNode current = rowLinkedList.head; while (current!=null){ if (row==current.index){ ArrayNode<T> currentNode = current.head; while (currentNode!=null){ if (currentNode.column==col){ return (T)(currentNode.data); } else{ currentNode = currentNode.nextCol; } } } else{ current = current.next; } } } return null; }
SparseArray2DImpl implements ISparseArray2D<T> { @Override public T getAt(int row, int col) throws ArrayIndexOutOfBoundsException { if (row>this.row || col>column){ throw new ArrayIndexOutOfBoundsException(); } else{ IndexNode current = rowLinkedList.head; while (current!=null){ if (row==current.index){ ArrayNode<T> currentNode = current.head; while (currentNode!=null){ if (currentNode.column==col){ return (T)(currentNode.data); } else{ currentNode = currentNode.nextCol; } } } else{ current = current.next; } } } return null; } }
SparseArray2DImpl implements ISparseArray2D<T> { @Override public T getAt(int row, int col) throws ArrayIndexOutOfBoundsException { if (row>this.row || col>column){ throw new ArrayIndexOutOfBoundsException(); } else{ IndexNode current = rowLinkedList.head; while (current!=null){ if (row==current.index){ ArrayNode<T> currentNode = current.head; while (currentNode!=null){ if (currentNode.column==col){ return (T)(currentNode.data); } else{ currentNode = currentNode.nextCol; } } } else{ current = current.next; } } } return null; } SparseArray2DImpl(int row, int column); }
SparseArray2DImpl implements ISparseArray2D<T> { @Override public T getAt(int row, int col) throws ArrayIndexOutOfBoundsException { if (row>this.row || col>column){ throw new ArrayIndexOutOfBoundsException(); } else{ IndexNode current = rowLinkedList.head; while (current!=null){ if (row==current.index){ ArrayNode<T> currentNode = current.head; while (currentNode!=null){ if (currentNode.column==col){ return (T)(currentNode.data); } else{ currentNode = currentNode.nextCol; } } } else{ current = current.next; } } } return null; } 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 T getAt(int row, int col) throws ArrayIndexOutOfBoundsException { if (row>this.row || col>column){ throw new ArrayIndexOutOfBoundsException(); } else{ IndexNode current = rowLinkedList.head; while (current!=null){ if (row==current.index){ ArrayNode<T> currentNode = current.head; while (currentNode!=null){ if (currentNode.column==col){ return (T)(currentNode.data); } else{ currentNode = currentNode.nextCol; } } } else{ current = current.next; } } } return null; } 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);  }