List of usage examples for org.jfree.data DefaultKeyedValues removeValue
public void removeValue(Comparable key)
From source file:org.jfree.data.DefaultKeyedValuesTest.java
/** * Another check for the getIndex(Comparable) method. *//* www.java 2 s.c o m*/ @Test public void testGetIndex2() { DefaultKeyedValues v = new DefaultKeyedValues(); assertEquals(-1, v.getIndex("K1")); v.addValue("K1", 1.0); assertEquals(0, v.getIndex("K1")); v.removeValue("K1"); assertEquals(-1, v.getIndex("K1")); }
From source file:org.jfree.data.junit.DefaultKeyedValuesTest.java
/** * Another check for the getIndex(Comparable) method. *//*w ww .ja v a2s . c om*/ public void testGetIndex2() { DefaultKeyedValues v = new DefaultKeyedValues(); assertEquals(-1, v.getIndex("K1")); v.addValue("K1", 1.0); assertEquals(0, v.getIndex("K1")); v.removeValue("K1"); assertEquals(-1, v.getIndex("K1")); }
From source file:org.jfree.data.DefaultKeyedValues2D.java
/** * Removes a column from the table.//from w w w . ja va2 s . c om * * @param columnKey the column key (<code>null</code> not permitted). * * @throws UnknownKeyException if the table does not contain a column with * the specified key. * @throws IllegalArgumentException if <code>columnKey</code> is * <code>null</code>. * * @see #removeColumn(int) * @see #removeRow(Comparable) */ public void removeColumn(Comparable columnKey) { if (columnKey == null) { throw new IllegalArgumentException("Null 'columnKey' argument."); } if (!this.columnKeys.contains(columnKey)) { throw new UnknownKeyException("Unknown key: " + columnKey); } Iterator iterator = this.rows.iterator(); while (iterator.hasNext()) { DefaultKeyedValues rowData = (DefaultKeyedValues) iterator.next(); int index = rowData.getIndex(columnKey); if (index >= 0) { rowData.removeValue(columnKey); } } this.columnKeys.remove(columnKey); }
From source file:org.jfree.data.DefaultKeyedValues2D.java
/** * Removes a column from the table./*from w w w . j a va2 s .co m*/ * * @param columnKey the column key (<code>null</code> not permitted). * * @throws UnknownKeyException if the table does not contain a column with * the specified key. * @throws IllegalArgumentException if <code>columnKey</code> is * <code>null</code>. * * @see #removeColumn(int) * @see #removeRow(Comparable) */ public void removeColumn(Comparable columnKey) { ParamChecks.nullNotPermitted(columnKey, "columnKey"); if (!this.columnKeys.contains(columnKey)) { throw new UnknownKeyException("Unknown key: " + columnKey); } Iterator iterator = this.rows.iterator(); while (iterator.hasNext()) { DefaultKeyedValues rowData = (DefaultKeyedValues) iterator.next(); int index = rowData.getIndex(columnKey); if (index >= 0) { rowData.removeValue(columnKey); } } this.columnKeys.remove(columnKey); }
From source file:org.jfree.data.DefaultKeyedValuesTest.java
/** * Some tests for the removeValue() method. *//*from w w w. jav a2 s .co m*/ @Test public void testRemoveValue() { DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("A", new Double(1.0)); data.addValue("B", null); data.addValue("C", new Double(3.0)); data.addValue("D", new Double(2.0)); assertEquals(1, data.getIndex("B")); data.removeValue("B"); assertEquals(-1, data.getIndex("B")); boolean pass = false; try { data.removeValue("XXX"); } catch (UnknownKeyException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.junit.DefaultKeyedValuesTest.java
/** * Some tests for the removeValue() method. *///from w ww.j av a 2 s . com public void testRemoveValue() { DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("A", new Double(1.0)); data.addValue("B", null); data.addValue("C", new Double(3.0)); data.addValue("D", new Double(2.0)); assertEquals(1, data.getIndex("B")); data.removeValue("B"); assertEquals(-1, data.getIndex("B")); boolean pass = false; try { data.removeValue("XXX"); } catch (UnknownKeyException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.DefaultKeyedValues2D.java
/** * Removes a value from the table by setting it to <code>null</code>. If * all the values 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 #addValue(Number, Comparable, Comparable) *//* w w w . jav a2 s . com*/ public void removeValue(Comparable rowKey, Comparable columnKey) { setValue(null, rowKey, columnKey); // 1. check whether the row is now empty. boolean allNull = true; int rowIndex = getRowIndex(rowKey); DefaultKeyedValues row = (DefaultKeyedValues) this.rows.get(rowIndex); for (int item = 0, itemCount = row.getItemCount(); item < itemCount; item++) { if (row.getValue(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; //int columnIndex = getColumnIndex(columnKey); for (int item = 0, itemCount = this.rows.size(); item < itemCount; item++) { row = (DefaultKeyedValues) this.rows.get(item); int columnIndex = row.getIndex(columnKey); if (columnIndex >= 0 && row.getValue(columnIndex) != null) { allNull = false; break; } } if (allNull) { for (int item = 0, itemCount = this.rows.size(); item < itemCount; item++) { row = (DefaultKeyedValues) this.rows.get(item); int columnIndex = row.getIndex(columnKey); if (columnIndex >= 0) { row.removeValue(columnIndex); } } this.columnKeys.remove(columnKey); } }