mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
Begun making the flag values... generic, and really abstract.
This commit is contained in:
parent
6997f8675b
commit
69b8f6080b
@ -32,6 +32,11 @@ import org.apache.commons.lang.StringUtils;
|
||||
public class AbstractFlag {
|
||||
|
||||
private final String key;
|
||||
private final FlagValue<?> value;
|
||||
|
||||
public AbstractFlag(final String key) {
|
||||
this(key, new FlagValue.StringValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* AbstractFlag is a parameter used in creating a new Flag
|
||||
@ -39,7 +44,7 @@ public class AbstractFlag {
|
||||
* @param key The key must be alphabetical characters and <= 16 characters
|
||||
* in length
|
||||
*/
|
||||
public AbstractFlag(final String key) {
|
||||
public AbstractFlag(final String key, final FlagValue<?> value) {
|
||||
if (!StringUtils.isAlpha(key.replaceAll("_", "").replaceAll("-", ""))) {
|
||||
throw new IllegalArgumentException("Flag must be alphabetic characters");
|
||||
}
|
||||
@ -47,14 +52,15 @@ public class AbstractFlag {
|
||||
throw new IllegalArgumentException("Key must be <= 16 characters");
|
||||
}
|
||||
this.key = key.toLowerCase();
|
||||
this.value = new FlagValue.StringValue();
|
||||
}
|
||||
|
||||
public String parseValue(final String value) {
|
||||
return value;
|
||||
return this.value.parse(value).toString();
|
||||
}
|
||||
|
||||
public String getValueDesc() {
|
||||
return "Flag value must be alphanumeric";
|
||||
return this.value.getDescription();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,68 @@
|
||||
package com.intellectualcrafters.plot.flag;
|
||||
|
||||
/**
|
||||
* Created 2014-11-17 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public abstract class FlagValue<T> {
|
||||
|
||||
private Class<T> clazz;
|
||||
|
||||
public FlagValue() {
|
||||
this.clazz = (Class<T>) this.getClass();
|
||||
}
|
||||
|
||||
public FlagValue(Class<T> clazz) {
|
||||
if (clazz == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public boolean validValue(Object value) {
|
||||
return value != null && value.getClass() == clazz;
|
||||
}
|
||||
|
||||
public abstract T getValue(String t);
|
||||
|
||||
public abstract String parse(String t);
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
public static class BooleanValue extends FlagValue<Boolean> {
|
||||
|
||||
@Override
|
||||
public Boolean getValue(String t) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(String t) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringValue extends FlagValue<String> {
|
||||
|
||||
@Override
|
||||
public String parse(String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Flag value must be alphanumeric";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String t) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user