Package jmri.configurexml
Class AbstractXmlAdapter.EnumIoMapped<T extends java.lang.Enum<T>>
- java.lang.Object
-
- jmri.configurexml.AbstractXmlAdapter.EnumIO<T>
-
- jmri.configurexml.AbstractXmlAdapter.EnumIoMapped<T>
-
- Type Parameters:
T
- generic enum class.
- Enclosing class:
- AbstractXmlAdapter
public static class AbstractXmlAdapter.EnumIoMapped<T extends java.lang.Enum<T>> extends AbstractXmlAdapter.EnumIO<T>
Support for Enum I/O to XML using explicit mapping.This converts to and from ordinal numbers so the order of definitions in the enum has to match up with the (former) constant values.
-
-
Constructor Summary
Constructors Constructor Description EnumIoMapped(java.lang.Class<T> clazz, java.util.Map<java.lang.String,T> mapToEnum)
EnumIoMapped(java.lang.Class<T> clazz, java.util.Map<java.lang.String,T> mapToEnum, java.util.Map<T,java.lang.String> mapFromEnum)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
inputFromString(java.lang.String s)
Convert a String value from an XML file to an enum value.java.lang.String
outputFromEnum(T e)
Convert an enum value to a String for storage in an XML file.-
Methods inherited from class jmri.configurexml.AbstractXmlAdapter.EnumIO
inputFromAttribute
-
-
-
-
Constructor Detail
-
EnumIoMapped
public EnumIoMapped(@Nonnull java.lang.Class<T> clazz, @Nonnull java.util.Map<java.lang.String,T> mapToEnum, @Nonnull java.util.Map<T,java.lang.String> mapFromEnum)
- Parameters:
clazz
- enum class.mapToEnum
- Substitutes an explicit mapping for mapping from Strings to enums; this could allow e.g. accepting both name and number versions. Multiple entries are OK: this can map both "1" and "Foo" to Foo for past-schema support.mapFromEnum
- Substitutes an explicit mapping enum entries to Strings; this determines what will be written out.
-
EnumIoMapped
public EnumIoMapped(@Nonnull java.lang.Class<T> clazz, @Nonnull java.util.Map<java.lang.String,T> mapToEnum)
- Parameters:
clazz
- enum class.mapToEnum
- Substitutes an explicit mapping for mapping from Strings to enums; this could allow e.g. accepting both name and number versions. Multiple entries are OK: this can map both "1" and "Foo" to Foo for past-schema support. The mapping from enums to Strings uses the enum names.
-
-
Method Detail
-
outputFromEnum
@Nonnull public java.lang.String outputFromEnum(@Nonnull T e)
Convert an enum value to a String for storage in an XML file.- Specified by:
outputFromEnum
in classAbstractXmlAdapter.EnumIO<T extends java.lang.Enum<T>>
- Parameters:
e
- enum value.- Returns:
- storage string.
-
inputFromString
@Nonnull public T inputFromString(@CheckForNull java.lang.String s)
Convert a String value from an XML file to an enum value.- Specified by:
inputFromString
in classAbstractXmlAdapter.EnumIO<T extends java.lang.Enum<T>>
- Parameters:
s
- storage string- Returns:
- enum value.
-
-