/** * Adds the given node to this list. This method fetches the object from {@link TableColumn#VALUE} * and assigns it to the property identified by {@link TableColumn#IDENTIFIER}. All other columns * are ignored. * * <p>If the identified property is a collection, then this method adds the value to that collection. * Otherwise the new value will be set only if the previous value is null, * {@linkplain org.apache.sis.xml.NilObject nil} or empty.</p> * * <p>This method does not iterate explicitly through the children list, because adding a metadata * object implicitly adds all its children.</p> * * @param node the node from which to get the values. * @return {@code true} if the metadata changed as a result of this method call. * @throws NullPointerException if the given node is null. * @throws IllegalArgumentException if this list does not have a property for the node identifier. * @throws IllegalStateException if a value already exists and no more value can be added for the node identifier. * @throws UnmodifiableMetadataException if the property for the node identifier is read-only. * @throws ClassCastException if the node value can not be converted to the expected type. * @throws BackingStoreException if the metadata implementation threw a checked exception. */ @Override public boolean add(final TreeTable.Node node) throws IllegalStateException { final String identifier = node.getValue(TableColumn.IDENTIFIER); if (identifier == null) { throw new IllegalArgumentException(Errors.format( Errors.Keys.MissingValueInColumn_1, TableColumn.IDENTIFIER.getHeader())); } return add(accessor.indexOf(identifier, true), node.getValue(TableColumn.VALUE)); }
/** * Adds the given node to this list. This method fetches the object from {@link TableColumn#VALUE} * and assigns it to the property identified by {@link TableColumn#IDENTIFIER}. All other columns * are ignored. * * <p>If the identified property is a collection, then this method adds the value to that collection. * Otherwise the new value will be set only if the previous value is null, * {@linkplain org.apache.sis.xml.NilObject nil} or empty.</p> * * <p>This method does not iterate explicitly through the children list, because adding a metadata * object implicitly adds all its children.</p> * * @param node the node from which to get the values. * @return {@code true} if the metadata changed as a result of this method call. * @throws NullPointerException if the given node is null. * @throws IllegalArgumentException if this list does not have a property for the node identifier. * @throws IllegalStateException if a value already exists and no more value can be added for the node identifier. * @throws UnmodifiableMetadataException if the property for the node identifier is read-only. * @throws ClassCastException if the node value can not be converted to the expected type. * @throws BackingStoreException if the metadata implementation threw a checked exception. */ @Override public boolean add(final TreeTable.Node node) throws IllegalStateException { final String identifier = node.getValue(TableColumn.IDENTIFIER); if (identifier == null) { throw new IllegalArgumentException(Errors.format( Errors.Keys.MissingValueInColumn_1, TableColumn.IDENTIFIER.getHeader())); } return add(accessor.indexOf(identifier, true), node.getValue(TableColumn.VALUE)); }
indexInList = -1; if (!siblings.add(indexInData, value)) { throw new IllegalArgumentException(Errors.format(Errors.Keys.ElementAlreadyPresent_1, value));
indexInList = -1; if (!siblings.add(indexInData, value)) { throw new IllegalArgumentException(Errors.format(Errors.Keys.ElementAlreadyPresent_1, value));
toAdd.setValue(TableColumn.IDENTIFIER, "edition"); toAdd.setValue(TableColumn.VALUE, citation.getEdition()); assertFalse("Adding the same value shall be a no-op.", children.add(toAdd)); toAdd.setValue(TableColumn.VALUE, "New edition"); try { children.add(toAdd); fail("Setting a different value shall be refused."); } catch (IllegalStateException e) { assertTrue("Setting a new value shall be a change.", children.add(toAdd)); assertFalse("Adding the same value shall be a no-op.", children.add(toAdd)); toAdd.setValue(TableColumn.VALUE, PresentationForm.IMAGE_DIGITAL); assertTrue("Adding a new value shall be a change.", children.add(toAdd)); assertTrue("Adding a new value shall be a change.", children.add(toAdd));