commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r933050 - /commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/MiscConverters.java
Date Mon, 12 Apr 2010 00:07:00 GMT
Author: adrianc
Date: Mon Apr 12 00:07:00 2010
New Revision: 933050

URL: http://svn.apache.org/viewvc?rev=933050&view=rev
Log:
Sorted MiscConverters classes - no functional change.

Modified:
    commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/MiscConverters.java

Modified: commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/MiscConverters.java
URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/MiscConverters.java?rev=933050&r1=933049&r2=933050&view=diff
==============================================================================
--- commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/MiscConverters.java
(original)
+++ commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/MiscConverters.java
Mon Apr 12 00:07:00 2010
@@ -34,6 +34,13 @@ import java.util.regex.Pattern;
 /** Miscellaneous Converter classes. */
 public class MiscConverters implements ConverterLoader {
 
+    public void loadConverters() {
+        Converters.loadContainedConverters(MiscConverters.class);
+        Converters.registerConverter(new GenericToStringConverter<Locale>(Locale.class));
+        Converters.registerConverter(new GenericToStringConverter<UUID>(UUID.class));
+        Converters.registerConverter(new GenericToStringConverter<Pattern>(Pattern.class));
+    }
+
     public static class BlobToByteArray extends AbstractConverter<Blob, byte[]> {
         public BlobToByteArray() {
             super(Blob.class, byte[].class);
@@ -79,6 +86,20 @@ public class MiscConverters implements C
         }
     }
 
+    public static class ByteArrayToByteBuffer extends AbstractConverter<byte[], ByteBuffer>
{
+        public ByteArrayToByteBuffer() {
+            super(byte[].class, ByteBuffer.class);
+        }
+
+        public ByteBuffer convert(byte[] obj) throws ConversionException {
+            try {
+                return ByteBuffer.wrap(obj);
+            } catch (Exception e) {
+                throw new ConversionException(e);
+            }
+        }
+    }
+
     public static class ByteBufferToByteArray extends AbstractConverter<ByteBuffer, byte[]>
{
         public ByteBufferToByteArray() {
             super(ByteBuffer.class, byte[].class);
@@ -93,17 +114,13 @@ public class MiscConverters implements C
         }
     }
 
-    public static class ByteArrayToByteBuffer extends AbstractConverter<byte[], ByteBuffer>
{
-        public ByteArrayToByteBuffer() {
-            super(byte[].class, ByteBuffer.class);
+    public static class CharsetToString extends AbstractConverter<Charset, String>
{
+        public CharsetToString() {
+            super(Charset.class, String.class);
         }
 
-        public ByteBuffer convert(byte[] obj) throws ConversionException {
-            try {
-                return ByteBuffer.wrap(obj);
-            } catch (Exception e) {
-                throw new ConversionException(e);
-            }
+        public String convert(Charset obj) throws ConversionException {
+            return obj.name();
         }
     }
 
@@ -138,6 +155,16 @@ public class MiscConverters implements C
         }
     }
 
+    public static class DecimalFormatToString extends AbstractConverter<DecimalFormat,
String> {
+        public DecimalFormatToString() {
+            super(DecimalFormat.class, String.class);
+        }
+
+        public String convert(DecimalFormat obj) throws ConversionException {
+            return obj.toPattern();
+        }
+    }
+
     public static class EnumToString extends AbstractConverter<Enum, String> {
         public EnumToString() {
             super(Enum.class, String.class);
@@ -147,52 +174,42 @@ public class MiscConverters implements C
             return Enum.class.isAssignableFrom(sourceClass) && String.class.isAssignableFrom(targetClass);
         }
 
-        public String convert(Enum obj) throws ConversionException {
-            return obj.name();
-        }
-
         public String convert(Class<? extends String> targetClass, Enum obj) throws
ConversionException {
             return convert(obj);
         }
 
+        public String convert(Enum obj) throws ConversionException {
+            return obj.toString();
+        }
+
         public Class<? super Enum> getSourceClass() {
             return null;
         }
     }
 
-    public static class StringToEnumConverterCreator implements ConverterCreator, ConverterLoader
{
-        public void loadConverters() {
-            Converters.registerCreator(this);
-        }
-
-        public <S, T> Converter<S, T> createConverter(Class<S> sourceClass,
Class<T> targetClass) {
-            if (String.class == sourceClass && Enum.class.isAssignableFrom(targetClass))
{
-                return Util.cast(new StringToEnum());
-            } else {
-                return null;
-            }
+    public static class NotAConverter {
+        protected NotAConverter() {
+            throw new Error("Should not be loaded");
         }
     }
 
-    private static class StringToEnum<E extends Enum<E>> extends AbstractConverter<String,
E> {
-        public StringToEnum() {
-            super(String.class, Enum.class);
-        }
-
-        public boolean canConvert(Class<?> sourceClass, Class<?> targetClass)
{
-            return String.class.isAssignableFrom(sourceClass) && Enum.class.isAssignableFrom(targetClass);
+    public static class SimpleDateFormatToString extends AbstractConverter<SimpleDateFormat,
String> {
+        public SimpleDateFormatToString() {
+            super(SimpleDateFormat.class, String.class);
         }
 
-        public E convert(String obj) throws ConversionException {
-            throw new UnsupportedOperationException();
+        public String convert(SimpleDateFormat obj) throws ConversionException {
+            return obj.toPattern();
         }
+    }
 
-        public E convert(Class<? extends E> targetClass, String obj) throws ConversionException
{
-            return Enum.valueOf(Util.<Class<E>>cast(targetClass), obj);
+    public static class StringToCharset extends AbstractConverter<String, Charset>
{
+        public StringToCharset() {
+            super(String.class, Charset.class);
         }
 
-        public Class<? super Enum> getTargetClass() {
-            return null;
+        public Charset convert(String obj) throws ConversionException {
+            return Charset.forName(obj);
         }
     }
 
@@ -210,26 +227,6 @@ public class MiscConverters implements C
         }
     }
 
-    public static class StringToLocale extends AbstractConverter<String, Locale> {
-        public StringToLocale() {
-            super(String.class, Locale.class);
-        }
-
-        public Locale convert(String obj) throws ConversionException {
-            return new Locale(obj);
-        }
-    }
-
-    public static class DecimalFormatToString extends AbstractConverter<DecimalFormat,
String> {
-        public DecimalFormatToString() {
-            super(DecimalFormat.class, String.class);
-        }
-
-        public String convert(DecimalFormat obj) throws ConversionException {
-            return obj.toPattern();
-        }
-    }
-
     public static class StringToDecimalFormat extends AbstractConverter<String, DecimalFormat>
{
         public StringToDecimalFormat() {
             super(String.class, DecimalFormat.class);
@@ -240,53 +237,49 @@ public class MiscConverters implements C
         }
     }
 
-    public static class SimpleDateFormatToString extends AbstractConverter<SimpleDateFormat,
String> {
-        public SimpleDateFormatToString() {
-            super(SimpleDateFormat.class, String.class);
-        }
-
-        public String convert(SimpleDateFormat obj) throws ConversionException {
-            return obj.toPattern();
+    private static class StringToEnum<E extends Enum<E>> extends AbstractConverter<String,
E> {
+        public StringToEnum() {
+            super(String.class, Enum.class);
         }
-    }
 
-    public static class StringToSimpleDateFormat extends AbstractConverter<String, SimpleDateFormat>
{
-        public StringToSimpleDateFormat() {
-            super(String.class, SimpleDateFormat.class);
+        public boolean canConvert(Class<?> sourceClass, Class<?> targetClass)
{
+            return String.class.isAssignableFrom(sourceClass) && Enum.class.isAssignableFrom(targetClass);
         }
 
-        public SimpleDateFormat convert(String obj) throws ConversionException {
-            return new SimpleDateFormat(obj);
+        public E convert(Class<? extends E> targetClass, String obj) throws ConversionException
{
+            return Enum.valueOf(Util.<Class<E>>cast(targetClass), obj);
         }
-    }
 
-    public static class CharsetToString extends AbstractConverter<Charset, String>
{
-        public CharsetToString() {
-            super(Charset.class, String.class);
+        public E convert(String obj) throws ConversionException {
+            throw new UnsupportedOperationException();
         }
 
-        public String convert(Charset obj) throws ConversionException {
-            return obj.name();
+        public Class<? super Enum> getTargetClass() {
+            return null;
         }
     }
 
-    public static class StringToCharset extends AbstractConverter<String, Charset>
{
-        public StringToCharset() {
-            super(String.class, Charset.class);
+    public static class StringToEnumConverterCreator implements ConverterCreator, ConverterLoader
{
+        public <S, T> Converter<S, T> createConverter(Class<S> sourceClass,
Class<T> targetClass) {
+            if (String.class == sourceClass && Enum.class.isAssignableFrom(targetClass))
{
+                return Util.cast(new StringToEnum());
+            } else {
+                return null;
+            }
         }
 
-        public Charset convert(String obj) throws ConversionException {
-            return Charset.forName(obj);
+        public void loadConverters() {
+            Converters.registerCreator(this);
         }
     }
 
-    public static class StringToUUID extends AbstractConverter<String, UUID> {
-        public StringToUUID() {
-            super(String.class, UUID.class);
+    public static class StringToLocale extends AbstractConverter<String, Locale> {
+        public StringToLocale() {
+            super(String.class, Locale.class);
         }
 
-        public UUID convert(String obj) throws ConversionException {
-            return UUID.fromString(obj);
+        public Locale convert(String obj) throws ConversionException {
+            return new Locale(obj);
         }
     }
 
@@ -300,16 +293,23 @@ public class MiscConverters implements C
         }
     }
 
-    public static class NotAConverter {
-        protected NotAConverter() {
-            throw new Error("Should not be loaded");
+    public static class StringToSimpleDateFormat extends AbstractConverter<String, SimpleDateFormat>
{
+        public StringToSimpleDateFormat() {
+            super(String.class, SimpleDateFormat.class);
+        }
+
+        public SimpleDateFormat convert(String obj) throws ConversionException {
+            return new SimpleDateFormat(obj);
         }
     }
 
-    public void loadConverters() {
-        Converters.loadContainedConverters(MiscConverters.class);
-        Converters.registerConverter(new GenericToStringConverter<Locale>(Locale.class));
-        Converters.registerConverter(new GenericToStringConverter<UUID>(UUID.class));
-        Converters.registerConverter(new GenericToStringConverter<Pattern>(Pattern.class));
+    public static class StringToUUID extends AbstractConverter<String, UUID> {
+        public StringToUUID() {
+            super(String.class, UUID.class);
+        }
+
+        public UUID convert(String obj) throws ConversionException {
+            return UUID.fromString(obj);
+        }
     }
 }



Mime
View raw message