You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2018/08/23 15:10:24 UTC

[sis] branch geoapi-4.0 updated (ed87f45 -> 11d5f39)

This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a change to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git.


    from ed87f45  One additional verification that values are written correctly in local copy of EPSG database.
     new 4bdd5c4  Update NetBeans project configuration for specifying a default workspace directory.
     new 50e0ba3  Upgrade parent project configuration.
     new 20bff4b  Use more fraction digits when this is required by the floating point number to format.
     new 11d5f39  CompoundFormat.getFormat(Class) needs to work with interfaces in addition of classes, in order to support DirectPosition and Unit types.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitignore                                         | 18 +++---
 .../apache/sis/metadata/TreeTableFormatTest.java   |  4 +-
 .../java/org/apache/sis/io/CompoundFormat.java     | 52 +++++++++------
 .../main/java/org/apache/sis/io/DefaultFormat.java | 13 +++-
 .../sis/util/collection/TreeTableFormat.java       | 75 +++++++++++++++++++++-
 ide-project/NetBeans/build.xml                     |  7 ++
 ide-project/NetBeans/nbproject/project.properties  | 15 +++--
 pom.xml                                            |  2 +-
 8 files changed, 144 insertions(+), 42 deletions(-)


[sis] 02/04: Upgrade parent project configuration.

Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 50e0ba39a512126706b3d8b97970650b26308db6
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Aug 23 14:28:42 2018 +0200

    Upgrade parent project configuration.
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 2a552e9..26eb439 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@
   <parent>
     <groupId>org.apache</groupId>
     <artifactId>apache</artifactId>
-    <version>20</version>
+    <version>21</version>
   </parent>
 
 


[sis] 01/04: Update NetBeans project configuration for specifying a default workspace directory.

Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 4bdd5c4e08eba2854011fa94a14963d1cbc7289d
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Aug 22 18:05:54 2018 +0200

    Update NetBeans project configuration for specifying a default workspace directory.
---
 .gitignore                                        | 18 ++++++++----------
 ide-project/NetBeans/build.xml                    |  7 +++++++
 ide-project/NetBeans/nbproject/project.properties | 15 +++++++++++----
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/.gitignore b/.gitignore
index b6127da..2d5d4d4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,28 +1,26 @@
-# All configurations
+ide-project/NetBeans/nbproject/private/
+ide-project/NetBeans/build/
+ide-project/NetBeans/dist/
 ide-project/local-src/
+ide-project/workspace/
 target/
-tmp/
 *.tmp
 *.log
-*.orig
 .svn/
 
-# NetBeans IDE files
-ide-project/NetBeans/build/
-ide-project/NetBeans/dist/
+# Generated by NetBeans IDE
 nbactions.xml
-nbproject
 
-# Eclipse IDE files
+# Generated by Eclipse IDE
 .classpath
 .project
 .settings/
 
-# IntelliJ IDE files
+# Generated by IntelliJ IDE
 *.iml
 *.ipr
 *.iws
 .idea/
 
-# MacOS
+# Generated by MacOS
 .DS_Store
diff --git a/ide-project/NetBeans/build.xml b/ide-project/NetBeans/build.xml
index 56c0b93..3051311 100644
--- a/ide-project/NetBeans/build.xml
+++ b/ide-project/NetBeans/build.xml
@@ -33,7 +33,14 @@
     avoid polluting the directory with dummy files as they appear in NetBeans.
   -->
   <target name="-post-init">
+    <available file="${src.local-src.dir}/.." type="dir" property="src.parent.exists"/>
+    <fail unless="src.parent.exists" message="Can not create &quot;${src.local-src.dir}&quot; because the parent directory does not exist."/>
+
+    <available file="${work.dir}/.." type="dir" property="wkd.parent.exists"/>
+    <fail unless="wkd.parent.exists" message="Can not create &quot;${work.dir}&quot; because the parent directory does not exist."/>
+
     <mkdir dir="${src.local-src.dir}"/>
+    <mkdir dir="${work.dir}"/>
   </target>
 
   <!--
diff --git a/ide-project/NetBeans/nbproject/project.properties b/ide-project/NetBeans/nbproject/project.properties
index 160ff9e..7b55c26 100644
--- a/ide-project/NetBeans/nbproject/project.properties
+++ b/ide-project/NetBeans/nbproject/project.properties
@@ -23,6 +23,8 @@ application.title    = Spatial Information System (SIS)
 application.vendor   = Apache
 application.homepage = http://sis.apache.org/
 application.desc     = Apache SIS is a free software, Java language library for developing geospatial applications.
