sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1676275 - in /sis/branches/JDK8/core: sis-feature/src/main/java/org/apache/sis/feature/ sis-feature/src/test/java/org/apache/sis/feature/ sis-utility/src/main/java/org/apache/sis/util/resources/
Date Mon, 27 Apr 2015 14:23:48 GMT
Author: desruisseaux
Date: Mon Apr 27 14:23:48 2015
New Revision: 1676275

URL: http://svn.apache.org/r1676275
Log:
Feature: add a column for "characteristics" at formatting time.

Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureFormat.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureFormat.java?rev=1676275&r1=1676274&r2=1676275&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureFormat.java
[UTF-8] Mon Apr 27 14:23:48 2015
@@ -24,6 +24,7 @@ import java.text.FieldPosition;
 import java.text.ParsePosition;
 import java.text.ParseException;
 import java.util.concurrent.atomic.AtomicReference;
+import org.opengis.referencing.IdentifiedObject;
 import org.opengis.util.InternationalString;
 import org.opengis.util.GenericName;
 import org.apache.sis.io.TableAppender;
@@ -31,10 +32,13 @@ import org.apache.sis.io.TabularFormat;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.resources.Vocabulary;
+import org.apache.sis.referencing.IdentifiedObjects;
 
 // Branch-dependent imports
 import org.opengis.feature.IdentifiedType;
+import org.opengis.feature.Property;
 import org.opengis.feature.PropertyType;
+import org.opengis.feature.Attribute;
 import org.opengis.feature.AttributeType;
 import org.opengis.feature.Feature;
 import org.opengis.feature.FeatureType;
