Class DefaultEnumStringConverter<T extends Enum<T>>

java.lang.Object
org.tquadrat.foundation.lang.internal.DefaultEnumStringConverter<T>
Type Parameters:
T - The concrete data type that is handled by this string converter implementation.
All Implemented Interfaces:
Serializable, StringConverter<T>

@ClassVersion(sourceVersion="$Id: DefaultEnumStringConverter.java 1119 2024-03-16 09:03:57Z tquadrat $") @API(status=INTERNAL, since="0.1.0") public class DefaultEnumStringConverter<T extends Enum<T>> extends Object implements StringConverter<T>
The default implementation of StringConverter for types that are derived from Enum.

The implementation of fromString(CharSequence) provided here uses Class.getEnumConstants() to find the enum value:
  …
  T result = stream( m_EnumType.getEnumConstants() )
      .filter( constant -> value.equals( constant.name() ) )
      .findFirst()
      .orElseThrow( () -> new IllegalArgumentException( … );
  …

The implementation of toString(Enum) in this class will return the value of Enum.name().
Author:
Thomas Thrien (thomas.thrien@tquadrat.org)
Version:
$Id: DefaultEnumStringConverter.java 1119 2024-03-16 09:03:57Z tquadrat $
Since:
0.1.0
See Also:
UML Diagram
UML Diagram for "org.tquadrat.foundation.lang.internal.DefaultEnumStringConverter"

UML Diagram for "org.tquadrat.foundation.lang.internal.DefaultEnumStringConverter"

UML Diagram for "org.tquadrat.foundation.lang.internal.DefaultEnumStringConverter"
  • Field Details

  • Constructor Details

    • DefaultEnumStringConverter

      public DefaultEnumStringConverter(Class<T> enumType)
      Creates a new EnumValueHandler instance.
      Parameters:
      enumType - The data type for the property.
  • Method Details