+work.dir             = ../workspace
+work.dir.to.root     = ../..
 
 #
 # Some global configuration.
@@ -40,11 +42,14 @@ javac.target         = 1.8
 platform.active      = default_platform
 junit.forkmode       = once
 run.jvmargs          = --add-modules java.xml.bind -enableassertions \
-                       -Dorg.apache.sis.test.verbose=true -Dorg.apache.sis.test.extensive=true
+                       -Dorg.apache.sis.test.verbose=true -Dorg.apache.sis.test.extensive=true \
+                       -Djava.util.logging.config.file=${work.dir.to.root}/src/main/config/logging.properties
+#                      -Djava.security.manager -Djava.security.policy=${work.dir.to.root}/src/main/config/security.policy \
 #                      -Dderby.drda.startNetworkServer=true -Dderby.drda.portNumber=1527
 
 #
-# Source directories.
+# Source directories. The "project.root" path is relative to "ide-project/NetBeans" directory.
+# Note that "work.dir.to.root" points to the same directory, but from another starting point.
 #
 project.root         = ../..
 src.local-src.dir    = ../local-src
@@ -196,7 +201,9 @@ debug.test.modulepath=\
 
 #
 # Build configuration and destination directories.
+# The "compile.on.save" property must be 'false' for enabling the use of "../build.xml" file.
 #
+compile.on.save                          = false
 javac.compilerargs                       = -Xdoclint:syntax,html,reference,missing/protected,accessibility/protected
 javac.deprecation                        = true
 javac.external.vm                        = false
@@ -248,5 +255,5 @@ mkdist.disabled                          = true
 #
 # Editor
 #
-auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsEnabled=true
-auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
+auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsEnabled = true
+auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile    = nbproject/cfg_hints.xml


[sis] 04/04: CompoundFormat.getFormat(Class) needs to work with interfaces in addition of classes, in order to support DirectPosition and Unit types.

Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 11d5f39b9c65e6e65b9d785bd0fb7f3751963215
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Aug 23 17:09:16 2018 +0200

    CompoundFormat.getFormat(Class) needs to work with interfaces in addition of classes, in order to support DirectPosition and Unit types.
---
 .../apache/sis/metadata/TreeTableFormatTest.java   |  4 +-
 .../java/org/apache/sis/io/CompoundFormat.java     | 52 +++++++++++++---------
 .../main/java/org/apache/sis/io/DefaultFormat.java | 13 +++++-
 .../sis/util/collection/TreeTableFormat.java       | 27 +++++++++++
 4 files changed, 71 insertions(+), 25 deletions(-)

diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java b/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
index dee83e6..6132989 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
@@ -146,12 +146,12 @@ public final strictfp class TreeTableFormatTest extends TestCase {
             "  │   └─Attribute\n" +
             "  │       ├─Max value………………… 0.26\n" +
             "  │       ├─Min value………………… 0.25\n" +
-            "  │       └─Units…………………………… cm\n" +
+            "  │       └─Units…………………………… centimetre\n" +
             "  └─Attribute group (2 of 2)\n" +
             "      └─Attribute\n" +
             "          ├─Max value………………… 0.29\n" +
             "          ├─Min value………………… 0.28\n" +
-            "          └─Units…………………………… cm\n", text);
+            "          └─Units…………………………… centimetre\n", text);
     }
 
     /**
diff --git a/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java b/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
index dfb6ca7..4ecf3fd 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
@@ -39,6 +39,7 @@ import org.apache.sis.measure.AngleFormat;
 import org.apache.sis.measure.Range;
 import org.apache.sis.measure.RangeFormat;
 import org.apache.sis.measure.UnitFormat;
+import org.apache.sis.util.Classes;
 import org.apache.sis.util.Localized;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.ArgumentChecks;
@@ -92,7 +93,7 @@ import static org.apache.sis.internal.util.StandardDateFormat.UTC;
  * in case of error.</div>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  *
  * @param <T>  the base type of objects parsed and formatted by this class.
  *
@@ -121,8 +122,8 @@ public abstract class CompoundFormat<T> extends Format implements Localized {
     private final TimeZone timezone;
 
     /**
-     * The formats for smaller unit of information.
-     * Will be created only when first needed.
+     * The formats for smaller unit of information, created when first needed.
+     * {@code null} is used as a sentinel value meaning "no format".
      */
     private transient Map<Class<?>, Format> formats;
 
