From 69b8f6080b9da14c3fcdd0fbc22ea99545a52e07 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Mon, 17 Nov 2014 19:18:05 +0100 Subject: [PATCH] Begun making the flag values... generic, and really abstract. --- .../plot/flag/AbstractFlag.java | 12 +++- .../plot/flag/FlagValue.java | 68 +++++++++++++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java 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; + } + } +}