sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1551243 - in /sis/branches/JDK7: application/sis-console/src/main/java/org/apache/sis/console/ core/sis-utility/src/main/java/org/apache/sis/internal/converter/ core/sis-utility/src/main/java/org/apache/sis/util/ core/sis-utility/src/main/...
Date Mon, 16 Dec 2013 15:59:46 GMT
Author: desruisseaux
Date: Mon Dec 16 15:59:46 2013
New Revision: 1551243

URL: http://svn.apache.org/r1551243
Log:
Revert the 'parse' method name change in Locales. The 'parseLanguage' was not really better,
because it gave the impression that the method does not parse country and variant codes.

Modified:
    sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/LocalesTest.java

Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java?rev=1551243&r1=1551242&r2=1551243&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java
[UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java
[UTF-8] Mon Dec 16 15:59:46 2013
@@ -189,7 +189,7 @@ abstract class SubCommand {
         final boolean explicitEncoding;
         try {
             value = options.get(option = Option.LOCALE);
-            locale = (value != null) ? Locales.parseLanguage(value, 0) : Locale.getDefault(Locale.Category.DISPLAY);
+            locale = (value != null) ? Locales.parse(value) : Locale.getDefault(Locale.Category.DISPLAY);
 
             value = options.get(option = Option.TIMEZONE);
             timezone = (value != null) ? TimeZone.getTimeZone(value) : TimeZone.getDefault();

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java?rev=1551243&r1=1551242&r2=1551243&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/converter/StringConverter.java
[UTF-8] Mon Dec 16 15:59:46 2013
@@ -249,7 +249,7 @@ abstract class StringConverter<T> extend
         public Locale() {super(java.util.Locale.class);} // Instantiated by ServiceLoader.
 
         @Override java.util.Locale doConvert(String source) throws IllegalArgumentException
{
-            return Locales.parseLanguage(source, 0);
+            return Locales.parse(source);
         }
     }
 

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java?rev=1551243&r1=1551242&r2=1551243&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Locales.java [UTF-8]
Mon Dec 16 15:59:46 2013
@@ -200,25 +200,34 @@ public final class Locales extends Stati
     }
 
     /**
-     * @deprecated Renamed as {@link #parseLanguage(String, int)}.
+     * Parses the given language code, optionally followed by country code and variant. The
given string can be either
+     * the 2 letters or the 3 letters ISO 639 code. It can optionally be followed by the
{@code '_'} character and the
+     * country code (again either as 2 or 3 letters), optionally followed by {@code '_'}
and the variant.
      *
-     * @param  code The language code, which may be followed by country code.
+     * <p>This method can be used when the caller wants the same {@code Locale} constants
no matter if the language
+     * and country codes use 2 or 3 letters. This method tries to convert 3-letters codes
to 2-letters code on a
+     * <cite>best effort</cite> basis.</p>
+     *
+     * @param  code The language code, optionally followed by country code and variant.
      * @return The language for the given code (never {@code null}).
      * @throws IllegalArgumentException If the given code doesn't seem to be a valid locale.
+     *
+     * @see Locale#forLanguageTag(String)
      */
-    @Deprecated
     public static Locale parse(final String code) throws IllegalArgumentException {
-        return parseLanguage(code, 0);
+        return parse(code, 0);
     }
 
     /**
-     * Parses the given language code. The given string can be either the 2 letters or the
3 letters ISO 639 code.
-     * It can optionally be followed by the {@code '_'} character and the country code (again
either as 2 or 3 letters),
-     * optionally followed by {@code '_'} and the variant.
-     *
-     * <p>This method can be used when the caller wants the same {@code Locale} constants
no matter if the language
-     * and country codes use 2 or 3 letters. This method tries to convert 3-letters codes
to 2-letters code on a
-     * <cite>best effort</cite> basis.</p>
+     * Parses the given language code and optional complements (country, variant), starting
at the given index.
+     * All characters before {@code fromIndex} are ignored. Characters from {@code fromIndex}
to the end of the
+     * string are parsed as documented in the {@link #parse(String)} method. In particular,
this method tries to
+     * convert 3-letters codes to 2-letters code on a <cite>best effort</cite>
basis.
+     *
+     * {@example This method is useful when language codes are appended to a base property
or resource name.
+     *           For example a dictionary may define the <code>"remarks"</code>
property by values associated
+     *           to the <code>"remarks_en"</code> and <code>"remarks_fr"</code>
keys, for English and French
+     *           locales respectively.}
      *
      * @param  code The language code, which may be followed by country code.
      * @param  fromIndex Index of the first character to parse.
@@ -228,7 +237,7 @@ public final class Locales extends Stati
      * @see Locale#forLanguageTag(String)
      * @see org.apache.sis.util.iso.Types#toInternationalString(Map, String)
      */
-    public static Locale parseLanguage(final String code, final int fromIndex) throws IllegalArgumentException
{
+    public static Locale parse(final String code, final int fromIndex) throws IllegalArgumentException
{
         ArgumentChecks.ensureNonNull("code", code);
         ArgumentChecks.ensurePositive("fromIndex", fromIndex);
         final String language, country, variant;
@@ -302,7 +311,7 @@ public final class Locales extends Stati
      *   <li>Otherwise if the given {@code key} does not start with the specified {@code
prefix}
      *       followed by the {@code '_'} character, then this method returns {@code null}.</li>
      *   <li>Otherwise, the characters after the {@code '_'} are parsed as an ISO language
-     *       and country code by the {@link #parseLanguage(String, int)} method.</li>
+     *       and country code by the {@link #parse(String, int)} method.</li>
      * </ul>
      *
      * @param  prefix The prefix to skip at the beginning of the {@code key}.
@@ -324,7 +333,7 @@ public final class Locales extends Stati
                     return Locale.ROOT;
                 }
                 if (key.charAt(offset) == '_') {
-                    return parseLanguage(key, offset + 1);
+                    return parse(key, offset + 1);
                 }
             }
         }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java?rev=1551243&r1=1551242&r2=1551243&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java [UTF-8]
Mon Dec 16 15:59:46 2013
@@ -579,7 +579,7 @@ public final class Types extends Static 
      * <ul>
      *   <li>If the key is exactly equals to {@code prefix}, selects {@link Locale#ROOT}.</li>
      *   <li>Otherwise the characters after {@code '_'} are parsed as an ISO language
and country code
-     *       by the {@link Locales#parseLanguage(String, int)} method. Note that 3-letters
codes are replaced
+     *       by the {@link Locales#parse(String, int)} method. Note that 3-letters codes
are replaced
      *       by their 2-letters counterparts on a <cite>best effort</cite> basis.</li>
      *   <li>The value for the decoded locale is added in the international string
to be returned.</li>
      * </ul>
@@ -594,7 +594,7 @@ public final class Types extends Static 
      *           <li>or the value associated to that key is a not a {@link CharSequence}.</li>
      *         </ul>
      *
-     * @see Locales#parseLanguage(String, int)
+     * @see Locales#parse(String, int)
      * @see DefaultInternationalString#DefaultInternationalString(Map)
      *
      * @since 0.4
@@ -644,7 +644,7 @@ public final class Types extends Static 
                     if (isSorted && c > '_') break;
                     continue;
                 }
-                locale = Locales.parseLanguage(key, offset + 1);
+                locale = Locales.parse(key, offset + 1);
             }
             final Object value = entry.getValue();
             if (value != null) {

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java?rev=1551243&r1=1551242&r2=1551243&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java [UTF-8]
Mon Dec 16 15:59:46 2013
@@ -326,7 +326,7 @@ abstract class Pooled {
         try {
             switch (name) {
                 case XML.LOCALE: {
-                    locale = (value instanceof CharSequence) ? Locales.parseLanguage(value.toString(),
0) : (Locale) value;
+                    locale = (value instanceof CharSequence) ? Locales.parse(value.toString())
: (Locale) value;
                     return;
                 }
                 case XML.TIMEZONE: {

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java?rev=1551243&r1=1551242&r2=1551243&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java
[UTF-8] Mon Dec 16 15:59:46 2013
@@ -190,12 +190,12 @@ public class ValueConverter {
      *         if an exception was thrown and {@code exceptionOccured(…)} returned {@code
true}.
      * @throws IllegalArgumentException If the given string can not be converted to a locale.
      *
-     * @see Locales#parseLanguage(String, int)
+     * @see Locales#parse(String)
      */
     public Locale toLocale(final MarshalContext context, String value) throws IllegalArgumentException
{
         value = trimWhitespaces(value);
         if (value != null && !value.isEmpty()) try {
-            return Locales.parseLanguage(value, 0);
+            return Locales.parse(value);
         } catch (IllegalArgumentException e) {
             if (!exceptionOccured(context, value, String.class, Locale.class, e)) {
                 throw e;

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/LocalesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/LocalesTest.java?rev=1551243&r1=1551242&r2=1551243&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/LocalesTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/LocalesTest.java
[UTF-8] Mon Dec 16 15:59:46 2013
@@ -68,24 +68,24 @@ public final strictfp class LocalesTest 
     }
 
     /**
-     * Tests the {@link Locales#parseLanguage(String, int)} method.
+     * Tests the {@link Locales#parse(String)} method.
      */
     @Test
     @DependsOnMethod("testUnique")
     public void testParseLanguage() {
-        assertSame(Locale.FRENCH,        Locales.parseLanguage("fr", 0));
-        assertSame(Locale.FRENCH,        Locales.parseLanguage("fra", 0));
-        assertSame(Locale.CANADA_FRENCH, Locales.parseLanguage("fr_CA", 0));
-        assertSame(Locale.CANADA_FRENCH, Locales.parseLanguage("fra_CA", 0));
-        assertSame(Locale.CANADA_FRENCH, Locales.parseLanguage("fr_CAN", 0));
-        assertSame(Locale.CANADA_FRENCH, Locales.parseLanguage("fra_CAN", 0));
-        assertSame(Locale.ENGLISH,       Locales.parseLanguage("en", 0));
+        assertSame(Locale.FRENCH,        Locales.parse("fr"));
+        assertSame(Locale.FRENCH,        Locales.parse("fra"));
+        assertSame(Locale.CANADA_FRENCH, Locales.parse("fr_CA"));
+        assertSame(Locale.CANADA_FRENCH, Locales.parse("fra_CA"));
+        assertSame(Locale.CANADA_FRENCH, Locales.parse("fr_CAN"));
+        assertSame(Locale.CANADA_FRENCH, Locales.parse("fra_CAN"));
+        assertSame(Locale.ENGLISH,       Locales.parse("en"));
 
-        assertEquals(new Locale("de", "DE"),        Locales.parseLanguage("de_DE", 0));
-        assertEquals(new Locale("",   "GB"),        Locales.parseLanguage("_GB", 0));
-        assertEquals(new Locale("en", "US", "WIN"), Locales.parseLanguage("en_US_WIN", 0));
-        assertEquals(new Locale("de", "", "POSIX"), Locales.parseLanguage("de__POSIX", 0));
-        assertEquals(new Locale("fr", "", "MAC"),   Locales.parseLanguage("fr__MAC", 0));
+        assertEquals(new Locale("de", "DE"),        Locales.parse("de_DE"));
+        assertEquals(new Locale("",   "GB"),        Locales.parse("_GB"));
+        assertEquals(new Locale("en", "US", "WIN"), Locales.parse("en_US_WIN"));
+        assertEquals(new Locale("de", "", "POSIX"), Locales.parse("de__POSIX"));
+        assertEquals(new Locale("fr", "", "MAC"),   Locales.parse("fr__MAC"));
     }
 
     /**



Mime
View raw message