sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1831583 - in /sis/branches/JDK8: application/sis-console/src/main/java/org/apache/sis/console/ application/sis-console/src/test/java/org/apache/sis/console/ core/sis-utility/src/main/java/org/apache/sis/util/collection/
Date Mon, 14 May 2018 16:07:28 GMT
Author: desruisseaux
Date: Mon May 14 16:07:28 2018
New Revision: 1831583

URL: http://svn.apache.org/viewvc?rev=1831583&view=rev
Log:
Simplify the "sis metadata" command-line by omiting the verbose nodes telling that the tree
use ISO 19115 standard.

Modified:
    sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/FormattedOutputCommand.java
    sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java
    sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/package-info.java
    sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java

Modified: sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/FormattedOutputCommand.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/FormattedOutputCommand.java?rev=1831583&r1=1831582&r2=1831583&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/FormattedOutputCommand.java
[UTF-8] (original)
+++ sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/FormattedOutputCommand.java
[UTF-8] Mon May 14 16:07:28 2018
@@ -20,6 +20,7 @@ import java.util.Locale;
 import java.util.EnumSet;
 import java.io.Console;
 import java.io.IOException;
+import java.util.function.Predicate;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.JAXBException;
 import org.opengis.metadata.Metadata;
@@ -54,7 +55,7 @@ import org.apache.sis.xml.XML;
  * The output format is controlled by {@link OutputFormat} enumeration.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.8
  * @module
  */
@@ -221,6 +222,7 @@ abstract class FormattedOutputCommand ex
                         ValueExistencePolicy.COMPACT);
                 final TreeTableFormat tf = new TreeTableFormat(locale, timezone);
                 tf.setColumns(TableColumn.NAME, TableColumn.VALUE);
+                tf.setNodeFilter(getNodeFilter());
                 tf.format(tree, out);
                 break;
             }
@@ -280,6 +282,14 @@ abstract class FormattedOutputCommand ex
     }
 
     /**
+     * Returns the filter for simplifying the tree table to be formatted, or {@code null}
if none.
+     * This is used only for the tree in text format (not for XML output).
+     */
+    Predicate<TreeTable.Node> getNodeFilter() {
+        return null;
+    }
+
+    /**
      * Returns {@code true} if {@link #out} is sending its output to the console.
      * If not, then we are probably writing to a file or the user specified his own encoding.
      * In such case, we will send the XML output to an {@code OutputStream} instead than
to a

Modified: sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java?rev=1831583&r1=1831582&r2=1831583&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java
[UTF-8] (original)
+++ sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/MetadataCommand.java
[UTF-8] Mon May 14 16:07:28 2018
@@ -18,16 +18,19 @@ package org.apache.sis.console;
 
 import java.util.Collections;
 import java.util.EnumSet;
+import java.util.function.Predicate;
 import org.opengis.metadata.Metadata;
 import org.opengis.referencing.ReferenceSystem;
 import org.apache.sis.metadata.iso.DefaultMetadata;
+import org.apache.sis.util.collection.TableColumn;
+import org.apache.sis.util.collection.TreeTable;
 
 
 /**
  * The "metadata" sub-command.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.3
  * @module
  */
@@ -76,4 +79,16 @@ final class MetadataCommand extends Form
         }
         return 0;
     }
+
+    /**
+     * Returns the filter for simplifying the tree table to be formatted.
+     * This is used only for the tree in text format (not for XML output).
+     *
+     * <p>We omit the "Metadata standard" node because it is hard-coded to the same
value in all Apache SIS {@code DataStore}
+     * implementations, and that hard-coded value is verbose. The value will be shown in
XML output, which is verbose anyway.</p>
+     */
+    @Override
+    Predicate<TreeTable.Node> getNodeFilter() {
+        return (node) -> !"metadataStandard".equals(node.getValue(TableColumn.IDENTIFIER));
+    }
 }

Modified: sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/package-info.java?rev=1831583&r1=1831582&r2=1831583&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/package-info.java
[UTF-8] Mon May 14 16:07:28 2018
@@ -47,7 +47,7 @@
  * and Management Using JMX Technology</a> page.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.3
  * @module
  */

