sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1405500 - in /sis/branches/JDK6: ./ sis-build-helper/src/main/java/org/apache/sis/util/resources/ sis-build-helper/src/site/apt/ sis-utility/src/main/java/org/apache/sis/internal/simple/ sis-utility/src/main/java/org/apache/sis/internal/ut...
Date Sun, 04 Nov 2012 04:53:29 GMT
Author: desruisseaux
Date: Sun Nov  4 04:53:29 2012
New Revision: 1405500

URL: http://svn.apache.org/viewvc?rev=1405500&view=rev
Log:
Merge from the JDK7 branch.

Added:
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/util/SurjectiveConverter.java
      - copied unchanged from r1405499, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/SurjectiveConverter.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/FormattedCharacterIterator.java
      - copied, changed from r1405499, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/FormattedCharacterIterator.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/FormattedCharacterIteratorTest.java
      - copied, changed from r1405499, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/FormattedCharacterIteratorTest.java
Modified:
    sis/branches/JDK6/   (props changed)
    sis/branches/JDK6/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java
    sis/branches/JDK6/sis-build-helper/src/main/java/org/apache/sis/util/resources/ResourceCompilerMojo.java
    sis/branches/JDK6/sis-build-helper/src/site/apt/index.apt
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleCharacterIterator.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/FormatField.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedIterator.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java

Propchange: sis/branches/JDK6/
------------------------------------------------------------------------------
  Merged /sis/branches/JDK7:r1405049-1405499

Modified: sis/branches/JDK6/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java?rev=1405500&r1=1405499&r2=1405500&view=diff
==============================================================================
--- sis/branches/JDK6/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java
(original)
+++ sis/branches/JDK6/sis-build-helper/src/main/java/org/apache/sis/util/resources/IndexedResourceCompiler.java
Sun Nov  4 04:53:29 2012
@@ -26,10 +26,10 @@ import java.util.regex.Pattern;
  * Reads a given list of {@code .properties} files and copies their content to {@code .utf}
files
  * using UTF-8 encoding. It also checks for key validity and checks values for {@link MessageFormat}
  * compatibility. Finally, it writes the key values in the Java source files.
- * <p>
- * This class is independent of any Mojo and could be executed from the command-line.
+ *
+ * <p>This class is independent of any Mojo and could be executed from the command-line.
  * For now we keep it package-private, but we could consider to enable execution from
- * the command-line in a future version if this happen to be useful.
+ * the command-line in a future version if this happen to be useful.</p>
  *
  * @author Martin Desruisseaux (IRD, Geomatys)
  * @since   0.3 (derived from geotk-1.2)
@@ -283,8 +283,8 @@ class IndexedResourceCompiler implements
      * conventions (i.e. resources expecting some arguments must have a key name ending with
      * {@code "_$n"} where {@code "n"} is the number of arguments). This method transforms
resource
      * values into legal {@link MessageFormat} patterns when necessary.
