List of usage examples for org.jfree.data KeyedObjects removeValue
public void removeValue(Comparable key)
From source file:org.jfree.data.KeyedObjectsTest.java
/** * Some checks for the removeValue(int) method. *//*from ww w. j av a 2s.co m*/ @Test public void testRemoveValueInt() { KeyedObjects ko1 = new KeyedObjects(); ko1.setObject("Key 1", "Object 1"); ko1.setObject("Key 2", null); ko1.setObject("Key 3", "Object 2"); ko1.removeValue(1); assertEquals(2, ko1.getItemCount()); assertEquals(1, ko1.getIndex("Key 3")); // try negative key index boolean pass = false; try { ko1.removeValue(-1); } catch (IndexOutOfBoundsException e) { pass = true; } assertTrue(pass); // try key index == itemCount pass = false; try { ko1.removeValue(2); } catch (IndexOutOfBoundsException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.KeyedObjectsTest.java
/** * Some checks for the removeValue() methods. *///w w w. j a va2 s . c o m @Test public void testRemoveValue() { KeyedObjects ko1 = new KeyedObjects(); ko1.setObject("Key 1", "Object 1"); ko1.setObject("Key 2", null); ko1.setObject("Key 3", "Object 2"); ko1.removeValue(1); assertEquals(2, ko1.getItemCount()); assertEquals(1, ko1.getIndex("Key 3")); ko1.removeValue("Key 1"); assertEquals(1, ko1.getItemCount()); assertEquals(0, ko1.getIndex("Key 3")); // try unknown key boolean pass = false; try { ko1.removeValue("UNKNOWN"); } catch (UnknownKeyException e) { pass = true; } assertTrue(pass); // try null argument pass = false; try { ko1.removeValue(null); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.KeyedObjects2D.java
/** * Removes an entire column from the table. * * @param columnKey the column key (<code>null</code> not permitted). * * @throws UnknownKeyException if <code>rowKey</code> is not recognised. * * @see #removeRow(Comparable)// w w w. j a v a 2 s . c om */ public void removeColumn(Comparable columnKey) { int index = getColumnIndex(columnKey); if (index < 0) { throw new UnknownKeyException("Column key (" + columnKey + ") not recognised."); } Iterator iterator = this.rows.iterator(); while (iterator.hasNext()) { KeyedObjects rowData = (KeyedObjects) iterator.next(); int i = rowData.getIndex(columnKey); if (i >= 0) { rowData.removeValue(i); } } this.columnKeys.remove(columnKey); }
From source file:org.jfree.data.junit.KeyedObjectsTests.java
/** * Some checks for the removeValue(int) method. *//*w w w . j a v a 2s .c om*/ public void testRemoveValueInt() { KeyedObjects ko1 = new KeyedObjects(); ko1.setObject("Key 1", "Object 1"); ko1.setObject("Key 2", null); ko1.setObject("Key 3", "Object 2"); ko1.removeValue(1); assertEquals(2, ko1.getItemCount()); assertEquals(1, ko1.getIndex("Key 3")); // try negative key index boolean pass = false; try { ko1.removeValue(-1); } catch (IndexOutOfBoundsException e) { pass = true; } assertTrue(pass); // try key index == itemCount pass = false; try { ko1.removeValue(2); } catch (IndexOutOfBoundsException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.junit.KeyedObjectsTests.java
/** * Some checks for the removeValue() methods. */// w w w . j ava2 s .co m public void testRemoveValue() { KeyedObjects ko1 = new KeyedObjects(); ko1.setObject("Key 1", "Object 1"); ko1.setObject("Key 2", null); ko1.setObject("Key 3", "Object 2"); ko1.removeValue(1); assertEquals(2, ko1.getItemCount()); assertEquals(1, ko1.getIndex("Key 3")); ko1.removeValue("Key 1"); assertEquals(1, ko1.getItemCount()); assertEquals(0, ko1.getIndex("Key 3")); // try unknown key boolean pass = false; try { ko1.removeValue("UNKNOWN"); } catch (UnknownKeyException e) { pass = true; } assertTrue(pass); // try null argument pass = false; try { ko1.removeValue(null); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.KeyedObjects2D.java
/** * Removes an object from the table by setting it to <code>null</code>. If * all the objects in the specified row and/or column are now * <code>null</code>, the row and/or column is removed from the table. * * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @see #addObject(Object, Comparable, Comparable) *//*from ww w. j a va2s. c o m*/ public void removeObject(Comparable rowKey, Comparable columnKey) { int rowIndex = getRowIndex(rowKey); if (rowIndex < 0) { throw new UnknownKeyException("Row key (" + rowKey + ") not recognised."); } int columnIndex = getColumnIndex(columnKey); if (columnIndex < 0) { throw new UnknownKeyException("Column key (" + columnKey + ") not recognised."); } setObject(null, rowKey, columnKey); // 1. check whether the row is now empty. boolean allNull = true; KeyedObjects row = (KeyedObjects) this.rows.get(rowIndex); for (int item = 0, itemCount = row.getItemCount(); item < itemCount; item++) { if (row.getObject(item) != null) { allNull = false; break; } } if (allNull) { this.rowKeys.remove(rowIndex); this.rows.remove(rowIndex); } // 2. check whether the column is now empty. allNull = true; for (int item = 0, itemCount = this.rows.size(); item < itemCount; item++) { row = (KeyedObjects) this.rows.get(item); int colIndex = row.getIndex(columnKey); if (colIndex >= 0 && row.getObject(colIndex) != null) { allNull = false; break; } } if (allNull) { for (int item = 0, itemCount = this.rows.size(); item < itemCount; item++) { row = (KeyedObjects) this.rows.get(item); int colIndex = row.getIndex(columnKey); if (colIndex >= 0) { row.removeValue(colIndex); } } this.columnKeys.remove(columnKey); } }