use of org.apache.sis.util.collection.DefaultTreeTable in project sis by apache.
the class TreeNodeChildrenTest method testAdd.
/**
* Tests the {@link TreeNodeChildren#add(TreeTable.Node)} method.
*/
@Test
@DependsOnMethod("testReadOnlyWithMultiOccurrences")
public void testAdd() {
final DefaultCitation citation = metadataWithMultiOccurrences();
final TreeNodeChildren children = create(citation, ValueExistencePolicy.NON_EMPTY);
assertEquals("titleProperty", -1, children.titleProperty);
final DefaultTreeTable.Node toAdd = new DefaultTreeTable.Node(new DefaultTreeTable(TableColumn.IDENTIFIER, TableColumn.VALUE));
final String[] expected = { "Some title", "First alternate title", "Second alternate title", // After addition
"Third alternate title", // After "addition" (actually change).
"New edition", // After addition
"PresentationForm[IMAGE_DIGITAL]", "PresentationForm[MAP_DIGITAL]", "PresentationForm[MAP_HARDCOPY]", "Some other details" };
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(e.getMessage().contains("edition"));
}
// Clears so we are allowed to add.
citation.setEdition(null);
assertTrue("Setting a new value shall be a change.", children.add(toAdd));
toAdd.setValue(TableColumn.IDENTIFIER, "presentationForm");
toAdd.setValue(TableColumn.VALUE, PresentationForm.MAP_DIGITAL);
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));
toAdd.setValue(TableColumn.IDENTIFIER, "alternateTitle");
toAdd.setValue(TableColumn.VALUE, "Third alternate title");
assertTrue("Adding a new value shall be a change.", children.add(toAdd));
assertEquals("size()", expected.length, children.size());
assertAllNextEqual(expected, children.iterator());
}
use of org.apache.sis.util.collection.DefaultTreeTable in project sis by apache.
the class AbstractLocationType method toString.
/**
* Returns a string representation of this location type and all its children.
* Current implementation formats a tree with the {@linkplain ModifiableLocationType#getName() name}
* and {@linkplain ModifiableLocationType#getDefinition() definition} of each type, like below:
*
* {@preformat text
* administrative area………………… area of responsibility of highest level local authority
* ├─town……………………………………………… city or town
* │ └─street……………………………… thoroughfare providing access to properties
* └─street………………………………………… thoroughfare providing access to properties
* }
*
* The string representation is mostly for debugging purpose and may change in any future SIS version.
*
* @return a string representation of this location type.
*/
@Override
public String toString() {
final DefaultTreeTable table = new DefaultTreeTable(TableColumn.NAME, TableColumn.VALUE_AS_TEXT);
format(this, table.getRoot());
return table.toString();
}
use of org.apache.sis.util.collection.DefaultTreeTable in project sis by apache.
the class StorageConnector method toString.
/**
* Returns a string representation of this {@code StorageConnector} for debugging purpose.
* This string representation is for debugging purpose only and may change in any future version.
*
* @return a string representation of this {@code StorageConnector} for debugging purpose.
*/
@Debug
@Override
public String toString() {
final TreeTable table = new DefaultTreeTable(TableColumn.NAME, TableColumn.VALUE);
final TreeTable.Node root = table.getRoot();
root.setValue(TableColumn.NAME, Classes.getShortClassName(this));
root.setValue(TableColumn.VALUE, getStorageName());
if (options != null) {
final TreeTable.Node op = root.newChild();
op.setValue(TableColumn.NAME, "options");
op.setValue(TableColumn.VALUE, options);
}
final Coupled c = getView(null);
if (c != null) {
c.append(root.newChild(), views);
}
return table.toString();
}
Aggregations