List of usage examples for org.jfree.data UnknownKeyException UnknownKeyException
public UnknownKeyException(String message)
From source file:org.jfree.data.KeyedObjects.java
/** * Returns the object for a given key. If the key is not recognised, the * method should return <code>null</code>. * * @param key the key./*from w w w. j ava2 s . c o m*/ * * @return The object (possibly <code>null</code>). * * @see #addObject(Comparable, Object) */ public Object getObject(Comparable key) { int index = getIndex(key); if (index < 0) { throw new UnknownKeyException("The key (" + key + ") is not recognised."); } return getObject(index); }
From source file:org.jfree.data.DefaultKeyedValues.java
/** * Returns the value for a given key./* w w w .ja v a 2 s.c om*/ * * @param key the key (<code>null</code> not permitted). * * @return The value (possibly <code>null</code>). * * @throws UnknownKeyException if the key is not recognised. * * @see #getValue(int) */ @Override public Number getValue(Comparable key) { int index = getIndex(key); if (index < 0) { throw new UnknownKeyException("Key not found: " + key); } return getValue(index); }
From source file:org.jfree.data.KeyedObjects2D.java
/** * Returns the object for the given row and column keys. * * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @return The object (possibly <code>null</code>). * * @throws IllegalArgumentException if <code>rowKey</code> or * <code>columnKey</code> is <code>null</code>. * @throws UnknownKeyException if <code>rowKey</code> or * <code>columnKey</code> is not recognised. *///w w w. jav a2s. com public Object getObject(Comparable rowKey, Comparable columnKey) { ParamChecks.nullNotPermitted(rowKey, "rowKey"); ParamChecks.nullNotPermitted(columnKey, "columnKey"); int row = this.rowKeys.indexOf(rowKey); if (row < 0) { throw new UnknownKeyException("Row key (" + rowKey + ") not recognised."); } int column = this.columnKeys.indexOf(columnKey); if (column < 0) { throw new UnknownKeyException("Column key (" + columnKey + ") not recognised."); } KeyedObjects rowData = (KeyedObjects) this.rows.get(row); int index = rowData.getIndex(columnKey); if (index >= 0) { return rowData.getObject(index); } else { return null; } }
From source file:org.jfree.data.KeyedObjects.java
/** * Removes a value from the collection./*from w ww . jav a 2 s. c o m*/ * * @param key the key (<code>null</code> not permitted). * * @see #removeValue(int) * * @throws UnknownKeyException if the key is not recognised. */ public void removeValue(Comparable key) { // defer argument checking int index = getIndex(key); if (index < 0) { throw new UnknownKeyException("The key (" + key.toString() + ") is not recognised."); } removeValue(index); }
From source file:org.jfree.data.category.SlidingCategoryDataset.java
/** * Returns the value for a pair of keys. * * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @return The value (possibly <code>null</code>). * * @throws UnknownKeyException if either key is not defined in the dataset. *//*from w w w .j a va 2 s .c o m*/ @Override public Number getValue(Comparable rowKey, Comparable columnKey) { int r = getRowIndex(rowKey); int c = getColumnIndex(columnKey); if (c != -1) { return this.underlying.getValue(r, c + this.firstCategoryIndex); } else { throw new UnknownKeyException("Unknown columnKey: " + columnKey); } }
From source file:org.jfree.data.DefaultKeyedValues2D.java
/** * Returns the value for the given row and column keys. This method will * throw an {@link UnknownKeyException} if either key is not defined in the * data structure.//from ww w. ja v a 2 s.co m * * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @return The value (possibly <code>null</code>). * * @see #addValue(Number, Comparable, Comparable) * @see #removeValue(Comparable, Comparable) */ public Number getValue(Comparable rowKey, Comparable columnKey) { if (rowKey == null) { throw new IllegalArgumentException("Null 'rowKey' argument."); } if (columnKey == null) { throw new IllegalArgumentException("Null 'columnKey' argument."); } // check that the column key is defined in the 2D structure if (!(this.columnKeys.contains(columnKey))) { throw new UnknownKeyException("Unrecognised columnKey: " + columnKey); } // now fetch the row data - need to bear in mind that the row // structure may not have an entry for the column key, but that we // have already checked that the key is valid for the 2D structure int row = getRowIndex(rowKey); if (row >= 0) { DefaultKeyedValues rowData = (DefaultKeyedValues) this.rows.get(row); int col = rowData.getIndex(columnKey); return (col >= 0 ? rowData.getValue(col) : null); } else { throw new UnknownKeyException("Unrecognised rowKey: " + rowKey); } }
From source file:org.jfree.data.DefaultKeyedValues2D.java
/** * Returns the value for the given row and column keys. This method will * throw an {@link UnknownKeyException} if either key is not defined in the * data structure./* ww w .jav a2 s .c o m*/ * * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @return The value (possibly <code>null</code>). * * @see #addValue(Number, Comparable, Comparable) * @see #removeValue(Comparable, Comparable) */ @Override public Number getValue(Comparable rowKey, Comparable columnKey) { ParamChecks.nullNotPermitted(rowKey, "rowKey"); ParamChecks.nullNotPermitted(columnKey, "columnKey"); // check that the column key is defined in the 2D structure if (!(this.columnKeys.contains(columnKey))) { throw new UnknownKeyException("Unrecognised columnKey: " + columnKey); } // now fetch the row data - need to bear in mind that the row // structure may not have an entry for the column key, but that we // have already checked that the key is valid for the 2D structure int row = getRowIndex(rowKey); if (row >= 0) { DefaultKeyedValues rowData = (DefaultKeyedValues) this.rows.get(row); int col = rowData.getIndex(columnKey); return (col >= 0 ? rowData.getValue(col) : null); } else { throw new UnknownKeyException("Unrecognised rowKey: " + rowKey); } }
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) *///w ww .ja v a 2s . 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); } }
From source file:org.jfree.data.gantt.SlidingGanttCategoryDataset.java
/** * Returns the percent complete for a given item. * * @param rowKey the row key.// ww w. j a va 2 s . com * @param columnKey the column key. * * @return The percent complete. */ @Override public Number getPercentComplete(Comparable rowKey, Comparable columnKey) { int r = getRowIndex(rowKey); int c = getColumnIndex(columnKey); if (c != -1) { return this.underlying.getPercentComplete(r, c + this.firstCategoryIndex); } else { throw new UnknownKeyException("Unknown columnKey: " + columnKey); } }
From source file:org.jfree.data.xy.XYSeriesCollection.java
/** * Returns a series from the collection. * * @param key the key (<code>null</code> not permitted). * * @return The series with the specified key. * * @throws UnknownKeyException if <code>key</code> is not found in the * collection./*from w w w. j a va2 s .c o m*/ * * @since 1.0.9 */ public XYSeries getSeries(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); Iterator iterator = this.data.iterator(); while (iterator.hasNext()) { XYSeries series = (XYSeries) iterator.next(); if (key.equals(series.getKey())) { return series; } } throw new UnknownKeyException("Key not found: " + key); }