sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1793563 - in /sis/branches/JDK8: core/sis-metadata/src/main/java/org/apache/sis/metadata/ core/sis-metadata/src/test/java/org/apache/sis/metadata/ storage/sis-earth-observation/src/test/java/org/apache/sis/storage/earthobservation/ storage...
Date Tue, 02 May 2017 17:18:32 GMT
Author: desruisseaux
Date: Tue May  2 17:18:32 2017
New Revision: 1793563

URL: http://svn.apache.org/viewvc?rev=1793563&view=rev
Log:
Better node name when a property have the same name than its type and various subtypes are
possible.
https://issues.apache.org/jira/browse/SIS-298

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeTableView.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableViewTest.java
    sis/branches/JDK8/storage/sis-earth-observation/src/test/java/org/apache/sis/storage/earthobservation/LandsatReaderTest.java
    sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java?rev=1793563&r1=1793562&r2=1793563&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
[UTF-8] Tue May  2 17:18:32 2017
@@ -344,10 +344,63 @@ class TreeNode implements Node {
          * {@link KeyNamePolicy#UML_IDENTIFIER} instead than {@link KeyNamePolicy#JAVABEANS_PROPERTY}
          * in order to get the singular form instead of the plural one, because we will create
one
          * node for each element in a collection.
+         *
+         * <p>If the property name is equals, ignoring case, to the simple type name,
then this method
+         * returns the subtype name. For example instead of:</p>
+         *
+         * {@preformat text
+         *   Citation
+         *    └─Cited responsible party
+         *       └─Party
+         *          └─Name ……………………………… Jon Smith
+         * }
+         *
+         * we format:
+         *
+         * {@preformat
+         *   Citation
+         *    └─Cited responsible party
+         *       └─Individual
+         *          └─Name ……………………………… Jon Smith
+         * }
+         *
+         * @see <a href="https://issues.apache.org/jira/browse/SIS-298">SIS-298</a>
          */
         @Override
         CharSequence getName() {
-            return CharSequences.camelCaseToSentence(getIdentifier()).toString();
+            String identifier = getIdentifier();
+            if (identifier.equalsIgnoreCase(Classes.getShortName(baseType))) {
+                final Object value = getUserObject();
+                if (value != null) {
+                    Class<?> type = standardSubType(Classes.getLeafInterfaces(value.getClass(),
baseType));
+                    if (type != null && type != Void.TYPE) {
+                        identifier = Classes.getShortName(type);
+                    }
+                }
+            }
+            return CharSequences.camelCaseToSentence(identifier).toString();
+        }
+
+        /**
+         * Returns the element of the given array which is both assignable to {@link #baseType}
and a member
+         * of the standard represented by {@link TreeTableView#standard}. If no such type
is found, returns
+         * {@code null}. If more than one type is found, returns the {@link Void#TYPE} sentinel
value.
+         */
+        private Class<?> standardSubType(final Class<?>[] subtypes) {
+            Class<?> type = null;
+            for (Class<?> c : subtypes) {
+                if (baseType.isAssignableFrom(c)) {
+                    if (!table.standard.isMetadata(c)) {
+                        c = standardSubType(c.getInterfaces());
+                    }
+                    if (type == null) {
+                        type = c;
+                    } else if (type != c) {
+                        return Void.TYPE;
+                    }
+                }
+            }
+            return type;
         }
 
         /**

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeTableView.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeTableView.java?rev=1793563&r1=1793562&r2=1793563&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeTableView.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeTableView.java
[UTF-8] Tue May  2 17:18:32 2017
@@ -104,7 +104,7 @@ final class TreeTableView implements Tre
     {
         this.standard    = standard;
         this.valuePolicy = valuePolicy;
-        this.root = new TreeNode(this, metadata, baseType);
+        this.root        = new TreeNode(this, metadata, baseType);
     }
 
     /**
@@ -113,7 +113,7 @@ final class TreeTableView implements Tre
     @Override
     @SuppressWarnings("ReturnOfCollectionOrArrayField")
     public List<TableColumn<?>> getColumns() {
-        return COLUMNS;     // Unmodifiable
+        return COLUMNS;                                 // Unmodifiable
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java?rev=1793563&r1=1793562&r2=1793563&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java
[UTF-8] Tue May  2 17:18:32 2017
@@ -65,11 +65,11 @@ public final strictfp class TreeNodeTest
      *     ├─Alternate title (2 of 2)…………………………………………
Second alternate title
      *     ├─Edition………………………………………………………………………………………
Some edition
      *     ├─Cited responsible party (1 of 2)
-     *     │   └─Party (Organisation)
+     *     │   └─Organisation
      *     │      ├─Name……………………………………………………………………………
Some organisation
      *     │      └─Role……………………………………………………………………………
Distributor
      *     ├─Cited responsible party (2 of 2)
-     *     │   └─Party (Individual)
+     *     │   └─Individual
      *     │      ├─Name……………………………………………………………………………
Some person of contact
      *     │      ├─Contact info
      *     │      │   └─Address
@@ -167,6 +167,8 @@ public final strictfp class TreeNodeTest
 
     /**
      * Tests {@link TreeNode#getName()} on a metadata with a deeper hierarchy.
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-298">SIS-298</a>
      */
     @Test
     @DependsOnMethod("testGetNameForMultiOccurrences")
@@ -179,11 +181,11 @@ public final strictfp class TreeNodeTest
               "Alternate title (2 of 2)",
               "Edition",
               "Cited responsible party (1 of 2)",
-                "Party",
+                "Organisation",                         // A Party subtype
                   "Name",
                 "Role",
               "Cited responsible party (2 of 2)",
-                "Party",
+                "Individual",                           // A Party subtype
                   "Name",
                   "Contact info",
                     "Address",

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java?rev=1793563&r1=1793562&r2=1793563&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
[UTF-8] Tue May  2 17:18:32 2017
@@ -44,7 +44,7 @@ import static org.apache.sis.test.Assert
  * Tests the {@link TreeTableFormat} applied to the formatting of metadata tree.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.5
+ * @version 0.8
  * @since   0.3
  * @module
  */
@@ -76,6 +76,8 @@ public final strictfp class TreeTableFor
 
     /**
      * Tests the formatting of a {@link DefaultCitation} object.
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-298">SIS-298</a>
      */
     @Test
     public void testCitation() {
@@ -92,11 +94,11 @@ public final strictfp class TreeTableFor
             "  │   ├─Code……………………………………………………………………
9782505004509\n" +
             "  │   └─Code space……………………………………………………
ISBN\n"+
             "  ├─Cited responsible party (1 of 2)\n" +
-            "  │   ├─Party\n" +
+            "  │   ├─Individual\n" +
             "  │   │   └─Name…………………………………………………………
Testsuya Toyoda\n" +
             "  │   └─Role……………………………………………………………………
Author\n" +
             "  ├─Cited responsible party (2 of 2)\n" +
-            "  │   ├─Party\n" +
+            "  │   ├─Organisation\n" +
             "  │   │   └─Name…………………………………………………………
Kōdansha\n" +
             "  │   ├─Role……………………………………………………………………
Editor\n" +
             "  │   └─Extent\n" +

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableViewTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableViewTest.java?rev=1793563&r1=1793562&r2=1793563&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableViewTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableViewTest.java
[UTF-8] Tue May  2 17:18:32 2017
@@ -60,11 +60,11 @@ public final strictfp class TreeTableVie
             "  ├─Alternate title (2 of 2)……………………………………………
Second alternate title\n" +
             "  ├─Edition…………………………………………………………………………………………
Some edition\n" +
             "  ├─Cited responsible party (1 of 2)\n" +
-            "  │   ├─Party\n" +
+            "  │   ├─Organisation\n" +
             "  │   │   └─Name……………………………………………………………………………
Some organisation\n" +
             "  │   └─Role………………………………………………………………………………………
Distributor\n" +
             "  ├─Cited responsible party (2 of 2)\n" +
-            "  │   ├─Party\n" +
+            "  │   ├─Individual\n" +
             "  │   │   ├─Name……………………………………………………………………………
Some person of contact\n" +
             "  │   │   └─Contact info\n" +
             "  │   │       └─Address\n" +

Modified: sis/branches/JDK8/storage/sis-earth-observation/src/test/java/org/apache/sis/storage/earthobservation/LandsatReaderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-earth-observation/src/test/java/org/apache/sis/storage/earthobservation/LandsatReaderTest.java?rev=1793563&r1=1793562&r2=1793563&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-earth-observation/src/test/java/org/apache/sis/storage/earthobservation/LandsatReaderTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-earth-observation/src/test/java/org/apache/sis/storage/earthobservation/LandsatReaderTest.java
[UTF-8] Tue May  2 17:18:32 2017
@@ -301,7 +301,7 @@ public class LandsatReaderTest extends T
                 + "  │   │   ├─Code space…………………………………………………………………
ISO\n"
                 + "  │   │   └─Version…………………………………………………………………………
2014(E)\n"
                 + "  │   ├─Cited responsible party\n"
-                + "  │   │   ├─Party\n"
+                + "  │   │   ├─Organisation\n"
                 + "  │   │   │   └─Name………………………………………………………………………
International Organization for Standardization\n"
                 + "  │   │   └─Role…………………………………………………………………………………
Principal investigator\n"
                 + "  │   └─Presentation form…………………………………………………………
Document digital\n"
@@ -313,7 +313,7 @@ public class LandsatReaderTest extends T
                 + "      │   ├─Code space…………………………………………………………………
ISO\n"
                 + "      │   └─Version…………………………………………………………………………
2009(E)\n"
                 + "      ├─Cited responsible party\n"
-                + "      │   ├─Party\n"
+                + "      │   ├─Organisation\n"
                 + "      │   │   └─Name………………………………………………………………………
International Organization for Standardization\n"
                 + "      │   └─Role…………………………………………………………………………………
Principal investigator\n"
                 + "      └─Presentation form…………………………………………………………
Document digital\n", text);

Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java?rev=1793563&r1=1793562&r2=1793563&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
[UTF-8] Tue May  2 17:18:32 2017
@@ -87,7 +87,7 @@ public final strictfp class MetadataRead
         assertMultilinesEquals(
             "Metadata\n" +
             "  ├─Contact\n" +
-            "  │   ├─Party\n" +
+            "  │   ├─Individual\n" +                         // TODO: actually
we can not distinguish individual from organization.
             "  │   │   └─Name…………………………………………………………………………………
NOAA/NWS/NCEP\n" +
             "  │   └─Role……………………………………………………………………………………………
Point of contact\n" +
             "  ├─Spatial representation info\n" +
@@ -114,12 +114,12 @@ public final strictfp class MetadataRead
             "  │   │   │   │   └─Title…………………………………………………………
edu.ucar.unidata\n" +
             "  │   │   │   └─Code………………………………………………………………………
NCEP/SST/Global_5x2p5deg/SST_Global_5x2p5deg_20050922_0000.nc\n" +
             "  │   │   └─Cited responsible party\n" +
-            "  │   │       ├─Party\n" +
+            "  │   │       ├─Individual\n" +                 // TODO:
actually we can not distinguish individual from organization.
             "  │   │       │   └─Name……………………………………………………………
NOAA/NWS/NCEP\n" +
             "  │   │       └─Role………………………………………………………………………
Originator\n" +
             "  │   ├─Abstract…………………………………………………………………………………
NCEP SST Global 5.0 x 2.5 degree model data\n" +
             "  │   ├─Point of contact\n" +
-            "  │   │   ├─Party\n" +
+            "  │   │   ├─Individual\n" +
             "  │   │   │   └─Name………………………………………………………………………
NOAA/NWS/NCEP\n" +
             "  │   │   └─Role…………………………………………………………………………………
Point of contact\n" +
             "  │   ├─Descriptive keywords\n" +
@@ -164,7 +164,7 @@ public final strictfp class MetadataRead
             "  │   │   ├─Code space…………………………………………………………………
ISO\n" +
             "  │   │   └─Version…………………………………………………………………………
2014(E)\n" +
             "  │   ├─Cited responsible party\n" +
-            "  │   │   ├─Party\n" +
+            "  │   │   ├─Organisation\n" +
             "  │   │   │   └─Name………………………………………………………………………
International Organization for Standardization\n" +
             "  │   │   └─Role…………………………………………………………………………………
Principal investigator\n" +
             "  │   └─Presentation form…………………………………………………………
Document digital\n" +
@@ -176,7 +176,7 @@ public final strictfp class MetadataRead
             "      │   ├─Code space…………………………………………………………………
ISO\n" +
             "      │   └─Version…………………………………………………………………………
2009(E)\n" +
             "      ├─Cited responsible party\n" +
-            "      │   ├─Party\n" +
+            "      │   ├─Organisation\n" +
             "      │   │   └─Name………………………………………………………………………
International Organization for Standardization\n" +
             "      │   └─Role…………………………………………………………………………………
Principal investigator\n" +
             "      └─Presentation form…………………………………………………………
Document digital\n", text);



Mime
View raw message