-     * <p>
-     * The following methods must be invoked before this one:
+     *
+     * <p>The following methods must be invoked before this one:</p>
      *
      * <ul>
      *   <li>{@link #initialize}</li>

Modified: sis/branches/JDK6/sis-build-helper/src/main/java/org/apache/sis/util/resources/ResourceCompilerMojo.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-build-helper/src/main/java/org/apache/sis/util/resources/ResourceCompilerMojo.java?rev=1405500&r1=1405499&r2=1405500&view=diff
==============================================================================
--- sis/branches/JDK6/sis-build-helper/src/main/java/org/apache/sis/util/resources/ResourceCompilerMojo.java
(original)
+++ sis/branches/JDK6/sis-build-helper/src/main/java/org/apache/sis/util/resources/ResourceCompilerMojo.java
Sun Nov  4 04:53:29 2012
@@ -55,6 +55,16 @@ public class ResourceCompilerMojo extend
     private String outputDirectory;
 
     /**
+     * The <code>compileSourceRoots</code> named "java" as a <code>File</code>.
+     */
+    private File javaDirectoryFile;
+
+    /**
+     * The <code>outputDirectory</code> as a <code>File</code>.
+     */
+    private File outputDirectoryFile;
+
+    /**
      * Executes the mojo.
      *
      * @throws MojoExecutionException if the plugin execution failed.
@@ -63,14 +73,12 @@ public class ResourceCompilerMojo extend
     @SuppressWarnings({"unchecked","rawtypes"}) // Generic array creation.
     public void execute() throws MojoExecutionException {
         int errors = 0;
-        final File target = new File(outputDirectory);
+        outputDirectoryFile = new File(outputDirectory);
         for (final String sourceDirectory : compileSourceRoots) {
-            File directory = new File(sourceDirectory);
+            final File directory = new File(sourceDirectory);
             if (directory.getName().equals("java")) {
-                final File[] resourcesToProcess = new File(sourceDirectory, "org/apache/sis/util/resources").listFiles(this);
-                if (resourcesToProcess != null && resourcesToProcess.length != 0)
{
-                    errors += new Compiler(directory, target, resourcesToProcess).run();
-                }
+                javaDirectoryFile = directory;
+                errors += processAllResourceDirectories(directory);
             }
         }
         if (errors != 0) {
@@ -79,6 +87,27 @@ public class ResourceCompilerMojo extend
     }
 
     /**
+     * Recursively scans the directories for a sub-package named "resources",
+     * then invokes the resource compiler for that directory.
+     */
+    private int processAllResourceDirectories(final File directory) throws ResourceCompilerException
{
+        int errors = 0;
+        for (final File subdir : directory.listFiles()) {
+            if (subdir.isDirectory()) {
+                if (subdir.getName().equals("resources")) {
+                    final File[] resourcesToProcess = subdir.listFiles(this);
+                    if (resourcesToProcess != null && resourcesToProcess.length !=
0) {
+                        errors += new Compiler(resourcesToProcess).run();
+                    }
+                } else {
+                    errors += processAllResourceDirectories(subdir);
+                }
+            }
+        }
+        return errors;
+    }
+
+    /**
      * Returns {@code true} if the given file is the source code for a resources bundle.
      * This method returns {@code true} if the given file is a Java source file and if a
      * properties file of the same name exists.
@@ -101,8 +130,8 @@ public class ResourceCompilerMojo extend
      * A resource compiler that delegates the messages to the Mojo logger.
      */
     private final class Compiler extends IndexedResourceCompiler {
-        public Compiler(File sourceDirectory, File buildDirectory, File[] resourcesToProcess)
{
-            super(sourceDirectory, buildDirectory, resourcesToProcess);
+        public Compiler(File[] resourcesToProcess) {
+            super(javaDirectoryFile, outputDirectoryFile, resourcesToProcess);
         }
 
         /**

Modified: sis/branches/JDK6/sis-build-helper/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-build-helper/src/site/apt/index.apt?rev=1405500&r1=1405499&r2=1405500&view=diff
==============================================================================
--- sis/branches/JDK6/sis-build-helper/src/site/apt/index.apt (original)
+++ sis/branches/JDK6/sis-build-helper/src/site/apt/index.apt Sun Nov  4 04:53:29 2012
@@ -50,7 +50,7 @@ Building Apache SIS
 
   The resource compiler is executed at Maven build time if the <<<pom.xml>>>
file
   contains the following declaration. Note that current implementation looks only for resources
-  in the <<<org.apache.sis.util.resources>>> package; all other packages
are ignored.
+  in any package ending with the <<<resources>>> name; all other packages
are ignored.
 
 +-----------------------------------------------------
 <build>

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleCharacterIterator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleCharacterIterator.java?rev=1405500&r1=1405499&r2=1405500&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleCharacterIterator.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleCharacterIterator.java
Sun Nov  4 04:53:29 2012
@@ -51,8 +51,10 @@ public class SimpleCharacterIterator imp
 
     /**
      * The upper index (index after the last character that we can return).
+     * This field is not final because some classes need to update it, for
+     * example if {@link #text} is a growing {@link StringBuffer}.
      */
-    protected final int upper;
+    protected int upper;
 
     /**
      * The index of the next character to be returned by the iterator.
@@ -198,6 +200,6 @@ public class SimpleCharacterIterator imp
      */
     @Override
     public final String toString() {
-        return text.toString();
+        return text.subSequence(lower, upper).toString();
     }
 }

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java?rev=1405500&r1=1405499&r2=1405500&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java Sun
Nov  4 04:53:29 2012
@@ -24,6 +24,7 @@ import java.text.ParseException;
 import java.text.NumberFormat;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
+import java.text.AttributedCharacterIterator;
 import net.jcip.annotations.NotThreadSafe;
 
 import org.apache.sis.util.Debug;
@@ -222,6 +223,19 @@ public class AngleFormat extends Format 
          * constructor in order to get the bounding index where hemisphere have been written.
          */
         public static final Field HEMISPHERE = new Field("HEMISPHERE", HEMISPHERE_FIELD);
+
+        /**
+         * Returns the field constant for the given numeric identifier.
+         */
+        static Field forCode(final int field) {
+            switch (field) {
+                case DEGREES_FIELD:    return DEGREES;
+                case MINUTES_FIELD:    return MINUTES;
+                case SECONDS_FIELD:    return SECONDS;
+                case HEMISPHERE_FIELD: return HEMISPHERE;
+                default: throw new AssertionError(field);
+            }
+        }
     }
 
     /**
@@ -283,7 +297,17 @@ public class AngleFormat extends Format 
      *
      * @see #dummyFieldPosition()
      */
-    private transient FieldPosition dummy;
+    private transient FieldPosition dummyFieldPosition;
+
+    /**
+     * A temporary variable which may be set to the character iterator for which the
+     * attributes need to be set. IF non-null, then this is actually an instance of
+     * {@link FormattedCharacterIterator}. But we use the interface here for avoiding
+     * too early class loading.
+     *
+     * @see #formatToCharacterIterator(Object)
+     */
+    private transient AttributedCharacterIterator characterIterator;
 
     /**
      * Returns the number format, created when first needed.
@@ -299,10 +323,10 @@ public class AngleFormat extends Format 
      * Returns the dummy field position.
      */
     private FieldPosition dummyFieldPosition() {
-        if (dummy == null) {
-            dummy = new FieldPosition(-1);
+        if (dummyFieldPosition == null) {
+            dummyFieldPosition = new FieldPosition(NumberFormat.INTEGER_FIELD);
         }
-        return dummy;
+        return dummyFieldPosition;
     }
 
     /**
@@ -831,6 +855,8 @@ scan:   for (int i=0; i<length;) {
         }
         /*
          * Formats fields in a loop from DEGREES_FIELD to SECONDS_FIELD inclusive.
+         * The first part of the loop will configure the NumberFormat, but without
+         * writing anything yet (ignoring the prefix written before the loop).
          */
         int field = DEGREES_FIELD;
         if (prefix != null) {
@@ -848,11 +874,9 @@ scan:   for (int i=0; i<length;) {
                 case SECONDS_FIELD: value=seconds; width=secondsFieldWidth; suffix=secondsSuffix;
hasMore=false; break;
                 default: throw new AssertionError(field);
             }
-            final int startPosition = toAppendTo.length();
             if (hasMore) {
                 numberFormat.setMinimumIntegerDigits(width);
                 numberFormat.setMaximumFractionDigits(0);
-                toAppendTo = numberFormat.format(value, toAppendTo, dummyFieldPosition());
             } else if (useDecimalSeparator) {
                 numberFormat.setMinimumIntegerDigits(width);
                 if (maximumTotalWidth != 0) {
@@ -875,19 +899,34 @@ scan:   for (int i=0; i<length;) {
                 }
                 numberFormat.setMinimumFractionDigits(minimumFractionDigits);
                 numberFormat.setMaximumFractionDigits(maximumFractionDigits);
-                toAppendTo = numberFormat.format(value, toAppendTo, dummyFieldPosition());
             } else {
                 value *= pow10(fractionFieldWidth);
                 numberFormat.setMaximumFractionDigits(0);
                 numberFormat.setMinimumIntegerDigits(width + fractionFieldWidth);
-                toAppendTo = numberFormat.format(value, toAppendTo, dummyFieldPosition());
             }
-            if (suffix != null) {
-                toAppendTo.append(suffix);
+            /*
+             * At this point, we known the value to format and the NumberFormat instance
has been
+             * configured. If the user asked for an attributed character iterator and assuming
that
+             * we want also the attributes produced by the NumberFormat, then we have to
invoke the
+             * heavy formatToCharacterIterator(…). Otherwise the usual format(…)
method fits well.
+             */
+            final int startPosition = toAppendTo.length();
+            if (characterIterator instanceof FormattedCharacterIterator) {
+                final FormattedCharacterIterator it = (FormattedCharacterIterator) characterIterator;
+                it.append(numberFormat.formatToCharacterIterator(value), toAppendTo);
+                if (suffix != null) {
+                    toAppendTo.append(suffix);
+                }
+                it.addFieldLimit(Field.forCode(field), Integer.valueOf((int) value), startPosition);
+            } else {
+                toAppendTo = numberFormat.format(value, toAppendTo, dummyFieldPosition());
+                if (suffix != null) {
+                    toAppendTo.append(suffix);
+                }
             }
             if (field == fieldPos) {
                 pos.setBeginIndex(startPosition);
-                pos.setEndIndex(toAppendTo.length() - 1);
+                pos.setEndIndex(toAppendTo.length());
             }
             field++;
         } while (hasMore);
@@ -950,16 +989,78 @@ scan:   for (int i=0; i<length;) {
             final FieldPosition pos, final char positiveSuffix, final char negativeSuffix)
     {
         toAppendTo = format(abs(angle), toAppendTo, pos);
-        final int start = toAppendTo.length();
-        toAppendTo.append(isNegative(angle) ? negativeSuffix : positiveSuffix);
+        final int startPosition = toAppendTo.length();
+        final char suffix = isNegative(angle) ? negativeSuffix : positiveSuffix;
+        toAppendTo.append(suffix);
         if (getField(pos) == HEMISPHERE_FIELD) {
-            pos.setBeginIndex(start);
-            pos.setEndIndex(toAppendTo.length()-1);
+            pos.setBeginIndex(startPosition);
+            pos.setEndIndex(toAppendTo.length());
+        }
+        if (characterIterator instanceof FormattedCharacterIterator) {
+            ((FormattedCharacterIterator) characterIterator).addFieldLimit(
+                    Field.HEMISPHERE, suffix, startPosition);
         }
         return toAppendTo;
     }
 
     /**
+     * Formats an angle, latitude or longitude value as an attributed character iterator.
+     * Callers can iterator over the returned iterator and queries the attribute values as
+     * in the following example:
+     *
+     * {@preformat java
+     *     AttributedCharacterIterator it = angleFormat.formatToCharacterIterator(myAngle);
+     *     for (char c=it.first(); c!=AttributedCharacterIterator.DONE; c=c.next()) {
+     *         // 'c' is a character from the formatted string.
+     *         if (it.getAttribute(AngleFormat.Field.MINUTES) != null) {
+     *             // If we enter this block, then the character 'c' is part of the minutes
field,
+     *             // This field extends from it.getRunStart(MINUTES) to it.getRunLimit(MINUTES).
+     *         }
+     *     }
+     * }
+     *
+     * Alternatively, if the current {@linkplain AttributedCharacterIterator#getIndex() iterator
+     * index} is before the start of the minutes field, then the starting position of that
field
+     * can be obtained directly by {@code it.getRunLimit(MINUTES)}. If the current iterator
index
+     * is inside the minutes field, then the above method call will rather returns the end
of that
+     * field. The same strategy works for other all fields too.
+     *
+     * <p>The returned character iterator contains all {@link java.text.NumberFormat.Field}
+     * attributes in addition to the {@link Field} ones. Consequently the same character
may
+     * have more than one attribute. For example when formatting 45°30′15.0″N,
then:</p>
+     *
+     * <ul>
+     *   <li>The {@code 45°}   part has the {@link Field#DEGREES} attribute.</li>
+     *   <li>The {@code 30′}   part has the {@link Field#MINUTES} attribute.</li>
+     *   <li>The {@code 15.0″} part has the {@link Field#SECONDS} attribute.</li>
+     *   <li>The {@code N}     part has the {@link Field#HEMISPHERE} attribute.</li>
+     *   <li>The {@code 45}, {@code 30} and {@code 15} parts have the
+     *       {@link java.text.NumberFormat.Field#INTEGER} attribute.</li>
+     *   <li>The {@code .} part has the {@link java.text.NumberFormat.Field#DECIMAL_SEPARATOR}
attribute.</li>
+     *   <li>The last {@code 0} part has the {@link java.text.NumberFormat.Field#FRACTION}
attribute.</li>
+     * </ul>
+     *
+     * In Apache SIS implementation, the returned character iterator also implements the
+     * {@link CharSequence} interface for convenience.
+     *
+     * @param  value {@link Angle} object to format.
+     * @return A character iterator together with the attributes describing the formatted
value.
+     * @throws IllegalArgumentException if {@code value} if not an instance of {@link Angle}.
+     */
+    @Override
+    public AttributedCharacterIterator formatToCharacterIterator(final Object value) {
+        final StringBuffer buffer = new StringBuffer(20);
+        final FormattedCharacterIterator it = new FormattedCharacterIterator(buffer);
+        try {
+            characterIterator = it;
+            format(value, buffer, null);
+        } finally {
+            characterIterator = null;
+        }
+        return it;
+    }
+
+    /**
      * Ignores a field suffix, then returns the identifier of the suffix just skipped.
      * This method is invoked by {@link #parse(String, ParsePosition)} for determining
      * what was the field it just parsed. For example if we just parsed "48°12'", then
@@ -1512,7 +1613,7 @@ BigBoss:    switch (skipSuffix(source, p
     public AngleFormat clone() {
         final AngleFormat clone = (AngleFormat) super.clone();
         clone.numberFormat = null;
-        clone.dummy = null;
+        clone.dummyFieldPosition = null;
         return clone;
     }
 

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/FormatField.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/FormatField.java?rev=1405500&r1=1405499&r2=1405500&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/FormatField.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/FormatField.java Sun
Nov  4 04:53:29 2012
@@ -28,13 +28,19 @@ import java.text.Format;
  * @version 0.3
  * @module
  */
-abstract class FormatField extends Format.Field {
+class FormatField extends Format.Field {
     /**
      * Serial number for cross-version compatibility.
      */
     private static final long serialVersionUID = -5344437554919766622L;
 
     /**
+     * A sentinel value for {@link FormattedCharacterIterator} internal usage only,
+     * meaning that all attributes shall be taken in account while computing a run range.
+     */
+    static final FormatField ALL = new FormatField("ALL", 0);
+
+    /**
      * The numeric {@code *_FIELD} value for this constant. This value doesn't need to
      * be serialized, because {@link #readResolve()} will locate the original constant
      * on deserialization.

Copied: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/FormattedCharacterIterator.java
(from r1405499, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/FormattedCharacterIterator.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/FormattedCharacterIterator.java?p2=sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/FormattedCharacterIterator.java&p1=sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/FormattedCharacterIterator.java&r1=1405499&r2=1405500&rev=1405500&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/FormattedCharacterIterator.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/FormattedCharacterIterator.java
Sun Nov  4 04:53:29 2012
@@ -156,7 +156,7 @@ final class FormattedCharacterIterator e
      */
     FormattedCharacterIterator(final CharSequence text) {
         super(text);
-        attributes = new IdentityHashMap<>(8);
+        attributes = new IdentityHashMap<Attribute,Entry>(8);
     }
 
     /**
@@ -315,7 +315,7 @@ final class FormattedCharacterIterator e
      * {@code getRunStart(Set)} and {@code getRunLimit(Set)} methods.
      */
     private Collection<Entry> entries(final Set<? extends Attribute> requested)
{
-        final Collection<Entry> entries = new ArrayList<>(requested.size());
+        final Collection<Entry> entries = new ArrayList<Entry>(requested.size());
         for (final Attribute r : requested) {
             final Entry e = attributes.get(r);
             if (e != null) {

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedIterator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedIterator.java?rev=1405500&r1=1405499&r2=1405500&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedIterator.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/DerivedIterator.java
Sun Nov  4 04:53:29 2012
@@ -26,7 +26,7 @@ import org.apache.sis.util.ObjectConvert
  * If a value is converted into a null value, then this iterator skips that value.
  * Consequently this iterator can not returns null value.
  *
- * @param <B> The type of elements in the backing set.
+ * @param <S> The type of elements in the storage collection.
  * @param <E> The type of elements in this set.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
@@ -35,16 +35,16 @@ import org.apache.sis.util.ObjectConvert
  * @module
  */
 @Decorator(Iterator.class)
-final class DerivedIterator<B,E> implements Iterator<E> {
+final class DerivedIterator<S,E> implements Iterator<E> {
     /**
      * The original iterator to wrap.
      */
-    private final Iterator<B> iterator;
+    private final Iterator<S> iterator;
 
     /**
      * The converter from the original values to the converted values.
      */
-    private final ObjectConverter<B,E> converter;
+    private final ObjectConverter<S,E> converter;
 
     /**
      * The next element to be returned, or {@code null}.
@@ -55,7 +55,7 @@ final class DerivedIterator<B,E> impleme
      * Creates a new iterator wrapping the given original iterator and converting the
      * values using the given converter.
      */
-    DerivedIterator(final Iterator<B> iterator, ObjectConverter<B,E> converter)
{
+    DerivedIterator(final Iterator<S> iterator, ObjectConverter<S,E> converter)
{
         this.iterator  = iterator;
         this.converter = converter;
     }

Modified: sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java?rev=1405500&r1=1405499&r2=1405500&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
(original)
+++ sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
Sun Nov  4 04:53:29 2012
@@ -17,6 +17,8 @@
 package org.apache.sis.measure;
 
 import java.util.Locale;
+import java.text.FieldPosition;
+import java.text.AttributedCharacterIterator;
 import org.apache.sis.test.TestCase;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.DependsOnMethod;
@@ -34,7 +36,10 @@ import static org.apache.sis.test.TestUt
  * @version 0.3
  * @module
  */
-@DependsOn(org.apache.sis.math.MathFunctionsTest.class)
+@DependsOn({
+  FormattedCharacterIteratorTest.class,
+  org.apache.sis.math.MathFunctionsTest.class
+})
 public final strictfp class AngleFormatTest extends TestCase {
     /**
      * Tests a pattern with illegal usage of D, M and S symbols.
@@ -197,4 +202,44 @@ public final strictfp class AngleFormatT
         assertEquals("8°",  f.format(new Angle( 8.123456)));
         assertEquals("20°", f.format(new Angle(20.123456)));
     }
+
+    /**
+     * Tests the field position while formatting an angle.
+     */
+    @Test
+    public void testFieldPosition() {
+        final Latitude latitude = new Latitude(FormattedCharacterIteratorTest.LATITUDE_VALUE);
+        final AngleFormat f = new AngleFormat("DD°MM′SS.s″", Locale.CANADA);
+        final StringBuffer buffer = new StringBuffer(12);
+        for (int i=AngleFormat.DEGREES_FIELD; i<=AngleFormat.HEMISPHERE_FIELD; i++) {
+            final AngleFormat.Field field;
+            final int start, limit;
+            switch (i) {
+                case AngleFormat.DEGREES_FIELD:    field = AngleFormat.Field.DEGREES;   
start= 0; limit= 3;  break;
+                case AngleFormat.MINUTES_FIELD:    field = AngleFormat.Field.MINUTES;   
start= 3; limit= 6;  break;
+                case AngleFormat.SECONDS_FIELD:    field = AngleFormat.Field.SECONDS;   
start= 6; limit=11; break;
+                case AngleFormat.HEMISPHERE_FIELD: field = AngleFormat.Field.HEMISPHERE;
start=11; limit=12; break;
+                default: continue; // Skip the fraction field.
+            }
+            final FieldPosition pos = new FieldPosition(field);
+            assertEquals(FormattedCharacterIteratorTest.LATITUDE_STRING, f.format(latitude,
buffer, pos).toString());
+            assertSame  ("getFieldAttribute", field, pos.getFieldAttribute());
+            assertEquals("getBeginIndex",     start, pos.getBeginIndex());
+            assertEquals("getEndIndex",       limit, pos.getEndIndex());
+            buffer.setLength(0);
+        }
+    }
+
+    /**
+     * Tests the {@link AngleFormat#formatToCharacterIterator(Object)} method.
+     */
+    @Test
+    @DependsOnMethod("testFieldPosition")
+    public void testFormatToCharacterIterator() {
+        final Latitude latitude = new Latitude(FormattedCharacterIteratorTest.LATITUDE_VALUE);
+        final AngleFormat f = new AngleFormat("DD°MM′SS.s″", Locale.CANADA);
+        final AttributedCharacterIterator it = f.formatToCharacterIterator(latitude);
+        assertEquals(FormattedCharacterIteratorTest.LATITUDE_STRING, it.toString());
+        FormattedCharacterIteratorTest.testAttributes(it, true);
+    }
 }

Copied: sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/FormattedCharacterIteratorTest.java
(from r1405499, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/FormattedCharacterIteratorTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/FormattedCharacterIteratorTest.java?p2=sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/FormattedCharacterIteratorTest.java&p1=sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/FormattedCharacterIteratorTest.java&r1=1405499&r2=1405500&rev=1405500&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/FormattedCharacterIteratorTest.java
(original)
+++ sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/FormattedCharacterIteratorTest.java
Sun Nov  4 04:53:29 2012
@@ -112,7 +112,7 @@ public final strictfp class FormattedCha
      * @param overlapping {@code true} for including the keys for overlapping attributes.
      */
     private static Set<Attribute> getAllAttributeKeys(final boolean overlapping) {
-        final Set<Attribute> keys = new HashSet<>(8);
+        final Set<Attribute> keys = new HashSet<Attribute>(8);
         assertTrue(keys.add(DEGREES));
         assertTrue(keys.add(MINUTES));
         assertTrue(keys.add(SECONDS));

Modified: sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1405500&r1=1405499&r2=1405500&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
(original)
+++ sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
Sun Nov  4 04:53:29 2012
@@ -58,6 +58,7 @@ import org.junit.runners.Suite;
   org.apache.sis.util.type.DefaultInternationalStringTest.class,
 
   // Formatting
+  org.apache.sis.measure.FormattedCharacterIteratorTest.class,
   org.apache.sis.measure.AngleFormatTest.class,
   org.apache.sis.measure.AngleTest.class,
   org.apache.sis.internal.util.X364Test.class,



Mime
View raw message