Don't know whether it is generally useful but if you think so, feel free to
include:
import com.pietschy.gwt.pectin.client.value.Converter;
/**
* Converts the value of an {@link Enum} type to its {@link Enum#ordinal()} integer.
*
* @param <E>
* the enum type
*/
public class EnumToIntegerConverter<E extends Enum<E>> implements Converter<E,
Integer>
{
private final Class<E> clazz;
public EnumToIntegerConverter(Class<E> clazz)
{
this.clazz = clazz;
}
@Override
public E fromSource(Integer value)
{
return clazz.getEnumConstants()[value];
}
@Override
public Integer toSource(E value)
{
return value.ordinal();
}
}
Original issue reported on code.google.com by kaspar.f...@gtempaccount.com on 15 Jul 2010 at 5:37
Original issue reported on code.google.com by
kaspar.f...@gtempaccount.com
on 15 Jul 2010 at 5:37