sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1457022 - in /sis/branches/JDK7/sis-utility/src: main/java/org/apache/sis/internal/converter/ test/java/org/apache/sis/internal/converter/
Date Fri, 15 Mar 2013 17:10:21 GMT
Author: desruisseaux
Date: Fri Mar 15 17:10:21 2013
New Revision: 1457022

URL: http://svn.apache.org/r1457022
Log:
Consolidation: remove static constants or make them private.

Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FallbackConverter.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/NumberConverter.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/ObjectToString.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/ConverterRegistryTest.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FallbackConverterTest.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FileConverterTest.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URIConverterTest.java
    sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URLConverterTest.java

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FallbackConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FallbackConverter.java?rev=1457022&r1=1457021&r2=1457022&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FallbackConverter.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/FallbackConverter.java [UTF-8] Fri Mar 15 17:10:21 2013
@@ -26,6 +26,7 @@ import org.apache.sis.util.ObjectConvert
 import org.apache.sis.math.FunctionProperty;
 import org.apache.sis.util.UnconvertibleObjectException;
 import org.apache.sis.util.collection.TreeTable;
+import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.Debug;
 
 
@@ -153,6 +154,8 @@ final class FallbackConverter<S,T> exten
                   final ObjectConverter<S, ? extends T> primary,
                   final ObjectConverter<S, ? extends T> fallback)
     {
+        ArgumentChecks.ensureNonNull("primary",  primary);
+        ArgumentChecks.ensureNonNull("fallback", fallback);
         assert !(fallback instanceof FallbackConverter<?,?>) : fallback; // See javadoc
         final ObjectConverter<S, ? extends T> candidate = mergeIfSubtype(primary, fallback, null);
         if (candidate != null) {

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/NumberConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/NumberConverter.java?rev=1457022&r1=1457021&r2=1457022&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/NumberConverter.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/NumberConverter.java [UTF-8] Fri Mar 15 17:10:21 2013
@@ -21,7 +21,9 @@ import java.util.EnumSet;
 import net.jcip.annotations.Immutable;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.math.FunctionProperty;
+import org.apache.sis.util.ObjectConverter;
 import org.apache.sis.util.UnconvertibleObjectException;
+import org.apache.sis.util.resources.Errors;
 
 
 /**
@@ -55,6 +57,11 @@ final class NumberConverter<S extends Nu
     private static final long serialVersionUID = -8715054480508622025L;
 
     /**
+     * The inverse converter, created when first needed.
+     */
+    private transient volatile ObjectConverter<T,S> inverse;
+
+    /**
      * Creates a new converter for the given source and target classes.
      * This constructor does not verify the validity of parameter values.
      * It is caller's responsibility to ensure that the given class are
@@ -65,6 +72,22 @@ final class NumberConverter<S extends Nu
     }
 
     /**
+     * Returns the inverse converter, creating it when first needed.
+     */
+    @Override
+    public ObjectConverter<T,S> inverse() throws UnsupportedOperationException {
+        // No need to synchronize. This is not a big deal if the same object is fetched twice.
+        // The ConverterRegistry clas provides the required synchronization.
+        ObjectConverter<T,S> candidate = inverse;
+        if (candidate == null) try {
+            inverse = candidate = HeuristicRegistry.SYSTEM.findExact(targetClass, sourceClass);
+        } catch (UnconvertibleObjectException e) {
+            throw new UnsupportedOperationException(Errors.format(Errors.Keys.NonInvertibleConversion), e);
+        }
+        return candidate;
+    }
+
+    /**
      * Declares this converter as a injective or surjective function,
      * depending on whether conversions loose information or not.
      */

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/ObjectToString.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/ObjectToString.java?rev=1457022&r1=1457021&r2=1457022&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/ObjectToString.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/ObjectToString.java [UTF-8] Fri Mar 15 17:10:21 2013
@@ -16,21 +16,25 @@
  */
 package org.apache.sis.internal.converter;
 
-import java.util.Locale;
-import java.io.File;
-import java.net.URI;
-import java.net.URL;
-import java.io.Serializable;
-import java.io.ObjectStreamException;
-import org.opengis.util.InternationalString;
+import java.util.Set;
+import java.util.EnumSet;
 import net.jcip.annotations.Immutable;
 import org.apache.sis.util.ObjectConverter;
+import org.apache.sis.math.FunctionProperty;
 
 
 /**
  * Handles conversions from arbitrary objects to {@link String}. This converter is
  * suitable to any object for which the {@link #toString()} method is sufficient.
  *
+ * <p>Some pre-defined unique instances of {@code ObjectToString} are available
+ * by the following pattern:</p>
+ *
+ * {@preformat java
+ *     Class<S> sourceClass = ...;
+ *     ObjectConverter<S,String> c = StringConverter.getInstance(sourceClass).inverse();
+ * }
+ *
  * @param <S> The source type.
  *
  * @author  Martin Desruisseaux (Geomatys)
@@ -39,95 +43,32 @@ import org.apache.sis.util.ObjectConvert
  * @module
  */
 @Immutable
-class ObjectToString<S> extends InjectiveConverter<S,String> implements Serializable {
+class ObjectToString<S> extends SystemConverter<S,String> {
     /**
      * For cross-version compatibility.
      */
     private static final long serialVersionUID = 1460382215827540172L;
 
     /**
-     * The shared instance for international strings.
-     */
-    static final ObjectToString<InternationalString> I18N = new ObjectToString<>(InternationalString.class, StringConverter.InternationalString.INSTANCE);
-
-    /**
-     * The shared instance for numbers. {@link ConverterRegistry} needs only the {@link Number}
-     * type. Other subtypes are created only by {@code StringConverter.Foo.inverse()} methods.
-     */
-    static final ObjectToString<Number> NUMBER = new ObjectToString<>(Number.class, StringConverter.Number.INSTANCE);
-
-    /**
-     * The shared instance for booleans.
-     */
-    static final ObjectToString<Boolean> BOOLEAN = new ObjectToString<>(Boolean.class, StringConverter.Boolean.INSTANCE);
-
-    /**
-     * The shared instance for URI.
-     * This converter does not encode the string, i.e. the conversion is performed with
-     * the {@link URI#toString()} method rather than {@link URI#toASCIIString()}. We do
-     * that in order to avoid too many transformations if we convert back and forward to
-     * {@code String}.
-     */
-    static final ObjectToString<File> FILE = new ObjectToString<>(File.class, StringConverter.File.INSTANCE);
-
-    /**
-     * The shared instance for URI.
-     * This converter does not encode the string, i.e. the conversion is performed with
-     * the {@link URI#toString()} method rather than {@link URI#toASCIIString()}. We do
-     * that in order to avoid too many transformations if we convert back and forward to
-     * {@code String}.
-     */
-    static final ObjectToString<URI> URI = new ObjectToString<>(URI.class, StringConverter.URI.INSTANCE);
-
-    /**
-     * The shared instance for URL.
-     * This converter does not encode the string. We do that in order to avoid too many
-     * transformations if we convert back and forward to {@code String}.
-     */
-    static final ObjectToString<URL> URL = new ObjectToString<>(URL.class, StringConverter.URL.INSTANCE);
-
-    /**
-     * The shared instance for locales.
-     */
-    static final ObjectToString<Locale> LOCALE = new ObjectToString<>(Locale.class, StringConverter.Locale.INSTANCE);
-
-    /**
-     * The shared instance for character sets.
-     */
-    static final ObjectToString<java.nio.charset.Charset> CHARSET = new Charset();
-
-    /**
-     * The source class.
-     */
-    private final Class<S> sourceClass;
-
-    /**
      * The inverse converter specified at construction time.
      */
-    private final ObjectConverter<String, S> inverse;
+    private final SystemConverter<String, S> inverse;
 
     /**
      * Creates a new converter from the given type of objects to {@code String} instances.
      */
-    ObjectToString(final Class<S> sourceClass, final ObjectConverter<String, S> inverse) {
-        this.sourceClass = sourceClass;
+    ObjectToString(final Class<S> sourceClass, final SystemConverter<String, S> inverse) {
+        super(sourceClass, String.class);
         this.inverse = inverse;
     }
 
     /**
-     * Returns the source class given at construction time.
+     * Declares this converter as injective on the assumption that all instances
+     * of the source class produce distinct string representations.
      */
     @Override
-    public final Class<S> getSourceClass() {
-        return sourceClass;
-    }
-
-    /**
-     * Returns the destination type (same for all instances of this class).
-     */
-    @Override
-    public final Class<String> getTargetClass() {
-        return String.class;
+    public Set<FunctionProperty> properties() {
+        return EnumSet.of(FunctionProperty.INJECTIVE, FunctionProperty.INVERTIBLE);
     }
 
     /**
@@ -147,34 +88,39 @@ class ObjectToString<S> extends Injectiv
     }
 
     /**
-     * Returns the singleton instance on deserialization.
+     * Returns the singleton instance on deserialization, if any.
      */
-    final Object readResolve() throws ObjectStreamException {
-        if (sourceClass == InternationalString.class) return I18N;
-        if (sourceClass == Number .class) return NUMBER;
-        if (sourceClass == Boolean.class) return BOOLEAN;
-        if (sourceClass == File   .class) return FILE;
-        if (sourceClass == URI    .class) return URI;
-        if (sourceClass == URL    .class) return URL;
-        if (sourceClass == Locale .class) return LOCALE;
-        if (sourceClass == java.nio.charset.Charset.class) return CHARSET;
+    @Override
+    public ObjectConverter<S, String> unique() {
+        if (inverse != null) {
+            return inverse.unique().inverse(); // Will typically delegate to StringConverter.
+        }
         return this;
     }
 
 
     /**
-     * Specialized instance for {@link java.nio.charset.Charset}.
-     * This class invokes {@java.nio.charset.Charset#name()} instead than {@code toString()}.
+     * Specialized instance for {@link org.opengis.util.CodeList}.
+     * This class invokes {@link org.opengis.util.CodeList#name()} instead than {@code toString()}.
+     *
+     * @see org.apache.sis.internal.converter.StringConverter.CodeList
      */
-    private static final class Charset extends ObjectToString<java.nio.charset.Charset> {
+    static final class CodeList<S extends org.opengis.util.CodeList<S>> extends ObjectToString<S> {
         private static final long serialVersionUID = 1313285261794842777L;
 
-        Charset() {
-            super(java.nio.charset.Charset.class, StringConverter.Charset.INSTANCE);
+        /** Creates a new converter from the given type of code list to strings. */
+        CodeList(final Class<S> sourceClass, final SystemConverter<String, S> inverse) {
+            super(sourceClass, inverse);
+        }
+
+        /** Function is bijective, because no duplicated code list name shall exist. */
+        @Override public Set<FunctionProperty> properties() {
+            return EnumSet.of(FunctionProperty.INJECTIVE, FunctionProperty.SURJECTIVE,
+                    FunctionProperty.INVERTIBLE);
         }
 
-        @Override
-        public String convert(final java.nio.charset.Charset source) {
+        /** Returns the name of the given code list element. */
+        @Override public String convert(final S source) {
             return (source != null) ? source.name() : null;
         }
     }

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java?rev=1457022&r1=1457021&r2=1457022&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java [UTF-8] Fri Mar 15 17:10:21 2013
@@ -18,8 +18,6 @@ package org.apache.sis.internal.converte
 
 import java.util.Set;
 import java.util.EnumSet;
-import java.io.Serializable;
-import java.io.ObjectStreamException;
 import java.nio.charset.UnsupportedCharsetException;
 import java.net.URISyntaxException;
 import java.net.MalformedURLException;
@@ -37,13 +35,9 @@ import org.apache.sis.util.iso.SimpleInt
 
 
 /**
- * Handles conversions from {@link String} to various objects.
- * The source class is fixed to {@code String}. The target class is determined
- * by the inner class which extends this {@code StringConverter}.
- *
- * <p>All subclasses will have a unique instance. For this reason, it is not necessary to
- * override the {@code hashCode()} and {@code equals(Object)} methods, since identity
- * comparisons will work just well.</p>
+ * Handles conversions between {@link String} and various kinds of objects.
+ * Each inner class in this {@code StringConverter} class defines both the
+ * forward and the inverse converters.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.4)
@@ -51,24 +45,75 @@ import org.apache.sis.util.iso.SimpleInt
  * @module
  */
 @Immutable
-abstract class StringConverter<T> extends SurjectiveConverter<String,T> implements Serializable {
+abstract class StringConverter<T> extends SystemConverter<String, T> {
     /**
      * For cross-version compatibility.
      */
     private static final long serialVersionUID = -3397013355582381432L;
 
     /**
-     * For inner classes only.
+     * The inverse converter from the target to the source class.
+     */
+    private final ObjectConverter<T, String> inverse;
+
+    /**
+     * Creates a new converter for the given target class.
+     *
+     * @param targetClass The {@linkplain #getTargetClass() target class}.
+     * @param inverse The inverse converter from the target to the source class.
+     */
+    StringConverter(final Class<T> targetClass) {
+        super(String.class, targetClass);
+        inverse = createInverse();
+    }
+
+    /**
+     * Invoked by the constructor for creating the inverse converter.
+     * To be overridden by classes which need a specialized instance.
      */
-    StringConverter() {
+    ObjectConverter<T, String> createInverse() {
+        return new ObjectToString<>(targetClass, this);
+    }
+
+    /**
+     * Returns a predefined instance for the given target class, or {@code null} if none.
+     * This method does not create any new instance.
+     *
+     * @param  <T> The target class.
+     * @param  targetClass The target class.
+     * @return An instance for the given target class, or {@code null} if none.
+     */
+    @SuppressWarnings({"unchecked","rawtypes"})
+    static <T> StringConverter<T> getInstance(final Class<T> targetClass) {
+        switch (Numbers.getEnumConstant(targetClass)) {
+            case Numbers.BOOLEAN:     return (StringConverter<T>) Boolean   .INSTANCE;
+            case Numbers.BYTE:        return (StringConverter<T>) Byte      .INSTANCE;
+            case Numbers.SHORT:       return (StringConverter<T>) Short     .INSTANCE;
+            case Numbers.INTEGER:     return (StringConverter<T>) Integer   .INSTANCE;
+            case Numbers.LONG:        return (StringConverter<T>) Long      .INSTANCE;
+            case Numbers.FLOAT:       return (StringConverter<T>) Float     .INSTANCE;
+            case Numbers.DOUBLE:      return (StringConverter<T>) Double    .INSTANCE;
+            case Numbers.BIG_INTEGER: return (StringConverter<T>) BigInteger.INSTANCE;
+            case Numbers.BIG_DECIMAL: return (StringConverter<T>) BigDecimal.INSTANCE;
+        }
+        if (targetClass == java.lang.Number        .class) return (StringConverter<T>) Number. INSTANCE;
+        if (targetClass == java.util.Locale        .class) return (StringConverter<T>) Locale. INSTANCE;
+        if (targetClass == java.nio.charset.Charset.class) return (StringConverter<T>) Charset.INSTANCE;
+        if (targetClass == java.io.File            .class) return (StringConverter<T>) File   .INSTANCE;
+        if (targetClass == java.nio.file.Path      .class) return (StringConverter<T>) Path   .INSTANCE;
+        if (targetClass == java.net.URI            .class) return (StringConverter<T>) URI    .INSTANCE;
+        if (targetClass == java.net.URL            .class) return (StringConverter<T>) URL    .INSTANCE;
+        if (targetClass == org.opengis.util.InternationalString.class) return (StringConverter<T>) InternationalString.INSTANCE;
+        return null;
     }
 
     /**
-     * Returns the source class, which is always {@link String}.
+     * Returns the singleton instance on deserialization, if any.
      */
     @Override
-    public final Class<String> getSourceClass() {
-        return String.class;
+    public ObjectConverter<String, T> unique() {
+        final StringConverter<T> instance = getInstance(targetClass);
+        return (instance != null) ? instance : this;
     }
 
     /**
@@ -81,6 +126,14 @@ abstract class StringConverter<T> extend
     }
 
     /**
+     * Returns the inverse converter.
+     */
+    @Override
+    public final ObjectConverter<T, String> inverse() {
+        return inverse;
+    }
+
+    /**
      * Converts the given string to the target type of this converter.
      * This method verifies that the given string is non-null and non-empty,
      * then delegates to {@link #doConvert(String)}.
@@ -120,252 +173,126 @@ abstract class StringConverter<T> extend
      * {@link Numbers#narrowestNumber(String)}.
      */
     @Immutable
-    static final class Number extends StringConverter<java.lang.Number> {
+    private static final class Number extends StringConverter<java.lang.Number> {
         /** Cross-version compatibility. */ static final long serialVersionUID = 1557277544742023571L;
         /** The unique, shared instance. */ static final Number INSTANCE = new Number();
-        /** For {@link #INSTANCE} only.  */ private Number() {}
-
-        @Override public Class<java.lang.Number> getTargetClass() {
-            return java.lang.Number.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private Number() {super(java.lang.Number.class);}
 
         @Override java.lang.Number doConvert(String source) throws NumberFormatException {
             return Numbers.narrowestNumber(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.lang.Number, String> inverse() {
-            return ObjectToString.NUMBER;
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link java.lang.Double}.
      */
     @Immutable
-    static final class Double extends StringConverter<java.lang.Double> {
+    private static final class Double extends StringConverter<java.lang.Double> {
         /** Cross-version compatibility. */ static final long serialVersionUID = -9094071164371643060L;
         /** The unique, shared instance. */ static final Double INSTANCE = new Double();
-        /** For {@link #INSTANCE} only.  */ private Double() {}
-
-        @Override public Class<java.lang.Double> getTargetClass() {
-            return java.lang.Double.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private Double() {super(java.lang.Double.class);}
 
         @Override java.lang.Double doConvert(String source) throws NumberFormatException {
             return java.lang.Double.parseDouble(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.lang.Double, String> inverse() {
-            return new ObjectToString<>(java.lang.Double.class, this);
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link java.lang.Float}.
      */
     @Immutable
-    static final class Float extends StringConverter<java.lang.Float> {
+    private static final class Float extends StringConverter<java.lang.Float> {
         /** Cross-version compatibility. */ static final long serialVersionUID = -2815192289550338333L;
         /** The unique, shared instance. */ static final Float INSTANCE = new Float();
-        /** For {@link #INSTANCE} only.  */ private Float() {}
-
-        @Override public Class<java.lang.Float> getTargetClass() {
-            return java.lang.Float.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private Float() {super(java.lang.Float.class);}
 
         @Override java.lang.Float doConvert(String source) throws NumberFormatException {
             return java.lang.Float.parseFloat(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.lang.Float, String> inverse() {
-            return new ObjectToString<>(java.lang.Float.class, this);
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link java.lang.Long}.
      */
     @Immutable
-    static final class Long extends StringConverter<java.lang.Long> {
+    private static final class Long extends StringConverter<java.lang.Long> {
         /** Cross-version compatibility. */ static final long serialVersionUID = -2171263041723939779L;
         /** The unique, shared instance. */ static final Long INSTANCE = new Long();
-        /** For {@link #INSTANCE} only.  */ private Long() {}
-
-        @Override public Class<java.lang.Long> getTargetClass() {
-            return java.lang.Long.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private Long() {super(java.lang.Long.class);}
 
         @Override java.lang.Long doConvert(String source) throws NumberFormatException {
             return java.lang.Long.parseLong(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.lang.Long, String> inverse() {
-            return new ObjectToString<>(java.lang.Long.class, this);
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link java.lang.Integer}.
      */
     @Immutable
-    static final class Integer extends StringConverter<java.lang.Integer> {
+    private static final class Integer extends StringConverter<java.lang.Integer> {
         /** Cross-version compatibility. */ static final long serialVersionUID = 763211364703205967L;
         /** The unique, shared instance. */ static final Integer INSTANCE = new Integer();
-        /** For {@link #INSTANCE} only.  */ private Integer() {}
-
-        @Override public Class<java.lang.Integer> getTargetClass() {
-            return java.lang.Integer.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private Integer() {super(java.lang.Integer.class);}
 
         @Override java.lang.Integer doConvert(String source) throws NumberFormatException {
             return java.lang.Integer.parseInt(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.lang.Integer, String> inverse() {
-            return new ObjectToString<>(java.lang.Integer.class, this);
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link java.lang.Short}.
      */
     @Immutable
-    static final class Short extends StringConverter<java.lang.Short> {
+    private static final class Short extends StringConverter<java.lang.Short> {
         /** Cross-version compatibility. */ static final long serialVersionUID = -1770870328699572960L;
         /** The unique, shared instance. */ static final Short INSTANCE = new Short();
-        /** For {@link #INSTANCE} only.  */ private Short() {}
-
-        @Override public Class<java.lang.Short> getTargetClass() {
-            return java.lang.Short.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private Short() {super(java.lang.Short.class);}
 
         @Override java.lang.Short doConvert(String source) throws NumberFormatException {
             return java.lang.Short.parseShort(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.lang.Short, String> inverse() {
-            return new ObjectToString<>(java.lang.Short.class, this);
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link java.lang.Byte}.
      */
     @Immutable
-    static final class Byte extends StringConverter<java.lang.Byte> {
+    private static final class Byte extends StringConverter<java.lang.Byte> {
         /** Cross-version compatibility. */ static final long serialVersionUID = 2084870859391804185L;
         /** The unique, shared instance. */ static final Byte INSTANCE = new Byte();
-        /** For {@link #INSTANCE} only.  */ private Byte() {}
-
-        @Override public Class<java.lang.Byte> getTargetClass() {
-            return java.lang.Byte.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private Byte() {super(java.lang.Byte.class);}
 
         @Override java.lang.Byte doConvert(String source) throws NumberFormatException {
             return java.lang.Byte.parseByte(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.lang.Byte, String> inverse() {
-            return new ObjectToString<>(java.lang.Byte.class, this);
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link java.math.BigDecimal}.
      */
     @Immutable
-    static final class BigDecimal extends StringConverter<java.math.BigDecimal> {
+    private static final class BigDecimal extends StringConverter<java.math.BigDecimal> {
         /** Cross-version compatibility. */ static final long serialVersionUID = -8597497425876120213L;
         /** The unique, shared instance. */ static final BigDecimal INSTANCE = new BigDecimal();
-        /** For {@link #INSTANCE} only.  */ private BigDecimal() {}
-
-        @Override public Class<java.math.BigDecimal> getTargetClass() {
-            return java.math.BigDecimal.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private BigDecimal() {super(java.math.BigDecimal.class);}
 
         @Override java.math.BigDecimal doConvert(String source) throws NumberFormatException {
             return new java.math.BigDecimal(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.math.BigDecimal, String> inverse() {
-            return new ObjectToString<>(java.math.BigDecimal.class, this);
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link java.math.BigInteger}.
      */
     @Immutable
-    static final class BigInteger extends StringConverter<java.math.BigInteger> {
+    private static final class BigInteger extends StringConverter<java.math.BigInteger> {
         /** Cross-version compatibility. */ static final long serialVersionUID = 8658903031519526466L;
         /** The unique, shared instance. */ static final BigInteger INSTANCE = new BigInteger();
-        /** For {@link #INSTANCE} only.  */ private BigInteger() {}
-
-        @Override public Class<java.math.BigInteger> getTargetClass() {
-            return java.math.BigInteger.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private BigInteger() {super(java.math.BigInteger.class);}
 
         @Override java.math.BigInteger doConvert(String source) throws NumberFormatException {
             return new java.math.BigInteger(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.math.BigInteger, String> inverse() {
-            return new ObjectToString<>(java.math.BigInteger.class, this);
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
@@ -385,14 +312,10 @@ abstract class StringConverter<T> extend
      * </table>
      */
     @Immutable
-    static final class Boolean extends StringConverter<java.lang.Boolean> {
+    private static final class Boolean extends StringConverter<java.lang.Boolean> {
         /** Cross-version compatibility. */ static final long serialVersionUID = -27525398425996373L;
         /** The unique, shared instance. */ static final Boolean INSTANCE = new Boolean();
-        /** For {@link #INSTANCE} only.  */ private Boolean() {}
-
-        @Override public Class<java.lang.Boolean> getTargetClass() {
-            return java.lang.Boolean.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private Boolean() {super(java.lang.Boolean.class);}
 
         @Override java.lang.Boolean doConvert(final String source) throws UnconvertibleObjectException {
             switch (source.toLowerCase(java.util.Locale.ROOT)) {
@@ -401,16 +324,6 @@ abstract class StringConverter<T> extend
             }
             throw new UnconvertibleObjectException(formatErrorMessage(source));
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.lang.Boolean, String> inverse() {
-            return ObjectToString.BOOLEAN;
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
@@ -418,66 +331,38 @@ abstract class StringConverter<T> extend
      * Examples of locale in string form: {@code "fr"}, {@code "fr_CA"}.
      */
     @Immutable
-    static final class Locale extends StringConverter<java.util.Locale> {
+    private static final class Locale extends StringConverter<java.util.Locale> {
         /** Cross-version compatibility. */ static final long serialVersionUID = -2888932450292616036L;
         /** The unique, shared instance. */ static final Locale INSTANCE = new Locale();
-        /** For {@link #INSTANCE} only.  */ private Locale() {}
-
-        @Override public Class<java.util.Locale> getTargetClass() {
-            return java.util.Locale.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private Locale() {super(java.util.Locale.class);}
 
         @Override java.util.Locale doConvert(String source) throws IllegalArgumentException {
             return Locales.parse(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.util.Locale, String> inverse() {
-            return ObjectToString.LOCALE;
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link java.nio.charset.Charset}.
      */
     @Immutable
-    static final class Charset extends StringConverter<java.nio.charset.Charset> {
+    private static final class Charset extends StringConverter<java.nio.charset.Charset> {
         /** Cross-version compatibility. */ static final long serialVersionUID = 4539755855992944656L;
         /** The unique, shared instance. */ static final Charset INSTANCE = new Charset();
-        /** For {@link #INSTANCE} only.  */ private Charset() {}
-
-        @Override public Class<java.nio.charset.Charset> getTargetClass() {
-            return java.nio.charset.Charset.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private Charset() {super(java.nio.charset.Charset.class);}
 
         @Override java.nio.charset.Charset doConvert(String source) throws UnsupportedCharsetException {
             return java.nio.charset.Charset.forName(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.nio.charset.Charset, String> inverse() {
-            return ObjectToString.CHARSET;
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link org.opengis.util.InternationalString}.
      */
     @Immutable
-    static final class InternationalString extends StringConverter<org.opengis.util.InternationalString> {
+    private static final class InternationalString extends StringConverter<org.opengis.util.InternationalString> {
         /** Cross-version compatibility. */ static final long serialVersionUID = 730809620191573819L;
         /** The unique, shared instance. */ static final InternationalString INSTANCE = new InternationalString();
-        /** For {@link #INSTANCE} only.  */ private InternationalString() {}
+        /** For {@link #INSTANCE} only.  */ private InternationalString() {super(org.opengis.util.InternationalString.class);}
 
         /** Returns the function properties, which is bijective. */
         @Override public Set<FunctionProperty> properties() {
@@ -485,22 +370,9 @@ abstract class StringConverter<T> extend
                     FunctionProperty.ORDER_PRESERVING, FunctionProperty.INVERTIBLE);
         }
 
-        @Override public Class<org.opengis.util.InternationalString> getTargetClass() {
-            return org.opengis.util.InternationalString.class;
-        }
-
         @Override org.opengis.util.InternationalString doConvert(String source) {
             return new SimpleInternationalString(source);
         }
-
-        @Override public ObjectConverter<org.opengis.util.InternationalString, String> inverse() {
-            return ObjectToString.I18N;
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
@@ -509,135 +381,84 @@ abstract class StringConverter<T> extend
      * ({@code '/'} and {@code '\'}) produce the same {@code File} object.
      */
     @Immutable
-    static final class File extends StringConverter<java.io.File> {
+    private static final class File extends StringConverter<java.io.File> {
         /** Cross-version compatibility. */ static final long serialVersionUID = 6445208470928432376L;
         /** The unique, shared instance. */ static final File INSTANCE = new File();
-        /** For {@link #INSTANCE} only.  */ private File() {}
-
-        @Override public Class<java.io.File> getTargetClass() {
-            return java.io.File.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private File() {super(java.io.File.class);}
 
         @Override java.io.File doConvert(String source) {
             return new java.io.File(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.io.File, String> inverse() {
-            return ObjectToString.FILE;
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link java.nio.file.Path}.
      */
     @Immutable
-    static final class Path extends StringConverter<java.nio.file.Path> {
+    private static final class Path extends StringConverter<java.nio.file.Path> {
         /** Cross-version compatibility. */ static final long serialVersionUID = -5227120925547132828L;
         /** The unique, shared instance. */ static final Path INSTANCE = new Path();
-        /** For {@link #INSTANCE} only.  */ private Path() {}
-
-        @Override public Class<java.nio.file.Path> getTargetClass() {
-            return java.nio.file.Path.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private Path() {super(java.nio.file.Path.class);}
 
         @Override java.nio.file.Path doConvert(String source) throws InvalidPathException {
             return java.nio.file.Paths.get(source);
         }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link java.net.URI}.
      */
     @Immutable
-    static final class URI extends StringConverter<java.net.URI> {
+    private static final class URI extends StringConverter<java.net.URI> {
         /** Cross-version compatibility. */ static final long serialVersionUID = -2804405634789179706L;
         /** The unique, shared instance. */ static final URI INSTANCE = new URI();
-        /** For {@link #INSTANCE} only.  */ private URI() {}
-
-        @Override public Class<java.net.URI> getTargetClass() {
-            return java.net.URI.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private URI() {super(java.net.URI.class);}
 
         @Override java.net.URI doConvert(String source) throws URISyntaxException {
             return new java.net.URI(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.net.URI, String> inverse() {
-            return ObjectToString.URI;
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link java.net.URL}.
      */
     @Immutable
-    static final class URL extends StringConverter<java.net.URL> {
+    private static final class URL extends StringConverter<java.net.URL> {
         /** Cross-version compatibility. */ static final long serialVersionUID = 2303928306635765592L;
         /** The unique, shared instance. */ static final URL INSTANCE = new URL();
-        /** For {@link #INSTANCE} only.  */ private URL() {}
-
-        @Override public Class<java.net.URL> getTargetClass() {
-            return java.net.URL.class;
-        }
+        /** For {@link #INSTANCE} only.  */ private URL() {super(java.net.URL.class);}
 
         @Override java.net.URL doConvert(String source) throws MalformedURLException {
             return new java.net.URL(source);
         }
-
-        /** Returns the inverse, since this converter is "almost" bijective. */
-        @Override public ObjectConverter<java.net.URL, String> inverse() {
-            return ObjectToString.URL;
-        }
-
-        /** Returns the singleton instance on deserialization. */
-        Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     /**
      * Converter from {@link String} to {@link org.opengis.util.CodeList}.
      * This converter is particular in that it requires the target class in argument
      * to the constructor.
+     *
+     * <p>Instances of this class are created by
+     * {@link HeuristicRegistry#createConverter(Class, Class)}.</p>
      */
     @Immutable
     static final class CodeList<T extends org.opengis.util.CodeList<T>> extends StringConverter<T> {
         /** For cross-version compatibility on serialization. */
         static final long serialVersionUID = 3289083947166861278L;
 
-        /** The type of the code list. */
-        private final Class<T> targetType;
-
         /** Creates a new converter for the given code list. */
-        CodeList(final Class<T> targetType) {
-            this.targetType = targetType;
-        }
-
-        /** Returns the target class given at construction time. */
-        @Override public Class<T> getTargetClass() {
-            return targetType;
+        CodeList(final Class<T> targetClass) {
+            super(targetClass);
         }
 
         /** Converts the given string to the target type of this converter. */
         @Override T doConvert(String source) {
-            return Types.forCodeName(targetType, source, true);
+            return Types.forCodeName(targetClass, source, true);
+        }
+
+        /** Invoked by the constructor for creating the inverse converter. */
+        @Override ObjectConverter<T, String> createInverse() {
+            return new ObjectToString.CodeList<>(targetClass, this);
         }
     }
 }

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java?rev=1457022&r1=1457021&r2=1457022&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java [UTF-8] Fri Mar 15 17:10:21 2013
@@ -18,7 +18,6 @@ package org.apache.sis.internal.converte
 
 import java.io.ObjectStreamException;
 import org.apache.sis.util.ObjectConverter;
-import org.apache.sis.util.UnconvertibleObjectException;
 import org.apache.sis.util.resources.Errors;
 
 
@@ -42,11 +41,6 @@ abstract class SystemConverter<S,T> exte
     private static final long serialVersionUID = 885663610056067478L;
 
     /**
-     * The inverse converter, created when first needed.
-     */
-    private transient volatile ObjectConverter<T,S> inverse;
-
-    /**
      * Creates a new converter for the given source and target classes.
      *
      * @param sourceClass The {@linkplain #getSourceClass() source class}.
@@ -73,19 +67,11 @@ abstract class SystemConverter<S,T> exte
     }
 
     /**
-     * Returns the inverse converter, creating it when first needed.
+     * Default to non-invertible conversion. Must be overridden by subclasses that support inversions.
      */
     @Override
-    public final ObjectConverter<T,S> inverse() throws UnsupportedOperationException {
-        // No need to synchronize. This is not a big deal if the same object is fetched twice.
-        // The ConverterRegistry clas provides the required synchronization.
-        ObjectConverter<T,S> candidate = inverse;
-        if (candidate == null) try {
-            inverse = candidate = HeuristicRegistry.SYSTEM.findExact(targetClass, sourceClass);
-        } catch (UnconvertibleObjectException e) {
-            throw new UnsupportedOperationException(Errors.format(Errors.Keys.NonInvertibleConversion), e);
-        }
-        return candidate;
+    public ObjectConverter<T,S> inverse() throws UnsupportedOperationException {
+        throw new UnsupportedOperationException(Errors.format(Errors.Keys.NonInvertibleConversion));
     }
 
     /**
@@ -128,7 +114,7 @@ abstract class SystemConverter<S,T> exte
      * exists for the same source an target classes, then this converter is returned.
      * Otherwise this converter is returned <strong>without</strong> being cached.
      */
-    public final ObjectConverter<S,T> unique() {
+    public ObjectConverter<S,T> unique() {
         final ObjectConverter<S,T> existing = HeuristicRegistry.SYSTEM.findEquals(this);
         return (existing != null) ? existing : this;
     }

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/ConverterRegistryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/ConverterRegistryTest.java?rev=1457022&r1=1457021&r2=1457022&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/ConverterRegistryTest.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/ConverterRegistryTest.java [UTF-8] Fri Mar 15 17:10:21 2013
@@ -44,8 +44,10 @@ import static org.apache.sis.test.Assert
  * @version 0.3
  * @module
  */
-@DependsOn({FallbackConverterTest.class,
-    org.apache.sis.util.collection.TreeTableFormatTest.class})
+@DependsOn({
+    StringConverterTest.class, FallbackConverterTest.class,
+    org.apache.sis.util.collection.TreeTableFormatTest.class
+})
 public final strictfp class ConverterRegistryTest extends TestCase {
     /**
      * The registry being tested.
@@ -62,6 +64,7 @@ public final strictfp class ConverterReg
      * Registers a converter to test.
      */
     private void register(final ObjectConverter<?,?> converter) {
+        assertNotNull("Missing ObjectConverter", converter);
         converters.add(converter);
         registry.register(converter);
     }
@@ -149,11 +152,15 @@ public final strictfp class ConverterReg
      * Tests registration of converters from {@link String} to miscellaneous objects.
      * This method tests the addition of many converters because we want to observe
      * how {@linkplain #registry} grow in reaction to those additions.
+     *
+     * <p>This test compares the string representations for convenience.  In theory those string
+     * representations are not committed API, so if the {@code FallbackConverter} implementation
+     * change, it is okay to update this test accordingly.</p>
      */
     @Test
     public void testStringToMiscellaneous() {
         assertAllConvertersAreRegistered();
-        register(StringConverter.Short.INSTANCE);
+        register(StringConverter.getInstance(Short.class));
         assertSameConverterForTarget(Short       .class);
         assertSameConverterForTarget(Number      .class);
         assertIdentityForTarget     (Object      .class);
@@ -174,7 +181,7 @@ public final strictfp class ConverterReg
          */
         assertAllConvertersAreRegistered();
         assertNoConverterForTarget(Long.class);
-        register(StringConverter.Long.INSTANCE);
+        register(StringConverter.getInstance(Long.class));
         assertSameConverterForTarget(Long        .class);
         assertIdentityForTarget     (Object      .class);
         assertNoConverterForTarget  (Cloneable   .class);
@@ -200,7 +207,7 @@ public final strictfp class ConverterReg
          */
         assertAllConvertersAreRegistered();
         assertNoConverterForTarget(Boolean.class);
-        register(StringConverter.Boolean.INSTANCE);
+        register(StringConverter.getInstance(Boolean.class));
         assertSameConverterForTarget(Boolean     .class);
         assertIdentityForTarget     (Object      .class);
         assertNoConverterForTarget  (Cloneable   .class);
@@ -222,7 +229,7 @@ public final strictfp class ConverterReg
          * Expected side-effect: replacement of the FallbackConverter
          */
         assertAllConvertersAreRegistered();
-        register(StringConverter.Number.INSTANCE);
+        register(StringConverter.getInstance(Number.class));
         assertSameConverterForTarget(Number      .class);
         assertIdentityForTarget     (Object      .class);
         assertNoConverterForTarget  (Cloneable   .class);
@@ -235,15 +242,15 @@ public final strictfp class ConverterReg
             "  ├─Comparable    ← String\n" +
             "  ├─Serializable  ← String\n" +
             "  ├─Long          ← String\n" +
-            "  ├─Number        ← String\n" + // Replaced the FallbackConverter.
-            "  └─Boolean       ← String\n", registry.toString());
+            "  ├─Boolean       ← String\n" +
+            "  └─Number        ← String\n", registry.toString()); // Replaced the FallbackConverter.
         /*
          * Adds String ← Float
          * Expected side-effect: none
          */
         assertAllConvertersAreRegistered();
         assertNoConverterForTarget(Float.class);
-        register(StringConverter.Float.INSTANCE);
+        register(StringConverter.getInstance(Float.class));
         assertSameConverterForTarget(Float       .class);
         assertIdentityForTarget     (Object      .class);
         assertNoConverterForTarget  (Cloneable   .class);
@@ -256,8 +263,8 @@ public final strictfp class ConverterReg
             "  ├─Comparable    ← String\n" +
             "  ├─Serializable  ← String\n" +
             "  ├─Long          ← String\n" +
-            "  ├─Number        ← String\n" +
             "  ├─Boolean       ← String\n" +
+            "  ├─Number        ← String\n" +
             "  └─Float         ← String\n", registry.toString());
         /*
          * Final check.
@@ -269,12 +276,16 @@ public final strictfp class ConverterReg
      * Tests registration of converters between {@link Number} and miscellaneous objects.
      * This method tests the addition of many converters because we want to observe
      * how {@linkplain #registry} grow in reaction to those additions.
+     *
+     * <p>This test compares the string representations for convenience.  In theory those string
+     * representations are not committed API, so if the {@code FallbackConverter} implementation
+     * change, it is okay to update this test accordingly.</p>
      */
     @Test
     @DependsOnMethod("testStringToMiscellaneous")
     public void testNumberToMiscellaneous() {
         assertAllConvertersAreRegistered();
-        register(ObjectToString.NUMBER);
+        register(StringConverter.getInstance(Number.class).inverse());
         assertSameConverterForTarget(String      .class);
         assertIdentityForTarget     (Object      .class);
         assertNoConverterForTarget  (Cloneable   .class);
@@ -293,7 +304,7 @@ public final strictfp class ConverterReg
          * Expected side-effect: none
          */
         assertAllConvertersAreRegistered();
-        register(StringConverter.Number.INSTANCE);
+        register(StringConverter.getInstance(Number.class));
         assertSameConverterForTarget(Number.class);
         assertMultilinesEquals("After StringConverter.Number",
             "ConverterRegistry\n" +

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FallbackConverterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FallbackConverterTest.java?rev=1457022&r1=1457021&r2=1457022&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FallbackConverterTest.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FallbackConverterTest.java [UTF-8] Fri Mar 15 17:10:21 2013
@@ -60,15 +60,15 @@ public final strictfp class FallbackConv
         final EnumSet<FunctionProperty> SURJECTIVE = EnumSet.of(FunctionProperty.SURJECTIVE);
         final EnumSet<FunctionProperty> INVERTIBLE = EnumSet.of(FunctionProperty.SURJECTIVE, FunctionProperty.INVERTIBLE);
 
-        ObjectConverter<String,?> c = StringConverter.Short.INSTANCE;
+        ObjectConverter<String,?> c = StringConverter.getInstance(Short.class);
         assertEquals(String.class, c.getSourceClass());
         assertEquals(Short.class,  c.getTargetClass());
         assertEquals(INVERTIBLE,   c.properties());
         tryConversions(c, SHORT);
         assertMultilinesEquals(
-                "StringConverter.Short[Short ← String]", c.toString());
+                "Short ← String", c.toString());
 
-        c = FallbackConverter.merge(c, StringConverter.Long.INSTANCE);
+        c = FallbackConverter.merge(c, StringConverter.getInstance(Long.class));
         assertEquals(String.class, c.getSourceClass());
         assertEquals(Number.class, c.getTargetClass());
         assertEquals(SURJECTIVE,   c.properties());
@@ -78,7 +78,7 @@ public final strictfp class FallbackConv
                 "  ├─Short ← String\n" +
                 "  └─Long  ← String\n", c.toString());
 
-        c = FallbackConverter.merge(c, StringConverter.Float.INSTANCE);
+        c = FallbackConverter.merge(c, StringConverter.getInstance(Float.class));
         assertEquals(String.class, c.getSourceClass());
         assertEquals(Number.class, c.getTargetClass());
         assertEquals(SURJECTIVE,   c.properties());
@@ -89,7 +89,7 @@ public final strictfp class FallbackConv
                 "  ├─Long  ← String\n" +
                 "  └─Float ← String\n", c.toString());
 
-        c = FallbackConverter.merge(c, StringConverter.Integer.INSTANCE);
+        c = FallbackConverter.merge(c, StringConverter.getInstance(Integer.class));
         assertEquals(String.class, c.getSourceClass());
         assertEquals(Number.class, c.getTargetClass());
         assertEquals(SURJECTIVE,   c.properties());
@@ -101,7 +101,7 @@ public final strictfp class FallbackConv
                 "  ├─Float   ← String\n" +
                 "  └─Integer ← String\n", c.toString());
 
-        c = FallbackConverter.merge(c, StringConverter.Boolean.INSTANCE);
+        c = FallbackConverter.merge(c, StringConverter.getInstance(Boolean.class));
         assertEquals(String.class, c.getSourceClass());
         assertEquals(Object.class, c.getTargetClass());
         assertEquals(SURJECTIVE,   c.properties());
@@ -115,7 +115,7 @@ public final strictfp class FallbackConv
                 "  │   └─Integer ← String\n" +
                 "  └─Boolean     ← String\n", c.toString());
 
-        c = FallbackConverter.merge(c, StringConverter.Double.INSTANCE);
+        c = FallbackConverter.merge(c, StringConverter.getInstance(Double.class));
         assertEquals(String.class, c.getSourceClass());
         assertEquals(Object.class, c.getTargetClass());
         assertEquals(SURJECTIVE,   c.properties());

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FileConverterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FileConverterTest.java?rev=1457022&r1=1457021&r2=1457022&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FileConverterTest.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/FileConverterTest.java [UTF-8] Fri Mar 15 17:10:21 2013
@@ -70,7 +70,7 @@ public final strictfp class FileConverte
      */
     @Test
     public void testString() {
-        final ObjectConverter<File,String> c = ObjectToString.FILE;
+        final ObjectConverter<File,String> c = StringConverter.getInstance(File.class).inverse();
         runInvertibleConversion(c, new File("home/user/index.txt"), "home/user/index.txt".replace("/", File.separator));
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
     }

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java?rev=1457022&r1=1457021&r2=1457022&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java [UTF-8] Fri Mar 15 17:10:21 2013
@@ -47,6 +47,17 @@ import static org.apache.sis.test.Assert
  */
 public final strictfp class StringConverterTest extends TestCase {
     /**
+     * Returns an instance for the given target type.
+     */
+    private static <T> StringConverter<T> getInstance(final Class<T> targetClass) {
+        final StringConverter<T> c = StringConverter.getInstance(targetClass);
+        assertNotNull("No instance found for the given target type.", c);
+        assertEquals("Unexpected source class.", String.class, c.getSourceClass());
+        assertEquals("Unexpected source class.", targetClass,  c.getTargetClass());
+        return c;
+    }
+
+    /**
      * Asserts that conversion of the given {@code source} value produces
      * the given {@code target} value, and tests the inverse conversion.
      */
@@ -78,7 +89,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testNumber() {
-        final ObjectConverter<String,Number> c = StringConverter.Number.INSTANCE;
+        final ObjectConverter<String,Number> c = getInstance(Number.class);
         runInvertibleConversion(c,    "-4", Byte   .valueOf((byte)   -4));
         runInvertibleConversion(c,   "128", Short  .valueOf((short) 128));
         runInvertibleConversion(c, "40000", Integer.valueOf(      40000));
@@ -92,7 +103,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testDouble() {
-        final ObjectConverter<String,Double> c = StringConverter.Double.INSTANCE;
+        final ObjectConverter<String,Double> c = getInstance(Double.class);
         runInvertibleConversion(c, "4.5", Double.valueOf(4.5));
         tryUnconvertibleValue(c);
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
@@ -103,7 +114,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testFloat() {
-        final ObjectConverter<String,Float> c = StringConverter.Float.INSTANCE;
+        final ObjectConverter<String,Float> c = getInstance(Float.class);
         runInvertibleConversion(c, "4.5", Float.valueOf(4.5f));
         tryUnconvertibleValue(c);
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
@@ -114,7 +125,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testLong() {
-        final ObjectConverter<String,Long> c = StringConverter.Long.INSTANCE;
+        final ObjectConverter<String,Long> c = getInstance(Long.class);
         runInvertibleConversion(c, "45000", Long.valueOf(45000));
         tryUnconvertibleValue(c);
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
@@ -125,7 +136,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testInteger() {
-        final ObjectConverter<String,Integer> c = StringConverter.Integer.INSTANCE;
+        final ObjectConverter<String,Integer> c = getInstance(Integer.class);
         runInvertibleConversion(c, "45000", Integer.valueOf(45000));
         tryUnconvertibleValue(c);
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
@@ -136,7 +147,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testShort() {
-        final ObjectConverter<String,Short> c = StringConverter.Short.INSTANCE;
+        final ObjectConverter<String,Short> c = getInstance(Short.class);
         runInvertibleConversion(c, "4500", Short.valueOf((short) 4500));
         tryUnconvertibleValue(c);
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
@@ -147,7 +158,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testByte() {
-        final ObjectConverter<String,Byte> c = StringConverter.Byte.INSTANCE;
+        final ObjectConverter<String,Byte> c = getInstance(Byte.class);
         runInvertibleConversion(c, "45", Byte.valueOf((byte) 45));
         tryUnconvertibleValue(c);
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
@@ -158,7 +169,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testBigDecimal() {
-        final ObjectConverter<String,BigDecimal> c = StringConverter.BigDecimal.INSTANCE;
+        final ObjectConverter<String,BigDecimal> c = getInstance(BigDecimal.class);
         runInvertibleConversion(c, "45000.5", BigDecimal.valueOf(45000.5));
         tryUnconvertibleValue(c);
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
@@ -169,7 +180,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testBigInteger() {
-        final ObjectConverter<String,BigInteger> c = StringConverter.BigInteger.INSTANCE;
+        final ObjectConverter<String,BigInteger> c = getInstance(BigInteger.class);
         runInvertibleConversion(c, "45000", BigInteger.valueOf(45000));
         tryUnconvertibleValue(c);
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
@@ -180,7 +191,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testBoolean() {
-        final ObjectConverter<String,Boolean> c = StringConverter.Boolean.INSTANCE;
+        final ObjectConverter<String,Boolean> c = getInstance(Boolean.class);
         runInvertibleConversion(c, "true",  Boolean.TRUE);
         runInvertibleConversion(c, "false", Boolean.FALSE);
         assertEquals(Boolean.TRUE,  c.convert("yes"));
@@ -198,7 +209,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testLocale() {
-        final ObjectConverter<String,Locale> c = StringConverter.Locale.INSTANCE;
+        final ObjectConverter<String,Locale> c = getInstance(Locale.class);
         runInvertibleConversion(c, "fr_CA", Locale.CANADA_FRENCH);
         tryUnconvertibleValue(c);
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
@@ -209,7 +220,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testCharset() {
-        final ObjectConverter<String,Charset> c = StringConverter.Charset.INSTANCE;
+        final ObjectConverter<String,Charset> c = getInstance(Charset.class);
         runInvertibleConversion(c, "UTF-8", StandardCharsets.UTF_8);
         tryUnconvertibleValue(c);
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
@@ -220,7 +231,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testInternationalString() {
-        final ObjectConverter<String,InternationalString> c = StringConverter.InternationalString.INSTANCE;
+        final ObjectConverter<String,InternationalString> c = getInstance(InternationalString.class);
         runInvertibleConversion(c, "Some sentence", new SimpleInternationalString("Some sentence"));
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
     }
@@ -230,7 +241,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testFile() {
-        final ObjectConverter<String,File> c = StringConverter.File.INSTANCE;
+        final ObjectConverter<String,File> c = getInstance(File.class);
         runInvertibleConversion(c, "home/user/index.txt", new File("home/user/index.txt"));
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
     }
@@ -242,7 +253,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testURI() throws URISyntaxException {
-        final ObjectConverter<String,URI> c = StringConverter.URI.INSTANCE;
+        final ObjectConverter<String,URI> c = getInstance(URI.class);
         runInvertibleConversion(c, "file:/home/user/index.txt", new URI("file:/home/user/index.txt"));
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
     }
@@ -254,7 +265,7 @@ public final strictfp class StringConver
      */
     @Test
     public void testURL() throws MalformedURLException  {
-        final ObjectConverter<String,URL> c = StringConverter.URL.INSTANCE;
+        final ObjectConverter<String,URL> c = getInstance(URL.class);
         runInvertibleConversion(c, "file:/home/user/index.txt", new URL("file:/home/user/index.txt"));
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
     }

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URIConverterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URIConverterTest.java?rev=1457022&r1=1457021&r2=1457022&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URIConverterTest.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URIConverterTest.java [UTF-8] Fri Mar 15 17:10:21 2013
@@ -61,7 +61,7 @@ public final strictfp class URIConverter
      */
     @Test
     public void testString() throws URISyntaxException {
-        final ObjectConverter<URI,String> c = ObjectToString.URI;
+        final ObjectConverter<URI,String> c = StringConverter.getInstance(URI.class).inverse();
         runInvertibleConversion(c, new URI("file:/home/user/index.txt"), "file:/home/user/index.txt");
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
     }

Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URLConverterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URLConverterTest.java?rev=1457022&r1=1457021&r2=1457022&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URLConverterTest.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/converter/URLConverterTest.java [UTF-8] Fri Mar 15 17:10:21 2013
@@ -61,7 +61,7 @@ public final strictfp class URLConverter
      */
     @Test
     public void testString() throws MalformedURLException {
-        final ObjectConverter<URL,String> c = ObjectToString.URL;
+        final ObjectConverter<URL,String> c = StringConverter.getInstance(URL.class).inverse();
         runInvertibleConversion(c, new URL("file:/home/user/index.txt"), "file:/home/user/index.txt");
         assertSame("Deserialization shall resolves to the singleton instance.", c, assertSerializedEquals(c));
     }



Mime
View raw message