/** * Creates a new item handler. * * @param root the root handler. */ public CategorySeriesHandler(RootHandler root) { this.root = root; this.values = new DefaultKeyedValues(); }
/** * Adds an item to the temporary storage for the series. * * @param key the key. * @param value the value. */ public void addItem(Comparable key, Number value) { this.values.addValue(key, value); }
/** * Adds a new value to the collection, or updates an existing value. * This method passes control directly to the * {@link #setValue(Comparable, Number)} method. * * @param key the key ({@code null} not permitted). * @param value the value ({@code null} permitted). */ public void addValue(Comparable key, Number value) { setValue(key, value); }
/** * Returns the value for a given key. * * @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) */ public Number getValue(Comparable key) { int index = getIndex(key); if (index < 0) { throw new UnknownKeyException("Key not found: " + key); } return getValue(index); }
/** * Removes a value from the collection. * * @param key the item key ({@code null} not permitted). * * @throws IllegalArgumentException if {@code key} is * {@code null}. * @throws UnknownKeyException if {@code key} is not recognised. */ public void removeValue(Comparable key) { int index = getIndex(key); if (index < 0) { throw new UnknownKeyException("The key (" + key + ") is not recognised."); } removeValue(index); }
/** * Creates a new dataset by copying data from a {@link KeyedValues} * instance. * * @param data the data (<code>null</code> not permitted). */ public DefaultPieDataset(KeyedValues data) { if (data == null) { throw new IllegalArgumentException("Null 'data' argument."); } this.data = new DefaultKeyedValues(); for (int i = 0; i < data.getItemCount(); i++) { this.data.addValue(data.getKey(i), data.getValue(i)); } }
row = new DefaultKeyedValues(); if (this.sortRowKeys) { rowIndex = -rowIndex - 1; row.setValue(columnKey, value);
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; item++) { row = (DefaultKeyedValues) this.rows.get(item); int columnIndex = row.getIndex(columnKey); if (columnIndex >= 0 && row.getValue(columnIndex) != null) { allNull = false; break; item++) { row = (DefaultKeyedValues) this.rows.get(item); int columnIndex = row.getIndex(columnKey); if (columnIndex >= 0) { row.removeValue(columnIndex);
/** * Sorts the items in the list by key. * * @param order the sort order ({@code null} not permitted). */ public void sortByKeys(SortOrder order) { final int size = this.keys.size(); final DefaultKeyedValue[] data = new DefaultKeyedValue[size]; for (int i = 0; i < size; i++) { data[i] = new DefaultKeyedValue((Comparable) this.keys.get(i), (Number) this.values.get(i)); } Comparator comparator = new KeyedValueComparator( KeyedValueComparatorType.BY_KEY, order); Arrays.sort(data, comparator); clear(); for (int i = 0; i < data.length; i++) { final DefaultKeyedValue value = data[i]; addValue(value.getKey(), value.getValue()); } }
if (position < 0 || position > getItemCount()) { throw new IllegalArgumentException("'position' out of bounds."); throw new IllegalArgumentException("Null 'key' argument."); int pos = getIndex(key); if (pos == position) { this.keys.set(pos, key); rebuildIndex();
int count = getItemCount(); if (count != that.getItemCount()) { return false; Comparable k1 = getKey(i); Comparable k2 = that.getKey(i); if (!k1.equals(k2)) { return false; Number v1 = getValue(i); Number v2 = that.getValue(i); if (v1 == null) {
/** * The end of an element. * * @param namespaceURI the namespace. * @param localName the element name. * @param qName the element name. */ @Override public void endElement(String namespaceURI, String localName, String qName) { if (this.root instanceof CategoryDatasetHandler) { CategoryDatasetHandler handler = (CategoryDatasetHandler) this.root; Iterator iterator = this.values.getKeys().iterator(); while (iterator.hasNext()) { Comparable key = (Comparable) iterator.next(); Number value = this.values.getValue(key); handler.addItem(this.seriesKey, key, value); } this.root.popSubHandler(); } }
/** * Returns the index for a key, or -1 if the key is not recognised. * * @param key the key (<code>null</code> not permitted). * * @return The index, or <code>-1</code> if the key is unrecognised. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. */ public int getIndex(Comparable key) { return this.data.getIndex(key); }
/** * Returns the data value associated with a key. * * @param key the key (<code>null</code> not permitted). * * @return The value (possibly <code>null</code>). * * @throws UnknownKeyException if the key is not recognised. */ public Number getValue(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } return this.data.getValue(key); }
/** * Returns the number of items in the dataset. * * @return The item count. */ @Override public int getItemCount() { return this.data.getItemCount(); }
/** * Returns the categories in the dataset. The returned list is * unmodifiable. * * @return The categories in the dataset. */ public List getKeys() { return Collections.unmodifiableList(this.data.getKeys()); }
/** * Clears all data from this dataset and sends a {@link DatasetChangeEvent} * to all registered listeners (unless the dataset was already empty). * * @since 1.0.2 */ public void clear() { if (getItemCount() > 0) { this.data.clear(); fireDatasetChanged(); } }
/** * Returns a clone of the dataset. * * @return A clone. * * @throws CloneNotSupportedException This class will not throw this * exception, but subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { DefaultPieDataset clone = (DefaultPieDataset) super.clone(); clone.data = (DefaultKeyedValues) this.data.clone(); return clone; }
/** * Returns the key for the specified item, or <code>null</code>. * * @param item the item index (in the range <code>0</code> to * <code>getItemCount() - 1</code>). * * @return The key, or <code>null</code>. * * @throws IndexOutOfBoundsException if <code>item</code> is not in the * specified range. */ public Comparable getKey(int item) { return this.data.getKey(item); }
/** * Creates a new dataset by copying data from a {@link KeyedValues} * instance. * * @param data the data ({@code null} not permitted). */ public DefaultPieDataset(KeyedValues data) { Args.nullNotPermitted(data, "data"); this.data = new DefaultKeyedValues(); for (int i = 0; i < data.getItemCount(); i++) { this.data.addValue(data.getKey(i), data.getValue(i)); } }