sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1759566 - in /sis/branches/JDK8: core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/ core/sis-utility/src/main/java/org/apache/sis/internal/util/ core/sis-utility/src/test/java/org/apache/sis/internal/util/ storage/sis...
Date Wed, 07 Sep 2016 08:59:55 GMT
Author: desruisseaux
Date: Wed Sep  7 08:59:55 2016
New Revision: 1759566

URL: http://svn.apache.org/viewvc?rev=1759566&view=rev
Log:
Add requirement identifier in Landsat acquisition metadata.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/package-info.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/UtilitiesTest.java
    sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
    sis/branches/JDK8/storage/sis-earth-observation/src/test/java/org/apache/sis/storage/earthobservation/LandsatReaderTest.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/package-info.java?rev=1759566&r1=1759565&r2=1759566&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/package-info.java
[UTF-8] Wed Sep  7 08:59:55 2016
@@ -50,24 +50,24 @@
  * {@code  ├─} {@linkplain org.opengis.metadata.acquisition.GeometryType  Geometry type}<br>
  * {@code  └─} {@linkplain org.opengis.metadata.acquisition.OperationType Operation
type}<br>
  * </td><td class="sep" style="width: 50%; white-space: nowrap">
- *                             {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultAcquisitionInformation
Acquisition information}<br>
- * {@code  ├─}                 {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultObjective
             Objective}<br>
- * {@code  │   ├─}             {@linkplain org.opengis.metadata.acquisition.ObjectiveType
                       Objective type} «code list»<br>
- * {@code  │   ├─}             {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultPlatformPass
          Platform pass}<br>
- * {@code  │   │   └─}         {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultEvent
                 Event}<br>
- * {@code  │   │       ├─}     {@linkplain org.opengis.metadata.acquisition.Trigger
                             Trigger} «code list»<br>
- * {@code  │   │       ├─}     {@linkplain org.opengis.metadata.acquisition.Context
                             Context} «code list»<br>
- * {@code  │   │       └─}     {@linkplain org.opengis.metadata.acquisition.Sequence
                            Sequence} «code list»<br>
- * {@code  │   ├─}             {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultRequirement
           Requirement}<br>
- * {@code  │   │   ├─}         {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultRequestedDate
         Requested date}<br>
- * {@code  │   │   └─}         {@linkplain org.opengis.metadata.acquisition.Priority
                            Priority} «code list»<br>
- * {@code  │   └─}             {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultPlan
                  Plan}<br>
- * {@code  │       ├─}         {@linkplain org.opengis.metadata.acquisition.GeometryType
                        Geometry type} «code list»<br>
- * {@code  │       └─}         {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultOperation
             Operation}<br>
- * {@code  │           ├─}     {@linkplain org.opengis.metadata.acquisition.OperationType
                       Operation type} «code list»<br>
- * {@code  │           └─}     {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultPlatform
              Platform}<br>
- * {@code  │               └─} {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultInstrument
            Instrument}<br>
- * {@code  └─}                 {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultEnvironmentalRecord
   Environmental record}<br>
+ *                         {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultAcquisitionInformation
Acquisition information}<br>
+ * {@code  ├─}             {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultRequirement
           Requirement}<br>
+ * {@code  │   ├─}         {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultRequestedDate
         Requested date}<br>
+ * {@code  │   └─}         {@linkplain org.opengis.metadata.acquisition.Priority
                            Priority} «code list»<br>
+ * {@code  ├─}             {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultObjective
             Objective}<br>
+ * {@code  │   ├─}         {@linkplain org.opengis.metadata.acquisition.ObjectiveType
                       Objective type} «code list»<br>
+ * {@code  │   └─}         {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultPlatformPass
          Platform pass}<br>
+ * {@code  │       └─}     {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultEvent
                 Event}<br>
+ * {@code  │           ├─} {@linkplain org.opengis.metadata.acquisition.Trigger
                             Trigger} «code list»<br>