@@ -379,7 +380,9 @@ public abstract class CompoundFormat<T> extends Format implements Localized {
      *   <li>Otherwise if a format can be {@linkplain #createFormat(Class) created}
      *       for the given type, cache the newly created format and return it.</li>
      *   <li>Otherwise do again the same checks for the {@linkplain Class#getSuperclass() super class}.</li>
-     *   <li>If no format can be created, returns {@code null}.</li>
+     *   <li>If no format is found for a concrete class, search again for
+     *       {@linkplain Classes#getAllInterfaces(Class) all implemented interfaces}.</li>
+     *   <li>If no format can be created, return {@code null}.</li>
      * </ol>
      *
      * See {@link #createFormat(Class)} for the list of value types recognized by the default
@@ -390,26 +393,33 @@ public abstract class CompoundFormat<T> extends Format implements Localized {
      *         or {@code null} if none.
      */
     protected Format getFormat(final Class<?> valueType) {
-        Format format = null;
-        Map<Class<?>,Format> formats = this.formats;
-        for (Class<?> type = valueType; type != null; type = type.getSuperclass()) {
-            if (formats != null) {
-                format = formats.get(type);
-                if (format != null) {
-                    if (type != valueType) {
-                        formats.put(valueType, format);
+        if (formats == null) {
+            formats = new IdentityHashMap<>(4);
+        }
+        Format format = formats.get(valueType);
+        if (format == null && !formats.containsKey(valueType)) {
+            format = createFormat(valueType);
+            if (format == null) {
+                Class<?>   type = valueType;
+                Class<?>[] interfaces = null;
+                for (int i=-1;;) {
+                    if (i >= 0 || (type = type.getSuperclass()) == null) {      // Try parent classes first.
+                        if (interfaces == null) {
+                            interfaces = Classes.getAllInterfaces(valueType);   // Try interfaces after we tried all parent classes.
+                        }
+                        if (++i >= interfaces.length) break;                    // No format found - stop the search with format = null.
+                        type = interfaces[i];
+                    }
+                    format = formats.get(type);
+                    if (format != null) break;                                  // Intentionally no formats.containsKey(type) check here.
+                    format = createFormat(type);
+                    if (format != null) {
+                        formats.put(type, format);
+                        break;
                     }
-                    break;
-                }
-            }
-            format = createFormat(type);
-            if (format != null) {
-                if (formats == null) {
-                    this.formats = formats = new IdentityHashMap<>(4);
                 }
-                formats.put(type, format);
-                break;
             }
+            formats.put(valueType, format);                                     // Store result even null.
         }
         return format;
     }
diff --git a/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java b/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
index af2d4f6..00fe190 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
@@ -38,11 +38,10 @@ import org.apache.sis.internal.util.LocalizedParseException;
  * for arbitrary {@code Format} classes.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.3
  * @module
  */
-@SuppressWarnings("CloneableClassWithoutClone")   // Because this class does not contain field that need to be cloned.
 final class DefaultFormat extends Format {
     /**
      * For cross-version compatibility.
@@ -161,6 +160,16 @@ final class DefaultFormat extends Format {
     }
 
     /**
+     * Unconditionally returns {@code this} since this format does not contain any modifiable field.
+     * This same {@code DefaultFormat} instances can be shared.
+     */
+    @Override
+    @SuppressWarnings("CloneDoesntCallSuperClone")
+    public Object clone() {
+        return this;
+    }
+
+    /**
      * Resolves to the singleton instance on deserialization.
      */
     private Object readResolve() throws ObjectStreamException {
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java b/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
index 41b0808..154c201 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
@@ -43,6 +43,7 @@ import org.apache.sis.io.LineAppender;
 import org.apache.sis.io.TableAppender;
 import org.apache.sis.io.TabularFormat;
 import org.apache.sis.io.CompoundFormat;
+import org.apache.sis.measure.UnitFormat;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.Workaround;
 import org.apache.sis.util.CharSequences;
@@ -982,6 +983,32 @@ public class TreeTableFormat extends TabularFormat<TreeTable> {
     }
 
     /**
+     * Creates a new format to use for parsing and formatting values of the given type.
+     * This method is invoked by the first time that a format is needed for the given type.
+     * Subclasses can override this method if they want to configure the way dates, numbers
+     * or other objects are formatted.
+     * See {@linkplain org.apache.sis.io.CompoundFormat#createFormat(Class) parent class documentation}
+     * for more information.
+     *
+     * <p>The implementation in {@code TreeTableFormat} differs from the default implementation
+     * in the following aspects:</p>
+     * <ul>
+     *   <li>{@code UnitFormat} uses {@link UnitFormat.Style#NAME}.</li>
+     * </ul>
+     *
+     * @param  valueType  the base type of values to parse or format.
+     * @return the format to use for parsing of formatting values of the given type, or {@code null} if none.
+     */
+    @Override
+    protected Format createFormat(final Class<?> valueType) {
+        final Format format = super.createFormat(valueType);
+        if (format instanceof UnitFormat) {
+            ((UnitFormat) format).setStyle(UnitFormat.Style.NAME);
+        }
+        return format;
+    }
+
+    /**
      * Returns a clone of this format.
      *
      * @return a clone of this format.


[sis] 03/04: Use more fraction digits when this is required by the floating point number to format.

Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 20bff4b835be44e07893386f92c3724d10b60fdd
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Aug 23 14:29:15 2018 +0200

    Use more fraction digits when this is required by the floating point number to format.
---
 .../sis/util/collection/TreeTableFormat.java       | 48 +++++++++++++++++++++-
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java b/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
index 2f771fd..41b0808 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
@@ -29,6 +29,7 @@ import java.util.ConcurrentModificationException;
 import java.util.function.Predicate;
 import java.io.IOException;
 import java.text.Format;
+import java.text.DecimalFormat;
 import java.text.ParsePosition;
 import java.text.ParseException;
 import java.util.regex.Matcher;
@@ -42,11 +43,13 @@ import org.apache.sis.io.LineAppender;
 import org.apache.sis.io.TableAppender;
 import org.apache.sis.io.TabularFormat;
 import org.apache.sis.io.CompoundFormat;
+import org.apache.sis.util.Numbers;
 import org.apache.sis.util.Workaround;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.resources.Vocabulary;
+import org.apache.sis.math.DecimalFunctions;
 import org.apache.sis.internal.util.Acyclic;
 import org.apache.sis.internal.util.MetadataServices;
 import org.apache.sis.internal.util.LocalizedParseException;
@@ -175,11 +178,29 @@ public class TreeTableFormat extends TabularFormat<TreeTable> {
 
     /**
      * The set to be given to {@link Writer} constructor,
-     * created when first needed and reused for subsequent formating.
+     * created when first needed and reused for subsequent formatting.
      */
     private transient Set<TreeTable.Node> recursivityGuard;
 
     /**
+     * A clone of the number format to be used with different settings (number of fraction digits, scientific notation).
+     * We use a clone for avoiding to change the setting of potentially user-supplied number format. This is used only
+     * for floating point numbers, not for integers.
+     */
+    private transient DecimalFormat adaptableFormat;
+
+    /**
+     * The default pattern used by {@link #adaptableFormat}.
+     * Used for switching back to default mode after scientific notation.
+     */
+    private transient String defaultPattern;
+
+    /**
+     * Whether {@link #adaptableFormat} is using scientific notation.
+     */
+    private transient boolean usingScientificNotation;
+
+    /**
      * Creates a new tree table format.
      *
      * @param locale    the locale to use for numbers, dates and angles formatting,
@@ -771,7 +792,30 @@ public class TreeTableFormat extends TabularFormat<TreeTable> {
                  * more uniform formatting.
                  */
                 final Format format = getFormat(value.getClass());
-                text = (format != null) ? format.format(value) : value.toString();
+                if (format instanceof DecimalFormat && Numbers.isFloat(value.getClass())) {
+                    /*
+                     * The default floating point formats use only 3 fraction digits. We adjust that to the number
+                     * of digits required by the number to format. We do that only if no NumberFormat was inferred
+                     * for the whole column (in order to keep column format uniform).  We use enough precision for
+                     * all fraction digits except the last 2, in order to let DecimalFormat round the number.
+                     */
+                    if (adaptableFormat == null) {
+                        adaptableFormat = (DecimalFormat) format.clone();
+                        defaultPattern = adaptableFormat.toPattern();
+                    }
+                    final int nf = DecimalFunctions.fractionDigitsForValue(((Number) value).doubleValue());
+                    final boolean preferScientificNotation = (nf > 20 || nf < 7);       // == (value < 1E-4 || value > 1E+9)
+                    if (preferScientificNotation != usingScientificNotation) {
+                        usingScientificNotation = preferScientificNotation;
+                        adaptableFormat.applyPattern(preferScientificNotation ? "0.0############E0" : defaultPattern);
+                    }
+                    if (!preferScientificNotation) {
+                        adaptableFormat.setMaximumFractionDigits(nf - 2);       // All significand fraction digits except last two.
+                    }
+                    text = adaptableFormat.format(value);
+                } else {
+                    text = (format != null) ? format.format(value) : value.toString();
+                }
             }
             append(text);
         }