I'm trying to use a custom defined Enum as a parameter type in my controllers and routes. I would like to map a portion of the request URL as an Enum.
public enum Sorting implements QueryStringBindable<Sorting2>, PathBindable<Sorting2>
{
@EnumValue("I")
IMPORTANT_FIRST,
@EnumValue("N")
NEWEST_FIRST,
@EnumValue("O")
OLDEST_FIRST;
private Sorting value;
@Override
public Option<Sorting> bind(String key, Map<String, String[]> data)
{
String[] vs = data.get(key);
if (vs != null && vs.length > 0) {
String v = vs[0];
value = Enum.valueOf(Sorting.class, v);
return Option.Some(value);
}
return Option.None();
}
@Override
public String unbind(String key)
{
return key + "=" + value;
}
@Override
public String javascriptUnbind()
{
return value.toString();
}
@Override
public Sorting bind(String key, String txt)
{
this.value = Enum.valueOf(Sorting.class, txt);
return this;
}
}
Play is compiling the code successfully and I don't get any exceptions in the console at runtime.
Thank you for your help.