|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.balusc.util.ObjectConverter
public final class ObjectConverter
Generic object converter.
Object o1 = Boolean.TRUE; Integer i = ObjectConverter.convert(o1, Integer.class); System.out.println(i); // 1 Object o2 = "false"; Boolean b = ObjectConverter.convert(o2, Boolean.class); System.out.println(b); // false Object o3 = new Integer(123); String s = ObjectConverter.convert(o3, String.class); System.out.println(s); // 123Not all possible conversions are implemented. You can extend the ObjectConverter easily by just adding a new method to it, with the appropriate logic. For example:
public static ToObject fromObjectToObject(FromObject fromObject) {
// Implement.
}
The method name doesn't matter. It's all about the parameter type and the
return type.
| Method Summary | ||
|---|---|---|
static Double |
bigDecimalToDouble(BigDecimal value)
Converts BigDecimal to Double. |
|
static Integer |
booleanToInteger(Boolean value)
Converts Boolean to Integer. |
|
static String |
booleanToString(Boolean value)
Converts Boolean to String. |
|
static
|
convert(Object from,
Class<T> to)
Convert the given object value to the given class. |
|
static BigDecimal |
doubleToBigDecimal(Double value)
Converts Double to BigDecimal. |
|
static Float |
doubleToFloat(Double value)
Converts Double to Float. |
|
static double |
doubleToPrimitive(Double value)
Converts Long to primitive. |
|
static double |
floatToPrimitive(Float value)
Converts Float to primitive. |
|
static Boolean |
integerToBoolean(Integer value)
Converts Integer to Boolean. |
|
static int |
integerToPrimitive(Integer value)
Converts Integer to primitive. |
|
static String |
integerToString(Integer value)
Converts Integer to String. |
|
static Integer |
longToInteger(Long value)
Converts Long to Integer. |
|
static long |
longToPrimitive(Long value)
Converts Long to primitive. |
|
static String |
longToString(Date value)
Converts Date to String. |
|
static String |
longToString(Double value)
Converts Double to String. |
|
static String |
longToString(Long value)
Converts Long to String. |
|
static Boolean |
stringToBoolean(String value)
Converts String to Boolean. |
|
static Double |
stringToDouble(String value)
Converts String to Float. |
|
static Float |
stringToFloat(String value)
Converts String to Float. |
|
static Integer |
stringToInteger(String value)
Converts String to Integer. |
|
static Long |
stringToLong(String value)
Converts String to Long. |
|
static long |
stringToLongPrimitive(String value)
Converts String to long. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <T> T convert(Object from,
Class<T> to)
from - The object value to be converted.to - The type class which the given object should be converted to.
NullPointerException - If 'to' is null.
UnsupportedOperationException - If no suitable converter can be found.
RuntimeException - If conversion failed somehow. This can be caused by at least an
ExceptionInInitializerError, IllegalAccessException or
InvocationTargetException.public static Boolean integerToBoolean(Integer value)
value - The Integer to be converted.
public static Integer booleanToInteger(Boolean value)
value - The Boolean to be converted.
public static BigDecimal doubleToBigDecimal(Double value)
value - The Double to be converted.
public static Double bigDecimalToDouble(BigDecimal value)
value - The BigDecimal to be converted.
public static String integerToString(Integer value)
value - The Integer to be converted.
public static Integer stringToInteger(String value)
value - The String to be converted.
public static Long stringToLong(String value)
value - The String to be converted.
public static long stringToLongPrimitive(String value)
value - The String to be converted.
public static String booleanToString(Boolean value)
value - The Boolean to be converted.
public static Boolean stringToBoolean(String value)
value - The String to be converted.
public static Integer longToInteger(Long value)
value - The Long value to be convered.
public static Float doubleToFloat(Double value)
value - The Double value to be convered.
public static Float stringToFloat(String value)
value - The Float value to be convered.
public static Double stringToDouble(String value)
value - The Float value to be convered.
public static long longToPrimitive(Long value)
value - The Long value to be convered.
public static String longToString(Long value)
value - The Long value to be converted.
public static String longToString(Double value)
value - The Double value to be converted.
public static String longToString(Date value)
value - The value to be converted.
public static int integerToPrimitive(Integer value)
value - The Integer value to be convered.
public static double doubleToPrimitive(Double value)
value - The Long value to be convered.
public static double floatToPrimitive(Float value)
value - The Float value to be convered.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||