/** * Adds a value to a field. * * @param field identifier of field * @param attributes field properties * @param value field to update * @param force if <code>true</code> create the value * @throws FieldFullException if no more values can be added to the field */ private void addValue(int field, int attributes, Object value, boolean force) { checkType(field, value); PIMField pimField = getField(field, true, true); int maxValues = pimHandler.getMaximumValues(pimListHandle, field); int currentValues = pimField.getValueCount(); if (maxValues != -1 && currentValues >= maxValues) { throw new FieldFullException("Can only store " + maxValues + " in field", field); } if (!force) { checkReadOnlyFields(field); } if (value instanceof Integer) { checkIntValue(field, ((Integer) value).intValue()); } if (pimField.isScalar()) { // upgrade PIM field if (currentValues == 0) { pimField = new ScalarPIMField(); putField(field, pimField); } else { Object value0 = pimField.getValue(0); int attributes0 = pimField.getAttributes(0); pimField = new VectorPIMField(); pimField.addValue(attributes0, value0); putField(field, pimField); } } attributes = filterAttributes(field, attributes); pimField.addValue(attributes, value); modified = true; }
// JAVADOC COMMENT ELIDED public void removeValue(int field, int index) { PIMField pimField = getField(field, false, true); if (pimField == null) { throw new IndexOutOfBoundsException("Empty field: " + field); } int currentValues = pimField.getValueCount(); if (index < 0 || index >= currentValues) { throw new IndexOutOfBoundsException( "0 <= index < " + currentValues + ", " + index + " not in range"); } checkReadOnlyFields(field); pimField.removeValue(index); currentValues--; if (currentValues == 0) { removeField(field); } else if (currentValues == 1) { // downgrade field Object value = pimField.getValue(0); int attributes = pimField.getAttributes(0); pimField = new ScalarPIMField(); pimField.addValue(attributes, value); putField(field, pimField); } modified = true; }