Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B8088108F6 for ; Wed, 9 Oct 2013 21:28:41 +0000 (UTC) Received: (qmail 39964 invoked by uid 500); 9 Oct 2013 21:26:44 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 39631 invoked by uid 500); 9 Oct 2013 21:26:35 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 39465 invoked by uid 99); 9 Oct 2013 21:26:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Oct 2013 21:26:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Oct 2013 21:26:27 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C51242388BEC for ; Wed, 9 Oct 2013 21:25:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r881939 [8/41] - in /websites/production/commons/content/sandbox/commons-convert: ./ apidocs/ apidocs/org/apache/commons/convert/ apidocs/org/apache/commons/convert/class-use/ apidocs/src-html/org/apache/commons/convert/ cobertura/ xref/ xr... Date: Wed, 09 Oct 2013 21:25:36 -0000 To: commits@commons.apache.org From: adrianc@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131009212542.C51242388BEC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: websites/production/commons/content/sandbox/commons-convert/apidocs/src-html/org/apache/commons/convert/NumberConverters.AbstractStringToNumberConverter.html ============================================================================== --- websites/production/commons/content/sandbox/commons-convert/apidocs/src-html/org/apache/commons/convert/NumberConverters.AbstractStringToNumberConverter.html (original) +++ websites/production/commons/content/sandbox/commons-convert/apidocs/src-html/org/apache/commons/convert/NumberConverters.AbstractStringToNumberConverter.html Wed Oct 9 21:25:34 2013 @@ -23,18 +23,18 @@ 020 021 import java.math.BigDecimal; 022 import java.math.BigInteger; -023 import java.text.NumberFormat; -024 import java.text.ParseException; -025 import java.util.Locale; -026 import java.util.TimeZone; -027 -028 /** Number Converter classes. */ -029 public class NumberConverters implements ConverterLoader { -030 -031 protected static final Class<?>[] classArray = {BigDecimal.class, BigInteger.class, Byte.class, Double.class, Integer.class, Float.class, Long.class, Short.class}; -032 -033 protected static Number fromString(String str, Locale locale) throws ConversionException { -034 NumberFormat nf = NumberFormat.getNumberInstance(locale); +023 import java.text.DecimalFormat; +024 import java.text.NumberFormat; +025 import java.text.ParseException; +026 import java.util.Locale; +027 import java.util.TimeZone; +028 +029 /** Number Converter classes. */ +030 public class NumberConverters implements ConverterLoader { +031 +032 protected static final Class<?>[] classArray = {BigDecimal.class, BigInteger.class, Byte.class, Double.class, Integer.class, Float.class, Long.class, Short.class}; +033 +034 protected static Number fromString(String str, NumberFormat nf) throws ConversionException { 035 try { 036 return nf.parse(str); 037 } catch (ParseException e) { @@ -65,426 +65,424 @@ 062 } 063 } 064 -065 public static abstract class AbstractNumberConverter<S, T> extends AbstractLocalizedConverter<S, T> { -066 protected AbstractNumberConverter(Class<S> sourceClass, Class<T> targetClass) { -067 super(sourceClass, targetClass); -068 } -069 -070 public T convert(S obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException { -071 return convert(obj, locale, null); +065 /** +066 * An abstract <code>Number</code> to <code>String</code> converter class +067 * that implements some of the <code>LocalizedConverter</code> methods. +068 */ +069 public static abstract class AbstractNumberToStringConverter<N extends Number> extends AbstractLocalizedConverter<N, String> { +070 public AbstractNumberToStringConverter(Class<N> sourceClass) { +071 super(sourceClass, String.class); 072 } -073 } -074 -075 /** -076 * An abstract <code>Number</code> to <code>String</code> converter class -077 * that implements some of the <code>LocalizedConverter</code> methods. -078 */ -079 public static abstract class AbstractNumberToStringConverter<N extends Number> extends AbstractNumberConverter<N, String> { -080 public AbstractNumberToStringConverter(Class<N> sourceClass) { -081 super(sourceClass, String.class); -082 } -083 -084 public String convert(N obj) throws ConversionException { -085 return obj.toString(); -086 } -087 -088 public String convert(N obj, Locale locale, TimeZone timeZone) throws ConversionException { -089 return format(obj, NumberFormat.getNumberInstance(locale)); -090 } -091 -092 protected abstract String format(N obj, NumberFormat nf) throws ConversionException; -093 } -094 -095 /** -096 * An abstract <code>String</code> to <code>Number</code> converter class -097 * that implements some of the <code>LocalizedConverter</code> methods. -098 */ -099 public static abstract class AbstractStringToNumberConverter<N extends Number> extends AbstractNumberConverter<String, N> { -100 public AbstractStringToNumberConverter(Class<N> targetClass) { -101 super(String.class, targetClass); -102 } -103 -104 protected abstract N convert(Number number) throws ConversionException; -105 -106 public N convert(String obj, Locale locale, TimeZone timeZone) throws ConversionException { -107 return convert(fromString(obj, locale)); -108 } -109 } -110 -111 /** -112 * An object that converts a <code>BigDecimal</code> to a -113 * <code>String</code>. -114 */ -115 public static class BigDecimalToString extends AbstractNumberToStringConverter<BigDecimal> { -116 public BigDecimalToString() { -117 super(BigDecimal.class); -118 } -119 -120 protected String format(BigDecimal obj, NumberFormat nf) throws ConversionException { -121 return nf.format(obj.doubleValue()); -122 } -123 } -124 -125 /** -126 * An object that converts a <code>BigInteger</code> to a -127 * <code>String</code>. -128 */ -129 public static class BigIntegerToString extends AbstractNumberToStringConverter<BigInteger> { -130 public BigIntegerToString() { -131 super(BigInteger.class); -132 } -133 -134 protected String format(BigInteger obj, NumberFormat nf) throws ConversionException { -135 return nf.format(obj.doubleValue()); -136 } -137 } -138 -139 /** -140 * An object that converts a <code>Byte</code> to a -141 * <code>String</code>. -142 */ -143 public static class ByteToString extends AbstractNumberToStringConverter<Byte> { -144 public ByteToString() { -145 super(Byte.class); -146 } -147 -148 protected String format(Byte obj, NumberFormat nf) throws ConversionException { -149 return nf.format(obj.floatValue()); -150 } -151 } -152 -153 /** -154 * An object that converts a <code>Double</code> to a -155 * <code>String</code>. -156 */ -157 public static class DoubleToString extends AbstractNumberToStringConverter<Double> { -158 public DoubleToString() { -159 super(Double.class); -160 } -161 -162 protected String format(Double obj, NumberFormat nf) throws ConversionException { -163 return nf.format(obj.doubleValue()); -164 } -165 } -166 -167 /** -168 * An object that converts a <code>Float</code> to a -169 * <code>String</code>. -170 */ -171 public static class FloatToString extends AbstractNumberToStringConverter<Float> { -172 public FloatToString() { -173 super(Float.class); -174 } -175 -176 protected String format(Float obj, NumberFormat nf) throws ConversionException { -177 return nf.format(obj.floatValue()); -178 } -179 } -180 -181 /** -182 * An object that converts a <code>Number</code> to a -183 * <code>BigDecimal</code>. -184 */ -185 public static class GenericNumberToBigDecimal<N extends Number> extends AbstractConverter<N, BigDecimal> { -186 public GenericNumberToBigDecimal(Class<N> sourceClass) { -187 super(sourceClass, BigDecimal.class); -188 } -189 -190 public BigDecimal convert(N obj) throws ConversionException { -191 return new BigDecimal(obj.doubleValue()); -192 } -193 } -194 -195 /** -196 * An object that converts a <code>Number</code> to a -197 * <code>BigInteger</code>. -198 */ -199 public static class GenericNumberToBigInteger<N extends Number> extends AbstractConverter<N, BigInteger> { -200 public GenericNumberToBigInteger(Class<N> sourceClass) { -201 super(sourceClass, BigInteger.class); -202 } -203 -204 public BigInteger convert(N obj) throws ConversionException { -205 return BigInteger.valueOf(obj.longValue()); -206 } -207 } -208 -209 /** -210 * An object that converts a <code>Number</code> to a -211 * <code>Byte</code>. -212 */ -213 public static class GenericNumberToByte<N extends Number> extends AbstractConverter<N, Byte> { -214 public GenericNumberToByte(Class<N> sourceClass) { -215 super(sourceClass, Byte.class); -216 } -217 -218 public Byte convert(N obj) throws ConversionException { -219 return Byte.valueOf(obj.byteValue()); -220 } -221 } -222 -223 /** -224 * An object that converts a <code>Number</code> to a -225 * <code>Double</code>. -226 */ -227 public static class GenericNumberToDouble<N extends Number> extends AbstractConverter<N, Double> { -228 public GenericNumberToDouble(Class<N> sourceClass) { -229 super(sourceClass, Double.class); -230 } -231 -232 public Double convert(N obj) throws ConversionException { -233 return obj.doubleValue(); -234 } -235 } -236 -237 /** -238 * An object that converts a <code>Number</code> to a -239 * <code>Float</code>. -240 */ -241 public static class GenericNumberToFloat<N extends Number> extends AbstractConverter<N, Float> { -242 public GenericNumberToFloat(Class<N> sourceClass) { -243 super(sourceClass, Float.class); -244 } -245 -246 public Float convert(N obj) throws ConversionException { -247 return obj.floatValue(); -248 } -249 } -250 -251 /** -252 * An object that converts a <code>Number</code> to an -253 * <code>Integer</code>. -254 */ -255 public static class GenericNumberToInteger<N extends Number> extends AbstractConverter<N, Integer> { -256 public GenericNumberToInteger(Class<N> sourceClass) { -257 super(sourceClass, Integer.class); -258 } -259 -260 public Integer convert(N obj) throws ConversionException { -261 return obj.intValue(); -262 } -263 } -264 -265 /** -266 * An object that converts a <code>Number</code> to a -267 * <code>Long</code>. -268 */ -269 public static class GenericNumberToLong<N extends Number> extends AbstractConverter<N, Long> { -270 public GenericNumberToLong(Class<N> sourceClass) { -271 super(sourceClass, Long.class); -272 } -273 -274 public Long convert(N obj) throws ConversionException { -275 return obj.longValue(); -276 } -277 } -278 -279 /** -280 * An object that converts a <code>Number</code> to a -281 * <code>Short</code>. -282 */ -283 public static class GenericNumberToShort<N extends Number> extends AbstractConverter<N, Short> { -284 public GenericNumberToShort(Class<N> sourceClass) { -285 super(sourceClass, Short.class); -286 } -287 -288 public Short convert(N obj) throws ConversionException { -289 return obj.shortValue(); -290 } -291 } -292 -293 /** -294 * An object that converts an <code>Integer</code> to a -295 * <code>String</code>. -296 */ -297 public static class IntegerToString extends AbstractNumberToStringConverter<Integer> { -298 public IntegerToString() { -299 super(Integer.class); -300 } -301 -302 protected String format(Integer obj, NumberFormat nf) throws ConversionException { -303 return nf.format(obj.intValue()); -304 } -305 } -306 -307 /** -308 * An object that converts a <code>Long</code> to a -309 * <code>BigDecimal</code>. -310 */ -311 public static class LongToBigDecimal extends AbstractConverter<Long, BigDecimal> { -312 public LongToBigDecimal() { -313 super(Long.class, BigDecimal.class); -314 } -315 -316 public BigDecimal convert(Long obj) throws ConversionException { -317 return BigDecimal.valueOf(obj.longValue()); -318 } -319 } -320 -321 /** -322 * An object that converts a <code>Long</code> to a -323 * <code>String</code>. -324 */ -325 public static class LongToString extends AbstractNumberToStringConverter<Long> { -326 public LongToString() { -327 super(Long.class); -328 } -329 -330 protected String format(Long obj, NumberFormat nf) throws ConversionException { -331 return nf.format(obj.longValue()); -332 } -333 } -334 -335 /** -336 * An object that converts a <code>Short</code> to a -337 * <code>String</code>. -338 */ -339 public static class ShortToString extends AbstractNumberToStringConverter<Short> { -340 public ShortToString() { -341 super(Short.class); -342 } -343 -344 protected String format(Short obj, NumberFormat nf) throws ConversionException { -345 return nf.format(obj.floatValue()); -346 } -347 } -348 -349 /** -350 * An object that converts a <code>String</code> to a -351 * <code>BigDecimal</code>. -352 */ -353 public static class StringToBigDecimal extends AbstractStringToNumberConverter<BigDecimal> { -354 public StringToBigDecimal() { -355 super(BigDecimal.class); -356 } -357 -358 protected BigDecimal convert(Number number) throws ConversionException { -359 return BigDecimal.valueOf(number.doubleValue()); -360 } -361 -362 public BigDecimal convert(String obj) throws ConversionException { -363 return BigDecimal.valueOf(Double.valueOf(obj)); -364 } -365 } -366 -367 /** -368 * An object that converts a <code>String</code> to a -369 * <code>BigInteger</code>. -370 */ -371 public static class StringToBigInteger extends AbstractStringToNumberConverter<BigInteger> { -372 public StringToBigInteger() { -373 super(BigInteger.class); -374 } -375 -376 protected BigInteger convert(Number number) throws ConversionException { -377 return BigInteger.valueOf(number.longValue()); -378 } -379 -380 public BigInteger convert(String obj) throws ConversionException { -381 return new BigInteger(obj); -382 } -383 } -384 -385 /** -386 * An object that converts a <code>String</code> to a -387 * <code>Byte</code>. -388 */ -389 public static class StringToByte extends AbstractConverter<String, Byte> { -390 public StringToByte() { -391 super(String.class, Byte.class); -392 } -393 -394 public Byte convert(String obj) throws ConversionException { -395 return Byte.valueOf(obj); -396 } -397 } -398 -399 /** -400 * An object that converts a <code>String</code> to a -401 * <code>Double</code>. -402 */ -403 public static class StringToDouble extends AbstractStringToNumberConverter<Double> { -404 public StringToDouble() { -405 super(Double.class); -406 } -407 -408 protected Double convert(Number number) throws ConversionException { -409 return number.doubleValue(); -410 } -411 -412 public Double convert(String obj) throws ConversionException { -413 return Double.valueOf(obj); -414 } -415 } -416 -417 /** -418 * An object that converts a <code>String</code> to a -419 * <code>Float</code>. -420 */ -421 public static class StringToFloat extends AbstractStringToNumberConverter<Float> { -422 public StringToFloat() { -423 super(Float.class); -424 } -425 -426 protected Float convert(Number number) throws ConversionException { -427 return number.floatValue(); -428 } -429 -430 public Float convert(String obj) throws ConversionException { -431 return Float.valueOf(obj); -432 } -433 } -434 -435 /** -436 * An object that converts a <code>String</code> to an -437 * <code>Integer</code>. -438 */ -439 public static class StringToInteger extends AbstractStringToNumberConverter<Integer> { -440 public StringToInteger() { -441 super(Integer.class); -442 } -443 -444 protected Integer convert(Number number) throws ConversionException { -445 return number.intValue(); -446 } -447 -448 public Integer convert(String obj) throws ConversionException { -449 return Integer.valueOf(obj); -450 } -451 } -452 -453 /** -454 * An object that converts a <code>String</code> to a -455 * <code>Long</code>. -456 */ -457 public static class StringToLong extends AbstractStringToNumberConverter<Long> { -458 public StringToLong() { -459 super(Long.class); -460 } -461 -462 protected Long convert(Number number) throws ConversionException { -463 return number.longValue(); -464 } -465 -466 public Long convert(String obj) throws ConversionException { -467 return Long.valueOf(obj); -468 } -469 } -470 -471 /** -472 * An object that converts a <code>String</code> to a -473 * <code>Short</code>. -474 */ -475 public static class StringToShort extends AbstractConverter<String, Short> { -476 public StringToShort() { -477 super(String.class, Short.class); -478 } -479 -480 public Short convert(String obj) throws ConversionException { -481 return Short.valueOf(obj); -482 } -483 } -484 } +073 +074 public String convert(N obj) throws ConversionException { +075 return obj.toString(); +076 } +077 +078 public String convert(N obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException { +079 if (formatString == null) { +080 return format(obj, NumberFormat.getNumberInstance(locale)); +081 } else { +082 return format(obj, new DecimalFormat(formatString)); +083 } +084 } +085 +086 protected abstract String format(N obj, NumberFormat nf) throws ConversionException; +087 } +088 +089 /** +090 * An abstract <code>String</code> to <code>Number</code> converter class +091 * that implements some of the <code>LocalizedConverter</code> methods. +092 */ +093 public static abstract class AbstractStringToNumberConverter<N extends Number> extends AbstractLocalizedConverter<String, N> { +094 public AbstractStringToNumberConverter(Class<N> targetClass) { +095 super(String.class, targetClass); +096 } +097 +098 protected abstract N convert(Number number) throws ConversionException; +099 +100 public N convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException { +101 if (formatString == null) { +102 return convert(fromString(obj, NumberFormat.getNumberInstance(locale))); +103 } else { +104 return convert(fromString(obj, new DecimalFormat(formatString))); +105 } +106 } +107 } +108 +109 /** +110 * An object that converts a <code>BigDecimal</code> to a +111 * <code>String</code>. +112 */ +113 public static class BigDecimalToString extends AbstractNumberToStringConverter<BigDecimal> { +114 public BigDecimalToString() { +115 super(BigDecimal.class); +116 } +117 +118 protected String format(BigDecimal obj, NumberFormat nf) throws ConversionException { +119 return nf.format(obj.doubleValue()); +120 } +121 } +122 +123 /** +124 * An object that converts a <code>BigInteger</code> to a +125 * <code>String</code>. +126 */ +127 public static class BigIntegerToString extends AbstractNumberToStringConverter<BigInteger> { +128 public BigIntegerToString() { +129 super(BigInteger.class); +130 } +131 +132 protected String format(BigInteger obj, NumberFormat nf) throws ConversionException { +133 return nf.format(obj.doubleValue()); +134 } +135 } +136 +137 /** +138 * An object that converts a <code>Byte</code> to a +139 * <code>String</code>. +140 */ +141 public static class ByteToString extends AbstractNumberToStringConverter<Byte> { +142 public ByteToString() { +143 super(Byte.class); +144 } +145 +146 protected String format(Byte obj, NumberFormat nf) throws ConversionException { +147 return nf.format(obj.floatValue()); +148 } +149 } +150 +151 /** +152 * An object that converts a <code>Double</code> to a +153 * <code>String</code>. +154 */ +155 public static class DoubleToString extends AbstractNumberToStringConverter<Double> { +156 public DoubleToString() { +157 super(Double.class); +158 } +159 +160 protected String format(Double obj, NumberFormat nf) throws ConversionException { +161 return nf.format(obj.doubleValue()); +162 } +163 } +164 +165 /** +166 * An object that converts a <code>Float</code> to a +167 * <code>String</code>. +168 */ +169 public static class FloatToString extends AbstractNumberToStringConverter<Float> { +170 public FloatToString() { +171 super(Float.class); +172 } +173 +174 protected String format(Float obj, NumberFormat nf) throws ConversionException { +175 return nf.format(obj.floatValue()); +176 } +177 } +178 +179 /** +180 * An object that converts a <code>Number</code> to a +181 * <code>BigDecimal</code>. +182 */ +183 public static class GenericNumberToBigDecimal<N extends Number> extends AbstractConverter<N, BigDecimal> { +184 public GenericNumberToBigDecimal(Class<N> sourceClass) { +185 super(sourceClass, BigDecimal.class); +186 } +187 +188 public BigDecimal convert(N obj) throws ConversionException { +189 return new BigDecimal(obj.doubleValue()); +190 } +191 } +192 +193 /** +194 * An object that converts a <code>Number</code> to a +195 * <code>BigInteger</code>. +196 */ +197 public static class GenericNumberToBigInteger<N extends Number> extends AbstractConverter<N, BigInteger> { +198 public GenericNumberToBigInteger(Class<N> sourceClass) { +199 super(sourceClass, BigInteger.class); +200 } +201 +202 public BigInteger convert(N obj) throws ConversionException { +203 return BigInteger.valueOf(obj.longValue()); +204 } +205 } +206 +207 /** +208 * An object that converts a <code>Number</code> to a +209 * <code>Byte</code>. +210 */ +211 public static class GenericNumberToByte<N extends Number> extends AbstractConverter<N, Byte> { +212 public GenericNumberToByte(Class<N> sourceClass) { +213 super(sourceClass, Byte.class); +214 } +215 +216 public Byte convert(N obj) throws ConversionException { +217 return Byte.valueOf(obj.byteValue()); +218 } +219 } +220 +221 /** +222 * An object that converts a <code>Number</code> to a +223 * <code>Double</code>. +224 */ +225 public static class GenericNumberToDouble<N extends Number> extends AbstractConverter<N, Double> { +226 public GenericNumberToDouble(Class<N> sourceClass) { +227 super(sourceClass, Double.class); +228 } +229 +230 public Double convert(N obj) throws ConversionException { +231 return obj.doubleValue(); +232 } +233 } +234 +235 /** +236 * An object that converts a <code>Number</code> to a +237 * <code>Float</code>. +238 */ +239 public static class GenericNumberToFloat<N extends Number> extends AbstractConverter<N, Float> { +240 public GenericNumberToFloat(Class<N> sourceClass) { +241 super(sourceClass, Float.class); +242 } +243 +244 public Float convert(N obj) throws ConversionException { +245 return obj.floatValue(); +246 } +247 } +248 +249 /** +250 * An object that converts a <code>Number</code> to an +251 * <code>Integer</code>. +252 */ +253 public static class GenericNumberToInteger<N extends Number> extends AbstractConverter<N, Integer> { +254 public GenericNumberToInteger(Class<N> sourceClass) { +255 super(sourceClass, Integer.class); +256 } +257 +258 public Integer convert(N obj) throws ConversionException { +259 return obj.intValue(); +260 } +261 } +262 +263 /** +264 * An object that converts a <code>Number</code> to a +265 * <code>Long</code>. +266 */ +267 public static class GenericNumberToLong<N extends Number> extends AbstractConverter<N, Long> { +268 public GenericNumberToLong(Class<N> sourceClass) { +269 super(sourceClass, Long.class); +270 } +271 +272 public Long convert(N obj) throws ConversionException { +273 return obj.longValue(); +274 } +275 } +276 +277 /** +278 * An object that converts a <code>Number</code> to a +279 * <code>Short</code>. +280 */ +281 public static class GenericNumberToShort<N extends Number> extends AbstractConverter<N, Short> { +282 public GenericNumberToShort(Class<N> sourceClass) { +283 super(sourceClass, Short.class); +284 } +285 +286 public Short convert(N obj) throws ConversionException { +287 return obj.shortValue(); +288 } +289 } +290 +291 /** +292 * An object that converts an <code>Integer</code> to a +293 * <code>String</code>. +294 */ +295 public static class IntegerToString extends AbstractNumberToStringConverter<Integer> { +296 public IntegerToString() { +297 super(Integer.class); +298 } +299 +300 protected String format(Integer obj, NumberFormat nf) throws ConversionException { +301 return nf.format(obj.intValue()); +302 } +303 } +304 +305 /** +306 * An object that converts a <code>Long</code> to a +307 * <code>BigDecimal</code>. +308 */ +309 public static class LongToBigDecimal extends AbstractConverter<Long, BigDecimal> { +310 public LongToBigDecimal() { +311 super(Long.class, BigDecimal.class); +312 } +313 +314 public BigDecimal convert(Long obj) throws ConversionException { +315 return BigDecimal.valueOf(obj.longValue()); +316 } +317 } +318 +319 /** +320 * An object that converts a <code>Long</code> to a +321 * <code>String</code>. +322 */ +323 public static class LongToString extends AbstractNumberToStringConverter<Long> { +324 public LongToString() { +325 super(Long.class); +326 } +327 +328 protected String format(Long obj, NumberFormat nf) throws ConversionException { +329 return nf.format(obj.longValue()); +330 } +331 } +332 +333 /** +334 * An object that converts a <code>Short</code> to a +335 * <code>String</code>. +336 */ +337 public static class ShortToString extends AbstractNumberToStringConverter<Short> { +338 public ShortToString() { +339 super(Short.class); +340 } +341 +342 protected String format(Short obj, NumberFormat nf) throws ConversionException { +343 return nf.format(obj.floatValue()); +344 } +345 } +346 +347 /** +348 * An object that converts a <code>String</code> to a +349 * <code>BigDecimal</code>. +350 */ +351 public static class StringToBigDecimal extends AbstractStringToNumberConverter<BigDecimal> { +352 public StringToBigDecimal() { +353 super(BigDecimal.class); +354 } +355 +356 protected BigDecimal convert(Number number) throws ConversionException { +357 return BigDecimal.valueOf(number.doubleValue()); +358 } +359 +360 public BigDecimal convert(String obj) throws ConversionException { +361 return BigDecimal.valueOf(Double.valueOf(obj)); +362 } +363 } +364 +365 /** +366 * An object that converts a <code>String</code> to a +367 * <code>BigInteger</code>. +368 */ +369 public static class StringToBigInteger extends AbstractStringToNumberConverter<BigInteger> { +370 public StringToBigInteger() { +371 super(BigInteger.class); +372 } +373 +374 protected BigInteger convert(Number number) throws ConversionException { +375 return BigInteger.valueOf(number.longValue()); +376 } +377 +378 public BigInteger convert(String obj) throws ConversionException { +379 return new BigInteger(obj); +380 } +381 } +382 +383 /** +384 * An object that converts a <code>String</code> to a +385 * <code>Byte</code>. +386 */ +387 public static class StringToByte extends AbstractConverter<String, Byte> { +388 public StringToByte() { +389 super(String.class, Byte.class); +390 } +391 +392 public Byte convert(String obj) throws ConversionException { +393 return Byte.valueOf(obj); +394 } +395 } +396 +397 /** +398 * An object that converts a <code>String</code> to a +399 * <code>Double</code>. +400 */ +401 public static class StringToDouble extends AbstractStringToNumberConverter<Double> { +402 public StringToDouble() { +403 super(Double.class); +404 } +405 +406 protected Double convert(Number number) throws ConversionException { +407 return number.doubleValue(); +408 } +409 +410 public Double convert(String obj) throws ConversionException { +411 return Double.valueOf(obj); +412 } +413 } +414 +415 /** +416 * An object that converts a <code>String</code> to a +417 * <code>Float</code>. +418 */ +419 public static class StringToFloat extends AbstractStringToNumberConverter<Float> { +420 public StringToFloat() { +421 super(Float.class); +422 } +423 +424 protected Float convert(Number number) throws ConversionException { +425 return number.floatValue(); +426 } +427 +428 public Float convert(String obj) throws ConversionException { +429 return Float.valueOf(obj); +430 } +431 } +432 +433 /** +434 * An object that converts a <code>String</code> to an +435 * <code>Integer</code>. +436 */ +437 public static class StringToInteger extends AbstractStringToNumberConverter<Integer> { +438 public StringToInteger() { +439 super(Integer.class); +440 } +441 +442 protected Integer convert(Number number) throws ConversionException { +443 return number.intValue(); +444 } +445 +446 public Integer convert(String obj) throws ConversionException { +447 return Integer.valueOf(obj); +448 } +449 } +450 +451 /** +452 * An object that converts a <code>String</code> to a +453 * <code>Long</code>. +454 */ +455 public static class StringToLong extends AbstractStringToNumberConverter<Long> { +456 public StringToLong() { +457 super(Long.class); +458 } +459 +460 protected Long convert(Number number) throws ConversionException { +461 return number.longValue(); +462 } +463 +464 public Long convert(String obj) throws ConversionException { +465 return Long.valueOf(obj); +466 } +467 } +468 +469 /** +470 * An object that converts a <code>String</code> to a +471 * <code>Short</code>. +472 */ +473 public static class StringToShort extends AbstractConverter<String, Short> { +474 public StringToShort() { +475 super(String.class, Short.class); +476 } +477 +478 public Short convert(String obj) throws ConversionException { +479 return Short.valueOf(obj); +480 } +481 } +482 }