@@ -157,6 +161,9 @@ public class FeatureFormat extends Tabul
     public void format(final Object object, final Appendable toAppendTo) throws IOException
{
         ArgumentChecks.ensureNonNull("object",     object);
         ArgumentChecks.ensureNonNull("toAppendTo", toAppendTo);
+        /*
+         * Separate the Feature (optional) and the FeatureType (mandatory) instances.
+         */
         final FeatureType featureType;
         final Feature feature;
         if (object instanceof Feature) {
@@ -169,11 +176,25 @@ public class FeatureFormat extends Tabul
             throw new IllegalArgumentException(Errors.getResources(displayLocale)
                     .getString(Errors.Keys.UnsupportedType_1, object.getClass()));
         }
+        /*
+         * Check if at least one attribute has at least one characteritic. In many cases
there is none.
+         * In none we will ommit the "characteristics" column, which is the last column.
+         */
+        boolean hasCharacteristics = false;
+        for (final PropertyType propertyType : featureType.getProperties(true)) {
+            if (propertyType instanceof AttributeType<?>) {
+                if (!((AttributeType<?>) propertyType).characteristics().isEmpty())
{
+                    hasCharacteristics = true;
+                    break;
+                }
+            }
+        }
+        /*
+         * Format the column header.
+         */
         toAppendTo.append(toString(featureType.getName())).append(getLineSeparator());
-        final StringBuffer  buffer    = new StringBuffer();
-        final FieldPosition dummyFP   = new FieldPosition(-1);
-        final Vocabulary    resources = Vocabulary.getResources(displayLocale);
-        final TableAppender table     = new TableAppender(toAppendTo, columnSeparator);
+        final Vocabulary resources = Vocabulary.getResources(displayLocale);
+        final TableAppender table = new TableAppender(toAppendTo, columnSeparator);
         table.setMultiLinesCells(true);
         table.nextLine('─');
 header: for (int i=0; ; i++) {
@@ -183,6 +204,15 @@ header: for (int i=0; ; i++) {
                 case 1:  nextColumn(table); key = Vocabulary.Keys.Type; break;
                 case 2:  nextColumn(table); key = Vocabulary.Keys.Cardinality; break;
                 case 3:  nextColumn(table); key = (feature != null) ? Vocabulary.Keys.Value
: Vocabulary.Keys.DefaultValue; break;
+                case 4: {
+                    if (hasCharacteristics) {
+                        nextColumn(table);
+                        key = Vocabulary.Keys.Characteristics;
+                        break;
+                    } else {
+                        break header;
+                    }
+                }
                 default: break header;
             }
             table.append(resources.getString(key));
@@ -193,6 +223,8 @@ header: for (int i=0; ; i++) {
          * Done writing the header. Now write all property rows.
          * Rows without value will be skipped only if optional.
          */
+        final StringBuffer  buffer  = new StringBuffer();
+        final FieldPosition dummyFP = new FieldPosition(-1);
         for (final PropertyType propertyType : featureType.getProperties(true)) {
             Object value;
             if (feature != null) {
@@ -201,12 +233,12 @@ header: for (int i=0; ; i++) {
                     if (propertyType instanceof AttributeType &&
                             ((AttributeType) propertyType).getMinimumOccurs() == 0)
                     {
-                        continue; // If no value, skip the full row.
+                        continue;   // If no value, skip the full row.
                     }
                     if (propertyType instanceof FeatureAssociationRole &&
                             ((FeatureAssociationRole) propertyType).getMinimumOccurs() ==
0)
                     {
-                        continue; // If no value, skip the full row.
+                        continue;   // If no value, skip the full row.
                     }
                 }
             } else if (propertyType instanceof AttributeType<?>) {
@@ -272,8 +304,6 @@ header: for (int i=0; ; i++) {
                 final Format format = getFormat(valueClass);
                 if (format != null) {
                     value = format.format(value, buffer, dummyFP);
-                } else if (value instanceof InternationalString) {
-                    value = ((InternationalString) value).toString(displayLocale);
                 } else if (value instanceof Feature && propertyType instanceof FeatureAssociationRole)
{
                     final String p = DefaultAssociationRole.getTitleProperty((FeatureAssociationRole)
propertyType);
                     if (p != null) {
@@ -281,10 +311,33 @@ header: for (int i=0; ; i++) {
                     }
                 }
                 if (value != null) {
-                    table.append(value.toString());
+                    table.append(formatValue(value));
                 }
                 buffer.setLength(0);
             }
+            /*
+             * Column 4 - Characteristics.
+             */
+            if (hasCharacteristics) {
+                nextColumn(table);
+                if (propertyType instanceof AttributeType<?>) {
+                    String separator = "";
+                    for (final AttributeType<?> attribute : ((AttributeType<?>)
propertyType).characteristics().values()) {
+                        table.append(separator).append(toString(attribute.getName()));
+                        Object c = attribute.getDefaultValue();
+                        if (feature != null) {
+                            final Property p = feature.getProperty(propertyType.getName().toString());
+                            if (p instanceof Attribute<?>) {  // Should always be true,
but we are paranoiac.
+                                c = ((Attribute<?>) p).characteristics().get(attribute.getName().toString());
+                            }
+                        }
+                        if (c != null) {
+                            table.append(" = ").append(formatValue(c));
+                        }
+                        separator = ", ";
+                    }
+                }
+            }
             table.nextLine();
         }
         table.nextLine('─');
@@ -309,6 +362,22 @@ header: for (int i=0; ; i++) {
     }
 
     /**
+     * Formats the given attribute value.
+     */
+    private String formatValue(final Object value) {
+        if (value instanceof InternationalString) {
+            return ((InternationalString) value).toString(displayLocale);
+        } else if (value instanceof GenericName) {
+            return toString((GenericName) value);
+        } else if (value instanceof IdentifiedType) {
+            return toString(((IdentifiedType) value).getName());
+        } else if (value instanceof IdentifiedObject) {
+            return IdentifiedObjects.getIdentifierOrName((IdentifiedObject) value);
+        }
+        return value.toString();
+    }
+
+    /**
      * Formats the given object using a shared instance of {@code ParameterFormat}.
      * This is used for {@link DefaultParameterDescriptorGroup#toString()} implementation.
      */

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java?rev=1676275&r1=1676274&r2=1676275&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
[UTF-8] Mon Apr 27 14:23:48 2015
@@ -129,20 +129,25 @@ public final strictfp class DefaultFeatu
      * {@link InternationalString} and an arbitrary amount of universities.
      */
     static DefaultFeatureType worldMetropolis() {
-        return worldMetropolis(metropolis(), universityCity(), InternationalString.class);
+        return worldMetropolis(metropolis(), universityCity(), CharacteristicTypeMapTest.temperature(),
InternationalString.class);
     }
 
     /**
      * Creates a sub-type of the "metropolis" type with the "region" attribute overridden
to the given type.
-     * The given type should be {@link InternationalString}, but we allow other type for
testing argument checks.
+     * The given type should be {@link InternationalString}, but we allow other types for
testing argument checks.
      */
     private static DefaultFeatureType worldMetropolis(final DefaultFeatureType metropolis,
-            final DefaultFeatureType universityCity, final Class<?> regionType)
+            final DefaultFeatureType universityCity, final DefaultAttributeType<?>
temperature, final Class<?> regionType)
     {
         return new DefaultFeatureType(singletonMap(DefaultFeatureType.NAME_KEY, "World metropolis"),
false,
-                new DefaultFeatureType[] {metropolis, universityCity},
-                new DefaultAttributeType<>(singletonMap(DefaultAttributeType.NAME_KEY,
"region"),
-                        regionType, 1, 1, null));
+                new DefaultFeatureType[] {
+                    metropolis,
+                    universityCity
+                },
+                new DefaultAttributeType<?>[] {
+                    new DefaultAttributeType<>(singletonMap(DefaultAttributeType.NAME_KEY,
"region"), regionType, 1, 1, null),
+                    temperature
+                });
 
     }
 
@@ -390,25 +395,26 @@ public final strictfp class DefaultFeatu
     public void testPropertyOverride() {
         final DefaultFeatureType metropolis     = metropolis();
         final DefaultFeatureType universityCity = universityCity();
+        final DefaultAttributeType<?> temperature = CharacteristicTypeMapTest.temperature();
         try {
-            worldMetropolis(metropolis, universityCity, Integer.class);
+            worldMetropolis(metropolis, universityCity, temperature, Integer.class);
             fail("Shall not be allowed to override a 'CharSequence' attribute with an 'Integer'
one.");
         } catch (IllegalArgumentException e) {
             final String message = e.getMessage();
             assertTrue(message, message.contains("region"));
             assertTrue(message, message.contains("Metropolis"));
         }
-        final DefaultFeatureType worldMetropolis = worldMetropolis(metropolis, universityCity,
InternationalString.class);
+        final DefaultFeatureType worldMetropolis = worldMetropolis(metropolis, universityCity,
temperature, InternationalString.class);
         assertUnmodifiable(worldMetropolis);
         assertEquals     ("name", "World metropolis", worldMetropolis.getName().toString());
         assertArrayEquals("superTypes", new Object[] {metropolis, universityCity}, worldMetropolis.getSuperTypes().toArray());
         assertFalse      ("isAbstract",      worldMetropolis.isAbstract());
         assertFalse      ("isSparse",        worldMetropolis.isSparse());
         assertFalse      ("isSimple",        worldMetropolis.isSimple()); // Because of the
arbitrary amount of universities.
-        assertEquals     ("instanceSize", 5, worldMetropolis.indices().size());
+        assertEquals     ("instanceSize", 6, worldMetropolis.indices().size());
 
-        assertPropertiesEquals(worldMetropolis, false, "region");
-        assertPropertiesEquals(worldMetropolis, true, "city", "population", "region", "isGlobal",
"universities");
+        assertPropertiesEquals(worldMetropolis, false, "region", "temperature");
+        assertPropertiesEquals(worldMetropolis, true, "city", "population", "region", "isGlobal",
"universities", "temperature");
         assertEquals("property(“region”).valueClass", InternationalString.class,
                 ((DefaultAttributeType) worldMetropolis.getProperty("region")).getValueClass());
 

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java?rev=1676275&r1=1676274&r2=1676275&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureFormatTest.java
[UTF-8] Mon Apr 27 14:23:48 2015
@@ -34,7 +34,10 @@ import static org.apache.sis.test.Assert
  * @version 0.5
  * @module
  */
-@DependsOn(DenseFeatureTest.class)
+@DependsOn({
+    DenseFeatureTest.class,
+    CharacteristicMapTest.class
+})
 public final strictfp class FeatureFormatTest extends TestCase {
     /**
      * Tests the formatting of a {@link DefaultFeatureType}.
@@ -45,15 +48,16 @@ public final strictfp class FeatureForma
         final FeatureFormat format = new FeatureFormat(Locale.US, null);
         final String text = format.format(feature);
         assertMultilinesEquals("World metropolis\n" +
-                "┌──────────────┬─────────────────────┬─────────────┬───────────────┐\n"
+
-                "│ Name         │ Type                │ Cardinality │ Default value
│\n" +
-                "├──────────────┼─────────────────────┼─────────────┼───────────────┤\n"
+
-                "│ city         │ String              │ [1 … 1]     │ Utopia  
     │\n" +
-                "│ population   │ Integer             │ [1 … 1]     │         
     │\n" +
-                "│ region       │ InternationalString │ [1 … 1]     │         
     │\n" +
-                "│ isGlobal     │ Boolean             │ [1 … 1]     │         
     │\n" +
-                "│ universities │ String              │ [0 … ∞]     │       
       │\n" +
-                "└──────────────┴─────────────────────┴─────────────┴───────────────┘\n",
text);
+                "┌──────────────┬─────────────────────┬─────────────┬───────────────┬────────────────────────────┐\n"
+
+                "│ Name         │ Type                │ Cardinality │ Default value
│ Characteristics            │\n" +
+                "├──────────────┼─────────────────────┼─────────────┼───────────────┼────────────────────────────┤\n"
+
+                "│ city         │ String              │ [1 … 1]     │ Utopia  
     │                            │\n" +
+                "│ population   │ Integer             │ [1 … 1]     │         
     │                            │\n" +
+                "│ region       │ InternationalString │ [1 … 1]     │         
     │                            │\n" +
+                "│ isGlobal     │ Boolean             │ [1 … 1]     │         
     │                            │\n" +
+                "│ universities │ String              │ [0 … ∞]     │       
       │                            │\n" +
+                "│ temperature  │ Float               │ [1 … 1]     │         
     │ accuracy = 0.1, units = °C │\n" +
+                "└──────────────┴─────────────────────┴─────────────┴───────────────┴────────────────────────────┘\n",
text);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java?rev=1676275&r1=1676274&r2=1676275&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
[UTF-8] Mon Apr 27 14:23:48 2015
@@ -184,9 +184,9 @@ public abstract strictfp class FeatureTe
          * Before we set the population attribute, the feature should be considered invalid.
          * After we set it, the feature should be valid since all mandatory attributes are
set.
          */
-        assertQualityReports("population", "population");
+        assertQualityReports("population");
         setAttributeValue("population", null, 1000);
-        assertQualityReports(null, null);
+        assertQualityReports();
         /*
          * Opportunist tests using the existing instance.
          */
@@ -259,9 +259,9 @@ public abstract strictfp class FeatureTe
          * Before we set the 'isGlobal' attribute, the feature should be considered invalid.
          * After we set it, the feature should be valid since all mandatory attributes are
set.
          */
-        assertQualityReports("isGlobal", "isGlobal");
+        assertQualityReports("isGlobal", "temperature");
         setAttributeValue("isGlobal", null, Boolean.TRUE);
-        assertQualityReports(null, null);
+        assertQualityReports("temperature");
         /*
          * Opportunist tests using the existing instance.
          */
@@ -299,7 +299,7 @@ public abstract strictfp class FeatureTe
          * The quality report is expected to contains a custom element.
          */
         int numOccurrences = 0;
-        final DataQuality quality = assertQualityReports("population", "population");
+        final DataQuality quality = assertQualityReports("population");
         for (final Element report : quality.getReports()) {
             final String identifier = report.getMeasureIdentification().toString();
             if (identifier.equals("city")) {
@@ -315,27 +315,28 @@ public abstract strictfp class FeatureTe
     }
 
     /**
-     * Asserts that {@link AbstractFeature#quality()} reports no anomaly, or only an anomaly
for the given property.
+     * Asserts that {@link AbstractFeature#quality()} reports no anomaly, or only anomalies
for the given properties.
      *
-     * @param  property The property for which we expect a report, or {@code null} if none.
-     * @param  keyword  A keyword which is expected to exists in the explanation.
+     * @param  anomalousProperties The property for which we expect a report.
      * @return The data quality report.
      */
-    private DataQuality assertQualityReports(final String property, final String keyword)
{
-        int numOccurrences = 0;
+    private DataQuality assertQualityReports(final String... anomalousProperties) {
+        int anomalyIndex  = 0;
         final DataQuality quality = feature.quality();
         for (final Element report : quality.getReports()) {
             for (final Result result : report.getResults()) {
                 if (result instanceof ConformanceResult && !((ConformanceResult)
result).pass()) {
-                    final String identifier  = report.getMeasureIdentification().toString();
-                    final String explanation = ((ConformanceResult) result).getExplanation().toString();
-                    assertEquals("quality.report.measureIdentification", property, identifier);
-                    assertTrue("quality.report.result.explanation", explanation.contains(keyword));
-                    numOccurrences++;
+                    assertTrue("Too many reports", anomalyIndex < anomalousProperties.length);
+                    final String propertyName = anomalousProperties[anomalyIndex];
+                    final String identifier   = report.getMeasureIdentification().toString();
+                    final String explanation  = ((ConformanceResult) result).getExplanation().toString();
+                    assertEquals("quality.report.measureIdentification", propertyName, identifier);
+                    assertTrue  ("quality.report.result.explanation", explanation.contains(propertyName));
+                    anomalyIndex++;
                 }
             }
         }
-        assertEquals("Number of reports.", property == null ? 0 : 1, numOccurrences);
+        assertEquals("Number of reports.", anomalousProperties.length, anomalyIndex);
         return quality;
     }
 

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java?rev=1676275&r1=1676274&r2=1676275&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
[UTF-8] Mon Apr 27 14:23:48 2015
@@ -101,6 +101,11 @@ public final class Vocabulary extends In
         public static final short CharacterEncoding = 6;
 
         /**
+         * Characteristics
+         */
+        public static final short Characteristics = 85;
+
+        /**
          * Classpath
          */
         public static final short Classpath = 7;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties?rev=1676275&r1=1676274&r2=1676275&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
[ISO-8859-1] Mon Apr 27 14:23:48 2015
@@ -23,6 +23,7 @@ Attributes              = Attributes
 BarometricAltitude      = Barometric altitude
 Cardinality             = Cardinality
 CharacterEncoding       = Character encoding
+Characteristics         = Characteristics
 Classpath               = Classpath
 Code_1                  = {0} code
 Commands                = Commands

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties?rev=1676275&r1=1676274&r2=1676275&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
[ISO-8859-1] Mon Apr 27 14:23:48 2015
@@ -23,6 +23,7 @@ Attributes              = Attributs
 BarometricAltitude      = Altitude barom\u00e9trique
 Cardinality             = Cardinalit\u00e9
 CharacterEncoding       = Encodage des caract\u00e8res
+Characteristics         = Caract\u00e9ristiques
 Classpath               = Chemin de classes
 Code_1                  = Code {0}
 Commands                = Commandes



Mime
View raw message