Repository: karaf-decanter Updated Branches: refs/heads/master 7f5cbf44e -> b34cc6c21
[KARAF-4749] Add BigDecimal support in SLA checker Project: http://git-wip-us.apache.org/repos/asf/karaf-decanter/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf-decanter/commit/b34cc6c2 Tree: http://git-wip-us.apache.org/repos/asf/karaf-decanter/tree/b34cc6c2 Diff: http://git-wip-us.apache.org/repos/asf/karaf-decanter/diff/b34cc6c2 Branch: refs/heads/master Commit: b34cc6c214e203b600f255d549a7805aecebdcd2 Parents: 7f5cbf4 Author: Jean-Baptiste Onofré <[email protected]> Authored: Wed Nov 2 06:53:53 2016 +0100 Committer: Jean-Baptiste Onofré <[email protected]> Committed: Wed Nov 2 06:53:53 2016 +0100 ---------------------------------------------------------------------- .../karaf/decanter/sla/checker/Checker.java | 56 +++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/b34cc6c2/sla/checker/src/main/java/org/apache/karaf/decanter/sla/checker/Checker.java ---------------------------------------------------------------------- diff --git a/sla/checker/src/main/java/org/apache/karaf/decanter/sla/checker/Checker.java b/sla/checker/src/main/java/org/apache/karaf/decanter/sla/checker/Checker.java index 085a8d0..d254846 100644 --- a/sla/checker/src/main/java/org/apache/karaf/decanter/sla/checker/Checker.java +++ b/sla/checker/src/main/java/org/apache/karaf/decanter/sla/checker/Checker.java @@ -27,6 +27,7 @@ import org.osgi.service.event.EventHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.math.BigDecimal; import java.util.Dictionary; import java.util.HashMap; import java.util.Map; @@ -135,6 +136,13 @@ public class Checker implements EventHandler { } if (patterns[0].contains(".")) { Float m = Float.parseFloat(patterns[0]); + if (value instanceof BigDecimal) { + BigDecimal v = new BigDecimal(value.toString()); + BigDecimal mBD = new BigDecimal(m); + int compare = v.compareTo(mBD); + if (minIncluded && compare == -1) return false; + else if (compare <= 0) return false; + } if (value instanceof Double) { double v = value.doubleValue(); if (minIncluded && m > v) return false; @@ -162,6 +170,13 @@ public class Checker implements EventHandler { } } else { int m = Integer.parseInt(patterns[0]); + if (value instanceof BigDecimal) { + BigDecimal v = new BigDecimal(value.toString()); + BigDecimal mBD = new BigDecimal(m); + int compare = v.compareTo(mBD); + if (minIncluded && compare == -1) return false; + else if (compare <= 0) return false; + } if (value instanceof Double) { double v = value.doubleValue(); if (minIncluded && m > v) return false; @@ -190,6 +205,13 @@ public class Checker implements EventHandler { } if (patterns[1].contains(".")) { Float m = Float.parseFloat(patterns[1]); + if (value instanceof BigDecimal) { + BigDecimal v = new BigDecimal(value.toString()); + BigDecimal mBD = new BigDecimal(m); + int compare = v.compareTo(mBD); + if (maxIncluded && compare <= 0) return false; + else if (compare < 0) return false; + } if (value instanceof Double) { double v = value.doubleValue(); if (maxIncluded && m <= v) return false; @@ -217,6 +239,13 @@ public class Checker implements EventHandler { } } else { int m = Integer.parseInt(patterns[1]); + if (value instanceof BigDecimal) { + BigDecimal v = new BigDecimal(value.toString()); + BigDecimal mBD = new BigDecimal(m); + int compare = v.compareTo(mBD); + if (maxIncluded && compare <= 0) return false; + else if (compare == -1) return false; + } if (value instanceof Double) { double v = value.doubleValue(); if (maxIncluded && m <= v) return false; @@ -250,6 +279,12 @@ public class Checker implements EventHandler { for (String p : patterns) { if (p.contains(".")) { float f = Float.parseFloat(p); + if (value instanceof BigDecimal) { + BigDecimal v = new BigDecimal(value.toString()); + BigDecimal mBD = new BigDecimal(f); + int compare = v.compareTo(mBD); + if (compare != 0) return false; + } if (value instanceof Double) { double v = value.doubleValue(); if (v != f) return false; @@ -272,6 +307,12 @@ public class Checker implements EventHandler { } } else { int f = Integer.parseInt(p); + if (value instanceof BigDecimal) { + BigDecimal v = new BigDecimal(value.toString()); + BigDecimal mBD = new BigDecimal(f); + int compare = v.compareTo(mBD); + if (compare != 0) return false; + } if (value instanceof Double) { double v = value.doubleValue(); if (v != f) return false; @@ -301,6 +342,12 @@ public class Checker implements EventHandler { for (String p : patterns) { if (p.contains(".")) { float f = Float.parseFloat(p); + if (value instanceof BigDecimal) { + BigDecimal v = new BigDecimal(value.toString()); + BigDecimal mBD = new BigDecimal(f); + int compare = v.compareTo(mBD); + if (compare == 0) return false; + } if (value instanceof Double) { double v = value.doubleValue(); if (v == f) return false; @@ -323,6 +370,12 @@ public class Checker implements EventHandler { } } else { int f = Integer.parseInt(p); + if (value instanceof BigDecimal) { + BigDecimal v = new BigDecimal(value.toString()); + BigDecimal mBD = new BigDecimal(f); + int compare = v.compareTo(mBD); + if (compare == 0) return false; + } if (value instanceof Double) { double v = value.doubleValue(); if (v == f) return false; @@ -383,7 +436,8 @@ public class Checker implements EventHandler { value instanceof Float || value instanceof Integer || value instanceof Long || - value instanceof Short) { + value instanceof Short || + value instanceof BigDecimal) { // we use a number checker return validateNumber(pattern, (Number) value); } else {
