commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r922875 - /commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/NumberConverters.java
Date Sun, 14 Mar 2010 15:14:36 GMT
Author: adrianc
Date: Sun Mar 14 15:14:36 2010
New Revision: 922875

URL: http://svn.apache.org/viewvc?rev=922875&view=rev
Log:
Reordered number converters - no functional change.

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

Modified: commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/NumberConverters.java
URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/NumberConverters.java?rev=922875&r1=922874&r2=922875&view=diff
==============================================================================
--- commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/NumberConverters.java
(original)
+++ commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/NumberConverters.java
Sun Mar 14 15:14:36 2010
@@ -37,18 +37,6 @@ public class NumberConverters implements
         }
     }
 
-    public static abstract class AbstractStringToNumberConverter<N extends Number>
extends AbstractNumberConverter<String, N> {
-        public AbstractStringToNumberConverter(Class<N> targetClass) {
-            super(String.class, targetClass);
-        }
-
-        public N convert(String obj, Locale locale, TimeZone timeZone) throws ConversionException
{
-            return convert(fromString(obj, locale));
-        }
-
-        protected abstract N convert(Number number) throws ConversionException;
-    }
-
     public static abstract class AbstractNumberConverter<S, T> extends AbstractLocalizedConverter<S,
T> {
         protected AbstractNumberConverter(Class<S> sourceClass, Class<T> targetClass)
{
             super(sourceClass, targetClass);
@@ -75,53 +63,15 @@ public class NumberConverters implements
         protected abstract String format(N obj, NumberFormat nf) throws ConversionException;
     }
 
-    public static class GenericNumberToDouble<N extends Number> extends AbstractConverter<N,
Double> {
-        public GenericNumberToDouble(Class<N> sourceClass) {
-            super(sourceClass, Double.class);
-        }
-
-        public Double convert(N obj) throws ConversionException {
-            return obj.doubleValue();
-        }
-    }
-
-    public static class GenericNumberToFloat<N extends Number> extends AbstractConverter<N,
Float> {
-        public GenericNumberToFloat(Class<N> sourceClass) {
-            super(sourceClass, Float.class);
-        }
-
-        public Float convert(N obj) throws ConversionException {
-            return obj.floatValue();
-        }
-    }
-
-    public static class GenericNumberToInteger<N extends Number> extends AbstractConverter<N,
Integer> {
-        public GenericNumberToInteger(Class<N> sourceClass) {
-            super(sourceClass, Integer.class);
-        }
-
-        public Integer convert(N obj) throws ConversionException {
-            return obj.intValue();
-        }
-    }
-
-    public static class GenericNumberToLong<N extends Number> extends AbstractConverter<N,
Long> {
-        public GenericNumberToLong(Class<N> sourceClass) {
-            super(sourceClass, Long.class);
-        }
-
-        public Long convert(N obj) throws ConversionException {
-            return obj.longValue();
+    public static abstract class AbstractStringToNumberConverter<N extends Number>
extends AbstractNumberConverter<String, N> {
+        public AbstractStringToNumberConverter(Class<N> targetClass) {
+            super(String.class, targetClass);
         }
-    }
 
-    public static class GenericNumberToShort<N extends Number> extends AbstractConverter<N,
Short> {
-        public GenericNumberToShort(Class<N> sourceClass) {
-            super(sourceClass, Short.class);
-        }
+        protected abstract N convert(Number number) throws ConversionException;
 
-        public Short convert(N obj) throws ConversionException {
-            return obj.shortValue();
+        public N convert(String obj, Locale locale, TimeZone timeZone) throws ConversionException
{
+            return convert(fromString(obj, locale));
         }
     }
 
@@ -135,16 +85,6 @@ public class NumberConverters implements
         }
     }
 
-    public static class DoubleToBigDecimal extends AbstractConverter<Double, BigDecimal>
{
-        public DoubleToBigDecimal() {
-            super(Double.class, BigDecimal.class);
-        }
-
-        public BigDecimal convert(Double obj) throws ConversionException {
-            return BigDecimal.valueOf(obj.doubleValue());
-        }
-    }
-
     public static class BigIntegerToString extends AbstractNumberToStringConverter<BigInteger>
{
         public BigIntegerToString() {
             super(BigInteger.class);
@@ -165,17 +105,13 @@ public class NumberConverters implements
         }
     }
 
-    public static class StringToBigInteger extends AbstractStringToNumberConverter<BigInteger>
{
-        public StringToBigInteger() {
-            super(BigInteger.class);
-        }
-
-        public BigInteger convert(String obj) throws ConversionException {
-            return new BigInteger(obj);
+    public static class DoubleToBigDecimal extends AbstractConverter<Double, BigDecimal>
{
+        public DoubleToBigDecimal() {
+            super(Double.class, BigDecimal.class);
         }
 
-        protected BigInteger convert(Number number) throws ConversionException {
-            return BigInteger.valueOf(number.longValue());
+        public BigDecimal convert(Double obj) throws ConversionException {
+            return BigDecimal.valueOf(obj.doubleValue());
         }
     }
 
@@ -209,6 +145,56 @@ public class NumberConverters implements
         }
     }
 
+    public static class GenericNumberToDouble<N extends Number> extends AbstractConverter<N,
Double> {
+        public GenericNumberToDouble(Class<N> sourceClass) {
+            super(sourceClass, Double.class);
+        }
+
+        public Double convert(N obj) throws ConversionException {
+            return obj.doubleValue();
+        }
+    }
+
+    public static class GenericNumberToFloat<N extends Number> extends AbstractConverter<N,
Float> {
+        public GenericNumberToFloat(Class<N> sourceClass) {
+            super(sourceClass, Float.class);
+        }
+
+        public Float convert(N obj) throws ConversionException {
+            return obj.floatValue();
+        }
+    }
+
+    public static class GenericNumberToInteger<N extends Number> extends AbstractConverter<N,
Integer> {
+        public GenericNumberToInteger(Class<N> sourceClass) {
+            super(sourceClass, Integer.class);
+        }
+
+        public Integer convert(N obj) throws ConversionException {
+            return obj.intValue();
+        }
+    }
+
+    public static class GenericNumberToLong<N extends Number> extends AbstractConverter<N,
Long> {
+        public GenericNumberToLong(Class<N> sourceClass) {
+            super(sourceClass, Long.class);
+        }
+
+        public Long convert(N obj) throws ConversionException {
+            return obj.longValue();
+        }
+    }
+
+    public static class GenericNumberToShort<N extends Number> extends AbstractConverter<N,
Short> {
+        public GenericNumberToShort(Class<N> sourceClass) {
+            super(sourceClass, Short.class);
+        }
+
+        public Short convert(N obj) throws ConversionException {
+            return obj.shortValue();
+        }
+    }
+
     public static class IntegerToBigDecimal extends AbstractConverter<Integer, BigDecimal>
{
         public IntegerToBigDecimal() {
             super(Integer.class, BigDecimal.class);
@@ -284,12 +270,26 @@ public class NumberConverters implements
             super(BigDecimal.class);
         }
 
+        protected BigDecimal convert(Number number) throws ConversionException {
+            return BigDecimal.valueOf(number.doubleValue());
+        }
+
         public BigDecimal convert(String obj) throws ConversionException {
             return BigDecimal.valueOf(Double.valueOf(obj));
         }
+    }
 
-        protected BigDecimal convert(Number number) throws ConversionException {
-            return BigDecimal.valueOf(number.doubleValue());
+    public static class StringToBigInteger extends AbstractStringToNumberConverter<BigInteger>
{
+        public StringToBigInteger() {
+            super(BigInteger.class);
+        }
+
+        protected BigInteger convert(Number number) throws ConversionException {
+            return BigInteger.valueOf(number.longValue());
+        }
+
+        public BigInteger convert(String obj) throws ConversionException {
+            return new BigInteger(obj);
         }
     }
 
@@ -308,13 +308,13 @@ public class NumberConverters implements
             super(Double.class);
         }
 
-        public Double convert(String obj) throws ConversionException {
-            return Double.valueOf(obj);
-        }
-
         protected Double convert(Number number) throws ConversionException {
             return number.doubleValue();
         }
+
+        public Double convert(String obj) throws ConversionException {
+            return Double.valueOf(obj);
+        }
     }
 
     public static class StringToFloat extends AbstractStringToNumberConverter<Float>
{
@@ -322,13 +322,13 @@ public class NumberConverters implements
             super(Float.class);
         }
 
-        public Float convert(String obj) throws ConversionException {
-            return Float.valueOf(obj);
-        }
-
         protected Float convert(Number number) throws ConversionException {
             return number.floatValue();
         }
+
+        public Float convert(String obj) throws ConversionException {
+            return Float.valueOf(obj);
+        }
     }
 
     public static class StringToInteger extends AbstractStringToNumberConverter<Integer>
{
@@ -336,13 +336,13 @@ public class NumberConverters implements
             super(Integer.class);
         }
 
-        public Integer convert(String obj) throws ConversionException {
-            return Integer.valueOf(obj);
-        }
-
         protected Integer convert(Number number) throws ConversionException {
             return number.intValue();
         }
+
+        public Integer convert(String obj) throws ConversionException {
+            return Integer.valueOf(obj);
+        }
     }
 
     public static class StringToLong extends AbstractStringToNumberConverter<Long>
{
@@ -350,13 +350,13 @@ public class NumberConverters implements
             super(Long.class);
         }
 
