/** * 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 index for a key, or -1 if the key is not recognised. * * @param key the key ({@code null} not permitted). * * @return The index, or {@code -1} if the key is unrecognised. * * @throws IllegalArgumentException if {@code key} is * {@code null}. */ @Override public int getIndex(Comparable key) { return this.data.getIndex(key); }
/** * Updates an existing value, or adds a new value to the collection. * * @param key the key (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). */ public void setValue(Comparable key, Number value) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } int keyIndex = getIndex(key); if (keyIndex >= 0) { this.keys.set(keyIndex, key); this.values.set(keyIndex, value); } else { this.keys.add(key); this.values.add(value); this.indexMap.put(key, new Integer(this.keys.size() - 1)); } }
/** * Updates an existing value, or adds a new value to the collection. * * @param key the key ({@code null} not permitted). * @param value the value ({@code null} permitted). */ public void setValue(Comparable key, Number value) { Args.nullNotPermitted(key, "key"); int keyIndex = getIndex(key); if (keyIndex >= 0) { this.keys.set(keyIndex, key); this.values.set(keyIndex, value); } else { this.keys.add(key); this.values.add(value); this.indexMap.put(key, new Integer(this.keys.size() - 1)); } }
/** * Returns the value for a given row and column. * * @param row the row index. * @param column the column index. * * @return The value. * * @see #getValue(Comparable, Comparable) */ @Override public Number getValue(int row, int column) { Number result = null; DefaultKeyedValues rowData = (DefaultKeyedValues) this.rows.get(row); if (rowData != null) { Comparable columnKey = (Comparable) this.columnKeys.get(column); // the row may not have an entry for this key, in which case the // return value is null int index = rowData.getIndex(columnKey); if (index >= 0) { result = rowData.getValue(index); } } return result; }
/** * Returns the value for a given row and column. * * @param row the row index. * @param column the column index. * * @return The value. * * @see #getValue(Comparable, Comparable) */ public Number getValue(int row, int column) { Number result = null; DefaultKeyedValues rowData = (DefaultKeyedValues) this.rows.get(row); if (rowData != null) { Comparable columnKey = (Comparable) this.columnKeys.get(column); // the row may not have an entry for this key, in which case the // return value is null int index = rowData.getIndex(columnKey); if (index >= 0) { result = rowData.getValue(index); } } return result; }
/** * Removes a column from the table. * * @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); }
throw new IllegalArgumentException("Null 'key' argument."); int pos = getIndex(key); if (pos == position) { this.keys.set(pos, key);
/** * Removes a column from the table. * * @param columnKey the column key ({@code null} not permitted). * * @throws UnknownKeyException if the table does not contain a column with * the specified key. * @throws IllegalArgumentException if {@code columnKey} is * {@code null}. * * @see #removeColumn(int) * @see #removeRow(Comparable) */ public void removeColumn(Comparable columnKey) { Args.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); }
int pos = getIndex(key); if (pos == position) { this.keys.set(pos, key);
/** * 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); }
/** * Removes a value from the collection. * * @param key the item key (<code>null</code> not permitted). * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. * @throws UnknownKeyException if <code>key</code> 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); }
/** * 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); }
/** * Returns the value for a given key. * * @param key the key ({@code null} not permitted). * * @return The value (possibly {@code null}). * * @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); }
item++) { row = (DefaultKeyedValues) this.rows.get(item); int columnIndex = row.getIndex(columnKey); if (columnIndex >= 0 && row.getValue(columnIndex) != null) { allNull = false; item++) { row = (DefaultKeyedValues) this.rows.get(item); int columnIndex = row.getIndex(columnKey); if (columnIndex >= 0) { row.removeValue(columnIndex);
item++) { row = (DefaultKeyedValues) this.rows.get(item); int columnIndex = row.getIndex(columnKey); if (columnIndex >= 0 && row.getValue(columnIndex) != null) { allNull = false; item++) { row = (DefaultKeyedValues) this.rows.get(item); int columnIndex = row.getIndex(columnKey); if (columnIndex >= 0) { row.removeValue(columnIndex);
DefaultKeyedValues rowData = (DefaultKeyedValues) this.rows.get(row); int col = rowData.getIndex(columnKey); return (col >= 0 ? rowData.getValue(col) : null);
DefaultKeyedValues rowData = (DefaultKeyedValues) this.rows.get(row); int col = rowData.getIndex(columnKey); return (col >= 0 ? rowData.getValue(col) : null);