Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnumToIntegerConverter [moved] #28

Open
jonnybbb opened this issue Nov 18, 2012 · 0 comments
Open

EnumToIntegerConverter [moved] #28

jonnybbb opened this issue Nov 18, 2012 · 0 comments

Comments

@jonnybbb
Copy link
Contributor

This is Issue 28 moved from a Google Code project.
Added by 2010-07-15T17:37:39.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Defect, Priority-Medium

Original description

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();
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant