Class StringConverterService

java.lang.Object
org.tquadrat.foundation.lang.internal.StringConverterService

@ClassVersion(sourceVersion="$Id: StringConverterService.java 1060 2023-09-24 19:21:40Z tquadrat $") @API(status=INTERNAL, since="0.1.0") @UtilityClass public final class StringConverterService extends Object
The implementation for the StringConverter service methods.
Author:
Thomas Thrien (thomas.thrien@tquadrat.org)
Version:
$Id: StringConverterService.java 1060 2023-09-24 19:21:40Z tquadrat $
Since:
0.1.0
UML Diagram
UML Diagram for "org.tquadrat.foundation.lang.internal.StringConverterService"

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

UML Diagram for "org.tquadrat.foundation.lang.internal.StringConverterService"
  • Constructor Details

  • Method Details

    • listInstances

      @API(status=INTERNAL, since="0.1.0") public static final Collection<Class<?>> listInstances()
      Returns the classes for that an instance of StringConverter is registered,
      Returns:
      The classes with a string converter.
    • loadConverters

      @API(status=INTERNAL, since="0.1.0") public static final Map<Class<?>,StringConverter<?>> loadConverters()
      Loads the known instances of StringConverter.
      Returns:
      The registry with the converters.
    • retrieveConverterForClass

      @API(status=INTERNAL, since="0.1.0") public static final <C> Optional<StringConverter<C>> retrieveConverterForClass(Class<C> type)
      Returns an instance of StringConverter for the given Class. If there is no converter for the given type, or the type is null, the return value is Optional.empty().
      Type Parameters:
      C - The class a converter is needed for.
      Parameters:
      type - The instance of the class a converter is needed for.
      Returns:
      An instance of Optional that holds the instance of StringConverter.
    • retrieveConverterForEnum

      @API(status=INTERNAL, since="0.1.0") public static final <E extends Enum<E>> StringConverter<E> retrieveConverterForEnum(Class<E> type)
      Returns an instance of StringConverter for the given Enum type. If there is no converter for the given type in the registry, a new instance of StringConverter will be created, on base of DefaultEnumStringConverter.
      Type Parameters:
      E - The class a converter is needed for.
      Parameters:
      type - The instance of the class a converter is needed for.
      Returns:
      The requested instance of StringConverter.
    • retrieveSubjectClasses

      private static final Collection<Class<?>> retrieveSubjectClasses(StringConverter<?> converter)

      Determines the key class for the given instance of StringConverter.

      The subject class is the target type for a call to fromString(), and usually this is also the type of the argument for toString(T); but under some circumstances, it cannot be guessed correctly by reflection. For that case, some implementation of StringConverter provides an optional method public Class<?> getSubjectClass() that returns the respective class.

      Parameters:
      converter - The converter instance.
      Returns:
      The subject class.