+ * {@code  │           ├─} {@linkplain org.opengis.metadata.acquisition.Context
                             Context} «code list»<br>
+ * {@code  │           └─} {@linkplain org.opengis.metadata.acquisition.Sequence
                            Sequence} «code list»<br>
+ * {@code  ├─}             {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultPlan
                  Plan}<br>
+ * {@code  │   ├─}         {@linkplain org.opengis.metadata.acquisition.GeometryType
                        Geometry type} «code list»<br>
+ * {@code  │   └─}         {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultOperation
             Operation}<br>
+ * {@code  │       ├─}     {@linkplain org.opengis.metadata.acquisition.OperationType
                       Operation type} «code list»<br>
+ * {@code  │       └─}     {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultPlatform
              Platform}<br>
+ * {@code  │           └─} {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultInstrument
            Instrument}<br>
+ * {@code  └─}             {@linkplain org.apache.sis.metadata.iso.acquisition.DefaultEnvironmentalRecord
   Environmental record}<br>
  * </td></tr></table>
  *
  * <div class="section">Null values, nil objects and collections</div>

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java?rev=1759566&r1=1759565&r2=1759566&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
[UTF-8] Wed Sep  7 08:59:55 2016
@@ -20,6 +20,7 @@ import java.util.Formatter;
 import java.util.FormattableFlags;
 import org.apache.sis.util.Static;
 import org.apache.sis.util.Classes;
+import org.apache.sis.util.Characters;
 import org.apache.sis.util.CharSequences;
 
 
@@ -55,11 +56,11 @@ public final class Utilities extends Sta
      *   <li>Note that {@code '_'} is valid both in {@code xsd:ID} and Unicode identifier.</li>
      * </ul>
      *
-     * @param  appendTo    The buffer where to append the valid characters.
-     * @param  separator   The separator to append before the valid characters, or 0 if none.
-     * @param  text        The text from which to get the valid character to append in the
given buffer.
-     * @param  accepted    Additional characters to accept (e.g. {@code "-."}), or an empty
string if none.
-     * @param  toLowerCase {@code true} for converting the characters to lower case.
+     * @param  appendTo     the buffer where to append the valid characters.
+     * @param  separator    the separator to append before the valid characters, or 0 if
none.
+     * @param  text         the text from which to get the valid character to append in the
given buffer.
+     * @param  accepted     additional characters to accept (e.g. {@code "-."}), or an empty
string if none.
+     * @param  toLowerCase  {@code true} for converting the characters to lower case.
      * @return {@code true} if at least one character has been added to the buffer.
      */
     public static boolean appendUnicodeIdentifier(final StringBuilder appendTo, final char
separator,
@@ -91,13 +92,57 @@ public final class Utilities extends Sta
     }
 
     /**
+     * Returns a string with the same content than the given string, but in upper case and
containing only the
+     * filtered characters. If the given string already matches the criterion, then it is
returned unchanged
+     * without creation of any temporary object.
+     *
+     * <p>This method is useful before call to an {@code Enum.valueOf(String)} method,
for making the search
+     * a little bit more tolerant.</p>
+     *
+     * <p>This method is not in public API because conversion to upper-cases should
be locale-dependent.</p>
+     *
+     * @param  text     the text to filter.
+     * @param  filter   the filter to apply.
+     * @return the filtered text.
+     *
+     * @since 0.8
+     */
+    public static String toUpperCase(final String text, final Characters.Filter filter) {
+        final int length = text.length();
+        int c, i = 0;
+        while (true) {
+            if (i >= length) {
+                return text;
+            }
+            c = text.codePointAt(i);
+            if (!filter.contains(c) || Character.toUpperCase(c) != c) {
+                break;
+            }
+            i += Character.charCount(c);
+        }
+        /*
+         * At this point we found that characters starting from index i does not match the
criterion.
+         * Copy what we have checked so far in the buffer, then add next characters one-by-one.
+         */
+        final StringBuilder buffer = new StringBuilder(length).append(text, 0, i);
+        while (i < length) {
+            c = text.codePointAt(i);
+            if (filter.contains(c)) {
+                buffer.appendCodePoint(Character.toUpperCase(c));
+            }
+            i += Character.charCount(c);
+        }
+        return buffer.toString();
+    }
+
+    /**
      * Returns a string representation of an instance of the given class having the given
properties.
      * This is a convenience method for implementation of {@link Object#toString()} methods
that are
      * used mostly for debugging purpose.
      *
-     * @param  classe     The class to format.
-     * @param  properties The (<var>key</var>=<var>value</var>) pairs.
-     * @return A string representation of an instance of the given class having the given
properties.
+     * @param  classe      the class to format.
+     * @param  properties  the (<var>key</var>=<var>value</var>)
pairs.
+     * @return a string representation of an instance of the given class having the given
properties.
      *
      * @since 0.4
      */
