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

public abstract class AbstractNumberConverter<T extends Number> extends Object implements Converter<T>
An abstract base class for Converter implementations that handle numeric types.

This class provides common logic for converting values to a specific Number subclass, including handling null values, identity conversions, numeric-to-numeric conversions, and string parsing.

  • Constructor Details

    • AbstractNumberConverter

      public AbstractNumberConverter()
  • Method Details

    • convert

      public @Nullable T convert(@Nullable Object value)
      Converts the given value to the target numeric type.

      The conversion process follows these steps:

      1. If the value is null, returns null.
      2. If the value is already of the target type, returns it as-is.
      3. If the value is a Number, calls convertNumber(Number).
      4. Otherwise, converts the value to a string and, if not blank, calls convertString(String).
      Specified by:
      convert in interface ConverterFunction<T extends Number>
      Parameters:
      value - the value to convert, may be null
      Returns:
      the converted numeric value, or null
    • convertNumber

      protected abstract T convertNumber(Number value)
      Converts a Number instance to the target type.
      Parameters:
      value - the numeric value to convert
      Returns:
      the converted value
    • convertString

      protected abstract T convertString(String value)
      Parses a string value into the target type.
      Parameters:
      value - the string value to parse
      Returns:
      the parsed value