/** * Appends a single line as a node in the current section. */ private void writeNode(final CharSequence line) { String text = line.toString().trim(); if (!text.isEmpty()) { section.newChild().setValue(TableColumn.VALUE_AS_TEXT, text); } }
/** * Starts a new section for the given property. * * @param property one of {@link #EXTENT}, {@link #ENVELOPE}, {@link #CRS}, {@link #GRID_TO_CRS} and {@link #RESOLUTION}. * @param title the {@link Vocabulary} key for the title to show for this section, if formatted. * @param cellCenter whether to add a "origin in cell center" text in the title. This is relevant only for conversion. * @param value the value to be formatted in that section. * @return {@code true} if the caller shall format the value. */ private boolean section(final int property, final short title, final Object value, final boolean cellCenter) { if ((bitmask & property) != 0) { CharSequence text = vocabulary.getString(title); if (cellCenter) { text = buffer.append(text).append(" (") .append(vocabulary.getString(Vocabulary.Keys.OriginInCellCenter).toLowerCase(locale)) .append(')').toString(); buffer.setLength(0); } section = root.newChild(); section.setValue(TableColumn.VALUE_AS_TEXT, text); if (value != null) { return true; } writeNode(vocabulary.getString(Vocabulary.Keys.Unspecified)); } return false; }
/** * Finds the node for the given file, or creates a new node if none exists. * This method performs the same work than the above variant, but working on * {@code File} instances rather than {@code Path}. * * @param from the root node from which to start the search. * @param column the column containing the file name. * @param path the file for which to find or create a node. * @return the node for the given file, either as an existing node or a new node. */ public static TreeTable.Node nodeForPath(TreeTable.Node from, final TableColumn<? super String> column, final File path) { final File parent = path.getParentFile(); if (parent != null) { from = nodeForPath(from, column, parent); } String name = path.getName(); if (name.isEmpty() && parent == null) { name = File.separator; // Root directory in Unix path syntax. } for (final TreeTable.Node child : from.getChildren()) { if (name.equals(child.getValue(column))) { return child; } } from = from.newChild(); from.setValue(column, name); return from; }
TreeTable.Node section = root.newChild(); section.setValue(column, "Target range"); final StringBuilder buffer = new StringBuilder(256); String text = line.toString().trim(); if (!text.isEmpty()) { section.newChild().setValue(column, text); buffer.append(s); section = root.newChild(); section.setValue(column, "Target strides"); section.newChild().setValue(column, buffer.append('}').toString()); buffer.setLength(0); section.newChild().setValue(column, buffer.append("Global ≈ ").append((float) getGlobalScale()).toString()); return tree;
pkTableName); fkNode = getOrCreateNode(ttable.getRoot(), pkTable, tablePath).newChild(); fkNode.setValue(pkColumn, foreignKeys.getString(4)); fkNode.setValue(fkColumn, foreignKeys.getString(8));
/** * Finds the node for the given file, or creates a new node if none exists. * This method performs the same work than the above variant, but working on * {@code File} instances rather than {@code Path}. * * @param from the root node from which to start the search. * @param column the column containing the file name. * @param path the file for which to find or create a node. * @return the node for the given file, either as an existing node or a new node. */ public static TreeTable.Node nodeForPath(TreeTable.Node from, final TableColumn<? super String> column, final File path) { final File parent = path.getParentFile(); if (parent != null) { from = nodeForPath(from, column, parent); } String name = path.getName(); if (name.isEmpty() && parent == null) { name = File.separator; // Root directory in Unix path syntax. } for (final TreeTable.Node child : from.getChildren()) { if (name.equals(child.getValue(column))) { return child; } } from = from.newChild(); from.setValue(column, name); return from; }
/** * Returns a tree representation of some elements of this grid coverage. * The tree representation is for debugging purpose only and may change * in any future SIS version. * * @param locale the locale to use for textual labels. * @param bitmask combination of {@link GridGeometry} flags. * @return a tree representation of the specified elements. * * @see GridGeometry#toTree(Locale, int) */ @Debug public TreeTable toTree(final Locale locale, final int bitmask) { ArgumentChecks.ensureNonNull("locale", locale); final Vocabulary vocabulary = Vocabulary.getResources(locale); final TableColumn<CharSequence> column = TableColumn.VALUE_AS_TEXT; final TreeTable tree = new DefaultTreeTable(column); final TreeTable.Node root = tree.getRoot(); root.setValue(column, Classes.getShortClassName(this)); TreeTable.Node branch = root.newChild(); branch.setValue(column, vocabulary.getString(Vocabulary.Keys.CoverageDomain)); gridGeometry.formatTo(locale, vocabulary, bitmask, branch); branch = root.newChild(); branch.setValue(column, vocabulary.getString(Vocabulary.Keys.SampleDimensions)); branch.newChild().setValue(column, SampleDimension.toString(locale, sampleDimensions)); return tree; } }
/** * Tests the {@link TreeTables#replaceCharSequences(TreeTable, Locale)} method. */ @Test public void testReplaceCharSequences() { final TreeTable table = new DefaultTreeTable(NAME, VALUE_AS_NUMBER); final TreeTable.Node root = table .getRoot(); final TreeTable.Node parent = root .newChild(); final TreeTable.Node child1 = parent.newChild(); final TreeTable.Node child2 = root .newChild(); root .setValue(NAME, new StringBuilder("Root")); parent.setValue(NAME, "A parent"); child1.setValue(NAME, new StringBuilder("A child")); child2.setValue(NAME, new SimpleInternationalString("A child")); root .setValue(VALUE_AS_NUMBER, 8); parent.setValue(VALUE_AS_NUMBER, 4); final String asString = table.toString(); assertEquals(3, replaceCharSequences(table, null)); assertInstanceOf("replaceCharSequences:", String.class, root .getValue(NAME)); assertInstanceOf("replaceCharSequences:", String.class, parent.getValue(NAME)); assertInstanceOf("replaceCharSequences:", String.class, child1.getValue(NAME)); assertInstanceOf("replaceCharSequences:", String.class, child2.getValue(NAME)); assertSame("Expected unique instance of String.", child1.getValue(NAME), child2.getValue(NAME)); assertEquals("String representation shall be the same.", asString, table.toString()); } }
/** * Formats the current {@code Coupled} and all its children as a tree in the given tree table node. * This method is used for {@link StorageConnector#toString()} implementation only and may change * in any future version. * * @param appendTo where to write name, value and children. * @param views reference to the {@link StorageConnector#views} map. Will be read only. */ @Debug final void append(final TreeTable.Node appendTo, final Map<Class<?>, Coupled> views) { Class<?> type = null; for (final Map.Entry<Class<?>, Coupled> entry : views.entrySet()) { if (entry.getValue() == this) { final Class<?> t = Classes.findCommonClass(type, entry.getKey()); if (t != Object.class) type = t; } } appendTo.setValue(TableColumn.NAME, Classes.getShortName(type)); appendTo.setValue(TableColumn.VALUE, Classes.getShortClassName(view)); if (wrappedBy != null) { for (final Coupled c : wrappedBy) { c.append(appendTo.newChild(), views); } } } }
/** * Formats the current {@code Coupled} and all its children as a tree in the given tree table node. * This method is used for {@link StorageConnector#toString()} implementation only and may change * in any future version. * * @param appendTo where to write name, value and children. * @param views reference to the {@link StorageConnector#views} map. Will be read only. */ @Debug final void append(final TreeTable.Node appendTo, final Map<Class<?>, Coupled> views) { Class<?> type = null; for (final Map.Entry<Class<?>, Coupled> entry : views.entrySet()) { if (entry.getValue() == this) { final Class<?> t = Classes.findCommonClass(type, entry.getKey()); if (t != Object.class) type = t; } } appendTo.setValue(TableColumn.NAME, Classes.getShortName(type)); appendTo.setValue(TableColumn.VALUE, Classes.getShortClassName(view)); if (wrappedBy != null) { for (final Coupled c : wrappedBy) { c.append(appendTo.newChild(), views); } } } }
/** * 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(); } }
/** * 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. */ @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(); } }
/** * Search in given tree node direct children for a node with a table column equals to some specific value. * If we cannot find any matching, we add a new child into input node, initiated with the wanted value. * @param <T> Table column value type. * @param parent Node to search into (only direct children) * @param searchCriteria The table column to search in. * @param searchValue Searched value. * @return A matching node, created if necessary. */ public static <T> TreeTable.Node getOrCreateNode(final TreeTable.Node parent, final TableColumn<T> searchCriteria, final T searchValue) { for (final TreeTable.Node n : parent.getChildren()) { if (searchValue.equals(n.getValue(searchCriteria))) { return n; } } final TreeTable.Node newChild = parent.newChild(); newChild.setValue(searchCriteria, searchValue); return newChild; } }
/** * Creates a node for the given converter and adds it to the given tree. * This method invokes itself recursively for scanning through fallbacks. * * @param converter the converter for which to create a tree. * @param addTo the node in which to add the converter. */ private void toTree(final ObjectConverter<?,?> converter, TreeTable.Node addTo) { if (converter instanceof FallbackConverter<?,?>) { final boolean isNew = converter.getTargetClass() != targetClass; if (isNew) { addTo = addTo.newChild(); } ((FallbackConverter<?,?>) converter).toTree(addTo, isNew); } else { Column.toTree(converter, addTo); } }
/** * Creates a node for the given converter and adds it to the given tree. * This method invokes itself recursively for scanning through fallbacks. * * @param converter the converter for which to create a tree. * @param addTo the node in which to add the converter. */ private void toTree(final ObjectConverter<?,?> converter, TreeTable.Node addTo) { if (converter instanceof FallbackConverter<?,?>) { final boolean isNew = converter.getTargetClass() != targetClass; if (isNew) { addTo = addTo.newChild(); } ((FallbackConverter<?,?>) converter).toTree(addTo, isNew); } else { Column.toTree(converter, addTo); } }
/** * Invoked recursively for formatting the given type in the given tree. * This method does not perform any check against infinite recursivity * on the assumption that subclasses verified this constraint by calls * to {@link #checkForCycles()}. */ private static void format(final AbstractLocationType type, final TreeTable.Node node) { node.setValue(TableColumn.NAME, type.getName()); node.setValue(TableColumn.VALUE_AS_TEXT, type.getDefinition()); for (final AbstractLocationType child : type.getChildren()) { format(child, node.newChild()); } } }
/** * Adds a child of the given name to the given parent node. * This is a convenience method for {@code toString()} implementations. * * @param parent the node where to add a child. * @param name the name to assign to the child. * @return the child added to the parent. */ @Debug static TreeTable.Node newChild(final TreeTable.Node parent, final String name) { final TreeTable.Node child = parent.newChild(); child.setValue(TableColumn.NAME, name); return child; }
/** * Creates a node for the given converter and adds it to the given tree. * Used by {@link FallbackConverter} and {@link ConverterRegistry} for * implementing their {@code toString()} method. * * @param converter the converter for which to create a tree. * @param addTo the node in which to add the converter. */ static void toTree(final ObjectConverter<?,?> converter, final TreeTable.Node addTo) { final TreeTable.Node node = addTo.newChild(); node.setValue(SOURCE, converter.getSourceClass()); node.setValue(TARGET, converter.getTargetClass()); }
/** * Creates a node for the given converter and adds it to the given tree. * Used by {@link FallbackConverter} and {@link ConverterRegistry} for * implementing their {@code toString()} method. * * @param converter the converter for which to create a tree. * @param addTo the node in which to add the converter. */ static void toTree(final ObjectConverter<?,?> converter, final TreeTable.Node addTo) { final TreeTable.Node node = addTo.newChild(); node.setValue(SOURCE, converter.getSourceClass()); node.setValue(TARGET, converter.getTargetClass()); }