-        public Long convert(String obj) throws ConversionException {
-            return Long.valueOf(obj);
-        }
-
         protected Long convert(Number number) throws ConversionException {
             return number.longValue();
         }
+
+        public Long convert(String obj) throws ConversionException {
+            return Long.valueOf(obj);
+        }
     }
 
     public static class StringToShort extends AbstractConverter<String, Short> {
@@ -371,7 +371,6 @@ public class NumberConverters implements
 
     public void loadConverters() {
         Converters.loadContainedConverters(NumberConverters.class);
-
         Converters.registerConverter(new GenericNumberToDouble<BigDecimal>(BigDecimal.class));
         Converters.registerConverter(new GenericNumberToDouble<BigInteger>(BigInteger.class));
         Converters.registerConverter(new GenericNumberToDouble<Byte>(Byte.class));
@@ -379,7 +378,6 @@ public class NumberConverters implements
         Converters.registerConverter(new GenericNumberToDouble<Integer>(Integer.class));
         Converters.registerConverter(new GenericNumberToDouble<Long>(Long.class));
         Converters.registerConverter(new GenericNumberToDouble<Short>(Short.class));
-
         Converters.registerConverter(new GenericNumberToFloat<BigDecimal>(BigDecimal.class));
         Converters.registerConverter(new GenericNumberToFloat<BigInteger>(BigInteger.class));
         Converters.registerConverter(new GenericNumberToFloat<Byte>(Byte.class));
@@ -387,7 +385,6 @@ public class NumberConverters implements
         Converters.registerConverter(new GenericNumberToFloat<Integer>(Integer.class));
         Converters.registerConverter(new GenericNumberToFloat<Long>(Long.class));
         Converters.registerConverter(new GenericNumberToFloat<Short>(Short.class));
-
         Converters.registerConverter(new GenericNumberToInteger<BigDecimal>(BigDecimal.class));
         Converters.registerConverter(new GenericNumberToInteger<BigInteger>(BigInteger.class));
         Converters.registerConverter(new GenericNumberToInteger<Byte>(Byte.class));
@@ -395,7 +392,6 @@ public class NumberConverters implements
         Converters.registerConverter(new GenericNumberToInteger<Float>(Float.class));
         Converters.registerConverter(new GenericNumberToInteger<Long>(Long.class));
         Converters.registerConverter(new GenericNumberToInteger<Short>(Short.class));
-
         Converters.registerConverter(new GenericSingletonToList<BigDecimal>(BigDecimal.class));
         Converters.registerConverter(new GenericSingletonToList<BigInteger>(BigInteger.class));
         Converters.registerConverter(new GenericSingletonToList<Byte>(Byte.class));
@@ -404,7 +400,6 @@ public class NumberConverters implements
         Converters.registerConverter(new GenericSingletonToList<Integer>(Integer.class));
         Converters.registerConverter(new GenericSingletonToList<Long>(Long.class));
         Converters.registerConverter(new GenericSingletonToList<Short>(Short.class));
-
         Converters.registerConverter(new GenericNumberToLong<BigDecimal>(BigDecimal.class));
         Converters.registerConverter(new GenericNumberToLong<BigInteger>(BigInteger.class));
         Converters.registerConverter(new GenericNumberToLong<Byte>(Byte.class));
@@ -412,7 +407,6 @@ public class NumberConverters implements
         Converters.registerConverter(new GenericNumberToLong<Float>(Float.class));
         Converters.registerConverter(new GenericNumberToLong<Integer>(Integer.class));
         Converters.registerConverter(new GenericNumberToLong<Short>(Short.class));
-
         Converters.registerConverter(new GenericSingletonToSet<BigDecimal>(BigDecimal.class));
         Converters.registerConverter(new GenericSingletonToSet<BigInteger>(BigInteger.class));
         Converters.registerConverter(new GenericSingletonToSet<Byte>(Byte.class));
@@ -421,7 +415,6 @@ public class NumberConverters implements
         Converters.registerConverter(new GenericSingletonToSet<Integer>(Integer.class));
         Converters.registerConverter(new GenericSingletonToSet<Long>(Long.class));
         Converters.registerConverter(new GenericSingletonToSet<Short>(Short.class));
-
         Converters.registerConverter(new GenericNumberToShort<Integer>(Integer.class));
         Converters.registerConverter(new GenericNumberToShort<Long>(Long.class));
     }



Mime
View raw message