Module litebridge.converter
Class AbstractNumberConverter<T extends Number>
java.lang.Object
org.litebridgedb.convert.converter.AbstractNumberConverter<T>
- Type Parameters:
T- the target numeric type
- All Implemented Interfaces:
Converter<T>,ConverterFunction<T>
- Direct Known Subclasses:
ByteConverter,DoubleConverter,FloatConverter,IntegerConverter,LongConverter,ShortConverter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@Nullable TConverts the given value to the target numeric type.protected abstract TconvertNumber(Number value) Converts aNumberinstance to the target type.protected abstract TconvertString(String value) Parses a string value into the target type.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.litebridgedb.convert.converter.Converter
primitiveType, type
-
Constructor Details
-
AbstractNumberConverter
public AbstractNumberConverter()
-
-
Method Details
-
convert
Converts the given value to the target numeric type.The conversion process follows these steps:
- If the value is
null, returnsnull. - If the value is already of the target type, returns it as-is.
- If the value is a
Number, callsconvertNumber(Number). - Otherwise, converts the value to a string and, if not blank, calls
convertString(String).
- Specified by:
convertin interfaceConverterFunction<T extends Number>- Parameters:
value- the value to convert, may benull- Returns:
- the converted numeric value, or
null
- If the value is
-
convertNumber
Converts aNumberinstance to the target type.- Parameters:
value- the numeric value to convert- Returns:
- the converted value
-
convertString
Parses a string value into the target type.- Parameters:
value- the string value to parse- Returns:
- the parsed value
-