@@ -125,11 +170,11 @@ public final class Utilities extends Sta
      * Formats the given character sequence to the given formatter. This method takes in
account
      * the {@link FormattableFlags#UPPERCASE} and {@link FormattableFlags#LEFT_JUSTIFY} flags.
      *
-     * @param formatter The formatter in which to format the value.
-     * @param flags     The formatting flags.
-     * @param width     Minimal number of characters to write, padding with {@code ' '} if
necessary.
-     * @param precision Number of characters to keep before truncation, or -1 if no limit.
-     * @param value     The text to format.
+     * @param formatter  the formatter in which to format the value.
+     * @param flags      the formatting flags.
+     * @param width      minimal number of characters to write, padding with {@code ' '}
if necessary.
+     * @param precision  number of characters to keep before truncation, or -1 if no limit.
+     * @param value      the text to format.
      */
     public static void formatTo(final Formatter formatter, final int flags,
             int width, int precision, String value)
@@ -140,7 +185,7 @@ public final class Utilities extends Sta
         if (isUpperCase && width > 0) {
             // May change the string length in some locales.
             value = value.toUpperCase(formatter.locale());
-            isUpperCase = false; // Because conversion has already been done.
+            isUpperCase = false;                            // Because conversion has already
been done.
         }
         int length = value.length();
         if (precision >= 0) {

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/UtilitiesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/UtilitiesTest.java?rev=1759566&r1=1759565&r2=1759566&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/UtilitiesTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/UtilitiesTest.java
[UTF-8] Wed Sep  7 08:59:55 2016
@@ -17,9 +17,10 @@
 package org.apache.sis.internal.util;
 
 import org.apache.sis.test.TestCase;
+import org.apache.sis.util.Characters;
 import org.junit.Test;
 
-import static org.apache.sis.test.Assert.*;
+import static org.junit.Assert.*;
 
 
 /**
@@ -27,7 +28,7 @@ import static org.apache.sis.test.Assert
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.4
+ * @version 0.8
  * @module
  */
 public final strictfp class UtilitiesTest extends TestCase {
@@ -38,4 +39,15 @@ public final strictfp class UtilitiesTes
     public void testToString() {
         assertEquals("Number[base=“decimal”, value=20]", Utilities.toString(Number.class,
"base", "decimal", "value", 20));
     }
+
+    /**
+     * Tests the {@link Utilities#toUpperCase(String, Characters.Filter)} method.
+     */
+    @Test
+    public void testToUpperCase() {
+        final String expected = "WGS84";
+        assertSame  (expected, Utilities.toUpperCase(expected, Characters.Filter.LETTERS_AND_DIGITS));
+        assertEquals(expected, Utilities.toUpperCase("WGS 84", Characters.Filter.LETTERS_AND_DIGITS));
+        assertEquals(expected, Utilities.toUpperCase("wgs 84", Characters.Filter.LETTERS_AND_DIGITS));
+    }
 }

Modified: sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java?rev=1759566&r1=1759565&r2=1759566&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
[UTF-8] Wed Sep  7 08:59:55 2016
@@ -65,6 +65,7 @@ import org.apache.sis.internal.storage.M
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.util.StandardDateFormat;
 import org.apache.sis.internal.util.Constants;
+import org.apache.sis.internal.util.Utilities;
 
 import static java.util.Collections.singleton;
 import static org.apache.sis.internal.util.CollectionsExt.singletonOrNull;
@@ -463,7 +464,10 @@ final class LandsatReader {
              * Routing, and Metrics (TRAM) order number and UUUUU = 5-digit TRAM unit number.
              * Example: "0501403126384_00011"
              */
-// TODO     case "REQUEST_ID":
+            case "REQUEST_ID": {
+                metadata.addAcquisitionRequirement(value);
+                break;
+            }
             /*
              * The unique Landsat scene identifier.
              * Format is {@code Ls8ppprrrYYYYDDDGGGVV}.
@@ -741,13 +745,7 @@ final class LandsatReader {
              * We ignore the "ELLIPSOID" attribute because it is implied by the datum.
              */
             case "DATUM": {
-                for (final CommonCRS c : CommonCRS.values()) {
-                    if (CharSequences.equalsFiltered(c.name(), value, Characters.Filter.LETTERS_AND_DIGITS,
true)) {
-                        datum = c;
-                        return;
-                    }
-                }
-                listeners.warning(errors().getString(Errors.Keys.UnexpectedValueInElement_2,
value, key), null);
+                datum = CommonCRS.valueOf(Utilities.toUpperCase(value, Characters.Filter.LETTERS_AND_DIGITS));
                 break;
             }
             /*

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=1759566&r1=1759565&r2=1759566&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] Wed Sep  7 08:59:55 2016
@@ -278,6 +278,9 @@ public class LandsatReaderTest extends T
                 + "  │           └─Name\n"
                 + "  │               └─Code……………………………………………………………
TestImage_B11.TIF\n"
                 + "  ├─Acquisition information\n"
+                + "  │   ├─Acquisition requirement\n"
+                + "  │   │   └─Identifier\n"
+                + "  │   │       └─Code………………………………………………………………………
Software unit tests\n"
                 + "  │   ├─Operation\n"
                 + "  │   │   ├─Status……………………………………………………………………………
Completed\n"
                 + "  │   │   ├─Type…………………………………………………………………………………
Real\n"

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java?rev=1759566&r1=1759565&r2=1759566&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
[UTF-8] Wed Sep  7 08:59:55 2016
@@ -67,6 +67,7 @@ import org.apache.sis.metadata.iso.acqui
 import org.apache.sis.metadata.iso.acquisition.DefaultInstrument;
 import org.apache.sis.metadata.iso.acquisition.DefaultOperation;
 import org.apache.sis.metadata.iso.acquisition.DefaultPlatform;
+import org.apache.sis.metadata.iso.acquisition.DefaultRequirement;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.Utilities;
 import org.apache.sis.util.iso.Types;
@@ -1065,6 +1066,19 @@ parse:      for (int i = 0; i < length;)
         }
     }
 
+    /**
+     * Returns the identifier of the requirement to be satisfied by data acquisition.
+     *
+     * @param  identifier  requirement identifier, or {@code null}.
+     */
+    public final void addAcquisitionRequirement(String identifier) {
+        if (identifier != null && !(identifier = identifier.trim()).isEmpty()) {
+            final DefaultRequirement r = new DefaultRequirement();
+            r.setIdentifier(new DefaultIdentifier(identifier));
+            acquisition().getAcquisitionRequirements().add(r);
+        }
+    }
+
     /**
      * Sets the area of the dataset obscured by clouds, expressed as a percentage of the
spatial extent.
      * This method does nothing if the given value is {@link Double#NaN}.



Mime
View raw message