Module org.tquadrat.foundation.util
Class NumberStringConverter<T extends Number>
java.lang.Object
org.tquadrat.foundation.util.stringconverter.NumberStringConverter<T>
- Type Parameters:
T- The type that is handled by this class.
- All Implemented Interfaces:
Serializable,StringConverter<T>
- Direct Known Subclasses:
BigDecimalStringConverter,BigIntegerStringConverter,ByteStringConverter,DoubleStringConverter,FloatStringConverter,IntegerStringConverter,LongStringConverter,ShortStringConverter
@ClassVersion(sourceVersion="$Id: NumberStringConverter.java 1080 2024-01-03 11:05:21Z tquadrat $")
@API(status=STABLE,
since="0.0.6")
public abstract sealed class NumberStringConverter<T extends Number>
extends Object
implements StringConverter<T>
permits BigDecimalStringConverter, BigIntegerStringConverter, ByteStringConverter, DoubleStringConverter, FloatStringConverter, IntegerStringConverter, LongStringConverter, ShortStringConverter
The base class for implementations of
StringConverter
for types that extend
Number.- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: NumberStringConverter.java 1080 2024-01-03 11:05:21Z tquadrat $
- Since:
- 0.0.6
- See Also:
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.util.stringconverter.NumberStringConverter"
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Collection<Class<?>> The subject classes for this converter.static final StringThe error message for a String argument tofromString(CharSequence)that cannot be parsed to a proper number value: "\'%1$s\' cannot be parsed as a valid number".Fields inherited from interface org.tquadrat.foundation.lang.StringConverter
METHOD_NAME_GetSubjectClass, METHOD_NAME_Provider -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNumberStringConverter(Class<?>... subjectClasses) Creates a new instance ofNumberStringConverter. -
Method Summary
Modifier and TypeMethodDescriptionfinal TfromString(CharSequence source) final Collection<Class<?>> Provides the subject class for this converter.protected abstract TparseNumber(String value) Parses the given String to a number.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.tquadrat.foundation.lang.StringConverter
toString
-
Field Details
-
MSG_InvalidNumberFormat
The error message for a String argument tofromString(CharSequence)that cannot be parsed to a proper number value: "\'%1$s\' cannot be parsed as a valid number".- See Also:
-
m_SubjectClasses
The subject classes for this converter.
-
-
Constructor Details
-
NumberStringConverter
Creates a new instance ofNumberStringConverter.- Parameters:
subjectClasses- The subject classes.
-
-
Method Details
-
parseNumber
Parses the given String to a number. The String is notnull, not empty, and it will not contain blanks only. Leading or trailing blanks have been cut off.- Parameters:
value- The String to parse.- Returns:
- The number.
- Throws:
NumberFormatException- The given value cannot be parsed to a number.
-
fromString
- Specified by:
fromStringin interfaceStringConverter<T extends Number>- Throws:
IllegalArgumentException
-
getSubjectClass
Provides the subject class for this converter.- Returns:
- The subject class.
-
