Package com.cedarsoftware.util
Class Converter
- java.lang.Object
-
- com.cedarsoftware.util.Converter
-
public final class Converter extends Object
Handy conversion utilities. Convert from primitive to other primitives, plus support for Date, TimeStamp SQL Date, and the Atomic's.- Author:
- John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tconvert(Object fromInstance, Class<T> toType)Turn the passed in value to the class indicated.static AtomicBooleanconvertToAtomicBoolean(Object fromInstance)static AtomicIntegerconvertToAtomicInteger(Object fromInstance)static AtomicLongconvertToAtomicLong(Object fromInstance)static BigDecimalconvertToBigDecimal(Object fromInstance)static BigIntegerconvertToBigInteger(Object fromInstance)static BooleanconvertToBoolean(Object fromInstance)static ByteconvertToByte(Object fromInstance)static CalendarconvertToCalendar(Object fromInstance)static DateconvertToDate(Object fromInstance)static DoubleconvertToDouble(Object fromInstance)static FloatconvertToFloat(Object fromInstance)static IntegerconvertToInteger(Object fromInstance)static LongconvertToLong(Object fromInstance)static ShortconvertToShort(Object fromInstance)static DateconvertToSqlDate(Object fromInstance)static StringconvertToString(Object fromInstance)static TimestampconvertToTimestamp(Object fromInstance)
-
-
-
Method Detail
-
convert
public static <T> T convert(Object fromInstance, Class<T> toType)
Turn the passed in value to the class indicated. This will allow, for example, a String value to be passed in and have it coerced to a Long.Examples: Long x = convert("35", Long.class); Date d = convert("2015/01/01", Date.class) int y = convert(45.0, int.class) String date = convert(date, String.class) String date = convert(calendar, String.class) Short t = convert(true, short.class); // returns (short) 1 or (short) 0 Long date = convert(calendar, long.class); // get calendar's time into long- Parameters:
fromInstance- A value used to create the targetType, even though it may not (most likely will not) be the same data type as the targetTypetoType- Class which indicates the targeted (final) data type. Please note that in addition to the 8 Java primitives, the targeted class can also be Date.class, String.class, BigInteger.class, BigDecimal.class, and the Atomic classes. The primitive class can be either primitive class or primitive wrapper class, however, the returned value will always [obviously] be a primitive wrapper.- Returns:
- An instanceof targetType class, based upon the value passed in.
-
convertToBigDecimal
public static BigDecimal convertToBigDecimal(Object fromInstance)
-
convertToBigInteger
public static BigInteger convertToBigInteger(Object fromInstance)
-
convertToAtomicInteger
public static AtomicInteger convertToAtomicInteger(Object fromInstance)
-
convertToAtomicLong
public static AtomicLong convertToAtomicLong(Object fromInstance)
-
convertToAtomicBoolean
public static AtomicBoolean convertToAtomicBoolean(Object fromInstance)
-
-