Module org.tquadrat.foundation.base
Package org.tquadrat.foundation.lang
Class GenericStringConverter<T>
java.lang.Object
org.tquadrat.foundation.lang.GenericStringConverter<T>
- Type Parameters:
T- The Object type for the conversion.
- All Implemented Interfaces:
Serializable,StringConverter<T>
@ClassVersion(sourceVersion="$Id: GenericStringConverter.java 1078 2023-10-19 14:39:47Z tquadrat $")
@API(status=STABLE,
since="0.0.6")
public class GenericStringConverter<T>
extends Object
implements StringConverter<T>
This implementation of
StringConverter
allows to create an instance of StringConverter for an arbitrary
type on the fly.- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: GenericStringConverter.java 1078 2023-10-19 14:39:47Z tquadrat $
- Since:
- 0.0.6
- See Also:
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.lang.GenericStringConverter"
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Function<CharSequence, T> The parser.The stringer.Fields inherited from interface org.tquadrat.foundation.lang.StringConverter
METHOD_NAME_GetSubjectClass, METHOD_NAME_Provider -
Constructor Summary
ConstructorsConstructorDescriptionGenericStringConverter(Function<? extends CharSequence, T> parser) Creates a newGenericStringConverterinstance that usesStringer.DEFAULT_STRINGERto convert an object of typeTto a String.GenericStringConverter(Function<? extends CharSequence, T> parser, Stringer<T> stringer) Creates a newGenericStringConverterinstance. -
Method Summary
Modifier and TypeMethodDescriptionfinal TfromString(CharSequence source) Converts the given String to an object instance.final StringConverts the given object instance to a String.
-
Field Details
-
m_Parser
The parser. -
m_Stringer
The stringer.
-
-
Constructor Details
-
GenericStringConverter
Creates a newGenericStringConverterinstance.- Parameters:
parser- The function that translates a String to an object of typeT.stringer- The function that converts an object of typeTto a String.
-
GenericStringConverter
Creates a newGenericStringConverterinstance that usesStringer.DEFAULT_STRINGERto convert an object of typeTto a String.- Parameters:
parser- The function that translates a String to an object of typeT.
-
-
Method Details
-
fromString
Converts the given String to an object instance.- Specified by:
fromStringin interfaceStringConverter<T>- Parameters:
source- The String representation for the object instance; can benull.- Returns:
- The resulting object instance; will be
nullifsourcewas alreadynull. - Throws:
IllegalArgumentException- The format of the given String is invalid and cannot be parsed into the object instance.
-
toString
Converts the given object instance to a String.- Specified by:
toStringin interfaceStringConverter<T>- Parameters:
source- The object to convert; can benull.- Returns:
- The resulting String; will be
nullifsourcewas alreadynull.
-
