Skip to content

Commit

Permalink
Add PrimitiveType.Percent and allow Element to handle it. This Primit…
Browse files Browse the repository at this point in the history
…iveType checks against a non-negative 'double'.
  • Loading branch information
aufdemrand committed Jul 9, 2013
1 parent 6a241e0 commit 62ed182
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -56,15 +56,15 @@ public Element(String prefix, String string) {
}

public double asDouble() {
return Double.valueOf(element);
return Double.valueOf(element.replace("%", ""));
}

public float asFloat() {
return Float.valueOf(element);
return Float.valueOf(element.replace("%", ""));
}

public int asInt() {
return Integer.valueOf(element);
return Integer.valueOf(element.replace("%", ""));
}

public boolean asBoolean() {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/aH.java
Expand Up @@ -20,14 +20,17 @@
*/
public class aH {

public enum PrimitiveType { Float, Double, Integer, Boolean, String, Word }
public enum PrimitiveType { Float, Double, Integer, Boolean, String, Word, Percentage }

final static Pattern floatPrimitive =
Pattern.compile("^[-+]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?$");

final static Pattern doublePrimitive =
Pattern.compile("(-)?(?:(?:\\d+)|)(?:(?:\\.\\d+)|)");

final static Pattern percentagePrimitive =
Pattern.compile("(?:(?:\\d+)|)(?:(?:\\.\\d+)|)(%|)");

final static Pattern integerPrimitive =
Pattern.compile("(-)?\\d+");

Expand Down Expand Up @@ -116,6 +119,9 @@ public boolean matchesPrimitive(PrimitiveType argumentType) {
case Boolean:
return booleanPrimitive.matcher(value).matches();

case Percentage:
return percentagePrimitive.matcher(value).matches();

case String:
return true;
}
Expand Down

0 comments on commit 62ed182

Please sign in to comment.