Modified: sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java?rev=1831583&r1=1831582&r2=1831583&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/application/sis-console/src/test/java/org/apache/sis/console/MetadataCommandTest.java
[UTF-8] Mon May 14 16:07:28 2018
@@ -56,7 +56,6 @@ public final strictfp class MetadataComm
      */
     private static void verifyNetCDF(final String expectedHeader, final String result) {
         assertTrue(expectedHeader,                           result.startsWith(expectedHeader));
-        assertTrue("ISO 19115",                              result.contains("ISO 19115"));
         assertTrue("Sea Surface Temperature Analysis Model", result.contains("Sea Surface
Temperature Analysis Model"));
         assertTrue("GCMD Science Keywords",                  result.contains("GCMD Science
Keywords"));
         assertTrue("NOAA/NWS/NCEP",                          result.contains("NOAA/NWS/NCEP"));

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java?rev=1831583&r1=1831582&r2=1831583&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
[UTF-8] Mon May 14 16:07:28 2018
@@ -26,6 +26,7 @@ import java.util.Locale;
 import java.util.TimeZone;
 import java.util.Currency;
 import java.util.ConcurrentModificationException;
+import java.util.function.Predicate;
 import java.io.IOException;
 import java.text.Format;
 import java.text.ParsePosition;
@@ -100,7 +101,7 @@ import static org.apache.sis.util.Charac
  * than the user object of a parent node <var>A</var>, then the children of the
<var>C</var> node will not be formatted.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.3
  * @module
  */
@@ -162,6 +163,15 @@ public class TreeTableFormat extends Tab
     private transient String treeBlank, treeLine, treeCross, treeEnd;
 
     /**
+     * A filter for specifying whether a node should be formatted, or {@code null} if no
filtering is applied.
+     * This is ignored at parsing time.
+     *
+     * @see #getNodeFilter()
+     * @see #setNodeFilter(Predicate)
+     */
+    private Predicate<TreeTable.Node> nodeFilter;
+
+    /**
      * The set to be given to {@link Writer} constructor,
      * created when first needed and reused for subsequent formating.
      */
@@ -292,6 +302,32 @@ public class TreeTableFormat extends Tab
     }
 
     /**
+     * Returns the filter that specify whether a node should be formatted or ignored.
+     * This is the predicate specified in the last call to {@link #setNodeFilter(Predicate)}.
+     * If no filter has been set, then this method returns {@code null}.
+     *
+     * @return a filter for specifying whether a node should be formatted, or {@code null}
if no filtering is applied.
+     *
+     * @since 1.0
+     */
+    public Predicate<TreeTable.Node> getNodeFilter() {
+        return nodeFilter;
+    }
+
+    /**
+     * Sets a filter specifying whether a node should be formatted or ignored.
+     * Filters are tested at formatting time for all children of the root node (but not for
the root node itself).
+     * Filters are ignored at parsing time.
+     *
+     * @param  filter  filter for specifying whether a node should be formatted, or {@code
null} for no filtering.
+     *
+     * @since 1.0
+     */
+    public void setNodeFilter(final Predicate<TreeTable.Node> filter) {
+        this.nodeFilter = filter;
+    }
+
+    /**
      * Returns the locale to use for code lists, international strings and exception messages.
      */
     final Locale getDisplayLocale() {
@@ -795,11 +831,11 @@ public class TreeTableFormat extends Tab
             final boolean omitCheck = node.getClass().isAnnotationPresent(Acyclic.class);
             if (omitCheck || recursivityGuard.add(node)) {
                 final Iterator<? extends TreeTable.Node> it = node.getChildren().iterator();
-                boolean hasNext = it.hasNext();
-                while (hasNext) {
-                    final TreeTable.Node child = it.next();
-                    hasNext = it.hasNext();
-                    isLast[level] = !hasNext;                   // Must be set before the
call to 'format' below.
+                TreeTable.Node next = next(it);
+                while (next != null) {
+                    final TreeTable.Node child = next;
+                    next = next(it);
+                    isLast[level] = (next == null);                 // Must be set before
the call to 'format' below.
                     format(child, level+1);
                 }
                 if (!omitCheck && !recursivityGuard.remove(node)) {
@@ -863,6 +899,21 @@ public class TreeTableFormat extends Tab
     }
 
     /**
+     * Returns the next filtered element from the given iterator, or {@code null} if none.
+     */
+    private TreeTable.Node next(final Iterator<? extends TreeTable.Node> it) {
+        while (it.hasNext()) {
+            final TreeTable.Node next = it.next();
+            if (next != null) {
+                if (nodeFilter == null || nodeFilter.test(next)) {
+                    return next;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
      * Returns a clone of this format.
      *
      * @return a clone of this format.



Mime
View raw message