@Test public void testGetColumnFor() { try { array.getColumnFor(10001); assertTrue("You failed to detect column out bounds", false); } catch (ArrayIndexOutOfBoundsException ae) { assertTrue(true); } List<String> list = array.getColumnFor(100); assertTrue("You did not return an empty list for an empty array", list.isEmpty()); array.putAt(10, 100, "C"); array.putAt(10, 150, "L"); array.putAt(30, 150, "D"); array.putAt(90, 150, "Z"); array.putAt(30, 100, "O"); array.putAt(30, 200, "T"); list = array.getColumnFor(150); assertEquals("Did not return correct entry count for column", 3, list.size()); assertEquals("First element of column was wrong", "L", list.get(0)); assertEquals("Second element of column was wrong", "D", list.get(1)); assertEquals("Third element of column was wrong", "Z", list.get(2)); list = array.getColumnFor(1000); assertTrue("You did not return empty for nonexistent column", list.isEmpty()); }
@Override public List<T> getColumnFor(int col) throws ArrayIndexOutOfBoundsException { if (col>column || col<0){ throw new ArrayIndexOutOfBoundsException(); } ArrayList<T> list = new ArrayList<T>(); IndexNode current = colLinkedList.head; while (current!=null){ if (col==current.index){ ArrayNode<T> currentNode = current.head; while (currentNode!=null){ list.add(currentNode.data); currentNode = currentNode.nextRow; } current = current.next; } else{ current = current.next; } } return list ; }
SparseArray2DImpl implements ISparseArray2D<T> { @Override public List<T> getColumnFor(int col) throws ArrayIndexOutOfBoundsException { if (col>column || col<0){ throw new ArrayIndexOutOfBoundsException(); } ArrayList<T> list = new ArrayList<T>(); IndexNode current = colLinkedList.head; while (current!=null){ if (col==current.index){ ArrayNode<T> currentNode = current.head; while (currentNode!=null){ list.add(currentNode.data); currentNode = currentNode.nextRow; } current = current.next; } else{ current = current.next; } } return list ; } }
SparseArray2DImpl implements ISparseArray2D<T> { @Override public List<T> getColumnFor(int col) throws ArrayIndexOutOfBoundsException { if (col>column || col<0){ throw new ArrayIndexOutOfBoundsException(); } ArrayList<T> list = new ArrayList<T>(); IndexNode current = colLinkedList.head; while (current!=null){ if (col==current.index){ ArrayNode<T> currentNode = current.head; while (currentNode!=null){ list.add(currentNode.data); currentNode = currentNode.nextRow; } current = current.next; } else{ current = current.next; } } return list ; } SparseArray2DImpl(int row, int column); }
SparseArray2DImpl implements ISparseArray2D<T> { @Override public List<T> getColumnFor(int col) throws ArrayIndexOutOfBoundsException { if (col>column || col<0){ throw new ArrayIndexOutOfBoundsException(); } ArrayList<T> list = new ArrayList<T>(); IndexNode current = colLinkedList.head; while (current!=null){ if (col==current.index){ ArrayNode<T> currentNode = current.head; while (currentNode!=null){ list.add(currentNode.data); currentNode = currentNode.nextRow; } current = current.next; } else{ current = current.next; } } return list ; } 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 List<T> getColumnFor(int col) throws ArrayIndexOutOfBoundsException { if (col>column || col<0){ throw new ArrayIndexOutOfBoundsException(); } ArrayList<T> list = new ArrayList<T>(); IndexNode current = colLinkedList.head; while (current!=null){ if (col==current.index){ ArrayNode<T> currentNode = current.head; while (currentNode!=null){ list.add(currentNode.data); currentNode = currentNode.nextRow; } current = current.next; } else{ current = current.next; } } return list ; } 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);  }