gui and text drawing, gui misc
This commit is contained in:
parent
c906760bd4
commit
4ec8affe85
37 changed files with 799 additions and 646 deletions
|
@ -4,9 +4,10 @@ import java.util.Map;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
public class EnumParser extends DefaultingParser {
|
||||
private final Map<String, Object> lookup = Maps.newHashMap();
|
||||
private final Object[] selections;
|
||||
public class EnumParser<T> extends DefaultingParser {
|
||||
private final Class<T> clazz;
|
||||
private final Map<String, T> lookup = Maps.newHashMap();
|
||||
private final T[] selections;
|
||||
|
||||
private static <T> String joinArgs(T[] iter) {
|
||||
StringBuilder sb = new StringBuilder("'");
|
||||
|
@ -18,16 +19,17 @@ public class EnumParser extends DefaultingParser {
|
|||
return sb.append("'").toString();
|
||||
}
|
||||
|
||||
public EnumParser(String name, Object def, Object ... selections) {
|
||||
public EnumParser(String name, Class<T> clazz, T def, T ... selections) {
|
||||
super(name, def, selections);
|
||||
this.clazz = clazz;
|
||||
this.selections = selections;
|
||||
for(Object o : selections) {
|
||||
for(T o : selections) {
|
||||
this.lookup.put(o.toString().toLowerCase(), o);
|
||||
}
|
||||
}
|
||||
|
||||
public Object parse(ScriptEnvironment env, String input) {
|
||||
Object value = this.lookup.get(input.toLowerCase());
|
||||
public T parse(ScriptEnvironment env, String input) {
|
||||
T value = this.lookup.get(input.toLowerCase());
|
||||
if(value != null)
|
||||
return value;
|
||||
int id = -1;
|
||||
|
@ -41,4 +43,8 @@ public class EnumParser extends DefaultingParser {
|
|||
joinArgs(this.selections));
|
||||
return this.selections[id];
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return this.clazz;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue