diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java index afe978cce..fea1d482e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/AbstractFlag.java @@ -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(); } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java new file mode 100644 index 000000000..0acaefeed --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java @@ -0,0 +1,68 @@ +package com.intellectualcrafters.plot.flag; + +/** + * Created 2014-11-17 for PlotSquared + * + * @author Citymonstret + */ +public abstract class FlagValue { + + private Class clazz; + + public FlagValue() { + this.clazz = (Class) this.getClass(); + } + + public FlagValue(Class 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 { + + @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 { + + @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; + } + } +}