Search in sources :

Example 1 with DefaultTreeTable

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());
}
Also used : DefaultTreeTable(org.apache.sis.util.collection.DefaultTreeTable) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 2 with DefaultTreeTable

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();
}
Also used : DefaultTreeTable(org.apache.sis.util.collection.DefaultTreeTable)

Example 3 with DefaultTreeTable

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();
}
Also used : DefaultTreeTable(org.apache.sis.util.collection.DefaultTreeTable) TreeTable(org.apache.sis.util.collection.TreeTable) DefaultTreeTable(org.apache.sis.util.collection.DefaultTreeTable) Debug(org.apache.sis.util.Debug)

Aggregations

DefaultTreeTable (org.apache.sis.util.collection.DefaultTreeTable)3 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)1 DependsOnMethod (org.apache.sis.test.DependsOnMethod)1 Debug (org.apache.sis.util.Debug)1 TreeTable (org.apache.sis.util.collection.TreeTable)1 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)1 Test (org.junit.Test)1