Top Description Fields Constructors Methods
com.thoughtworks.xstream.converters.enums

public Class EnumToStringConverter<T extends java.lang.Enum<T>>

extends AbstractSingleValueConverter
Class Inheritance
Imports
java.util.EnumMap, .EnumSet, .HashMap, .Map, com.thoughtworks.xstream.InitializationException, com.thoughtworks.xstream.converters.ConversionException, com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter

A single value converter for a special enum type using its string representation.
Author
Jörg Schaible
Since
1.4.5

Field Summary

Modifier and TypeField and Description
private final Class<T>
private final Map<String, T>
private final EnumMap<T, String>

Constructor Summary

AccessConstructor and Description
public
public
EnumToStringConverter(Class<T> type, Map<String, T> strings)

private
EnumToStringConverter(Class<T> type, Map<String, T> strings, EnumMap<T, String> values)

Method Summary

Modifier and TypeMethod and Description
private static <T extends Enum<T>> EnumMap<T, String>
buildValueMap(Class<T> type, Map<String, T> strings)

public boolean
canConvert(Class<T>
the Class representing the object type to be converted
type
)

Implements abstract com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.canConvert.

Implements com.thoughtworks.xstream.converters.ConverterMatcher.canConvert.

Determines whether the converter can marshall a particular type.
private static <T> void
checkType(Class<T> type)

private static <T extends Enum<T>> Map<String, T>
public Object
fromString(String
the String with the single value of the Object
str
)

Implements abstract com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.fromString.

Implements com.thoughtworks.xstream.converters.SingleValueConverter.fromString.

Unmarshals an Object from its single value representation.
public String
toString(Object
the Object to be converted
obj
)

Overrides com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.toString.

Implements com.thoughtworks.xstream.converters.SingleValueConverter.toString.

Marshals an Object into a single value representation.

Field Detail

enumTypeback to summary
private final Class<T> enumType
stringsback to summary
private final Map<String, T> strings
valuesback to summary
private final EnumMap<T, String> values

Constructor Detail

EnumToStringConverterback to summary
public EnumToStringConverter(Class<T> type)
EnumToStringConverterback to summary
public EnumToStringConverter(Class<T> type, Map<String, T> strings)
EnumToStringConverterback to summary
private EnumToStringConverter(Class<T> type, Map<String, T> strings, EnumMap<T, String> values)

Method Detail

buildValueMapback to summary
private static <T extends Enum<T>> EnumMap<T, String> buildValueMap(Class<T> type, Map<String, T> strings)
canConvertback to summary
public boolean canConvert(Class<T> type)

Implements abstract com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.canConvert.

Implements com.thoughtworks.xstream.converters.ConverterMatcher.canConvert.

Doc from com.thoughtworks.xstream.converters.ConverterMatcher.canConvert.

Determines whether the converter can marshall a particular type.

Parameters
type:Class<T>

the Class representing the object type to be converted

Annotations
@Override
checkTypeback to summary
private static <T> void checkType(Class<T> type)
extractStringMapback to summary
private static <T extends Enum<T>> Map<String, T> extractStringMap(Class<T> type)
fromStringback to summary
public Object fromString(String str)

Implements abstract com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.fromString.

Implements com.thoughtworks.xstream.converters.SingleValueConverter.fromString.

Doc from com.thoughtworks.xstream.converters.SingleValueConverter.fromString.

Unmarshals an Object from its single value representation.

Parameters
str:String

the String with the single value of the Object

Returns:Object

the Object

Annotations
@Override
toStringback to summary
public String toString(Object obj)

Overrides com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.toString.

Implements com.thoughtworks.xstream.converters.SingleValueConverter.toString.

Doc from com.thoughtworks.xstream.converters.SingleValueConverter.toString.

Marshals an Object into a single value representation.

Parameters
obj:Object

the Object to be converted

Returns:String

a String with the single value of the Object or null

Annotations
@Override