jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1381982 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint: DoubleConstraint.java LongConstraint.java NumericConstraint.java
Date Fri, 07 Sep 2012 11:40:33 GMT
Author: mduerig
Date: Fri Sep  7 11:40:33 2012
New Revision: 1381982

URL: http://svn.apache.org/viewvc?rev=1381982&view=rev
Log:
OAK-66: JCR Node Type Management
value constraints for Numeric: refactor

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/DoubleConstraint.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/LongConstraint.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/NumericConstraint.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/DoubleConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/DoubleConstraint.java?rev=1381982&r1=1381981&r2=1381982&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/DoubleConstraint.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/DoubleConstraint.java
Fri Sep  7 11:40:33 2012
@@ -30,21 +30,10 @@ public class DoubleConstraint extends Nu
     }
 
     @Override
-    protected void setBounds(String lowerBound, String upperBound) {
-        try {
-            this.lowerBound = lowerBound == null || lowerBound.isEmpty()
-                ? null
-                : Double.parseDouble(lowerBound);
-
-            this.upperBound = upperBound == null || upperBound.isEmpty()
-                ? null
-                : Double.parseDouble(upperBound);
-        }
-        catch (NumberFormatException e) {
-            this.lowerBound = 1.0;
-            this.upperBound = 0.0;
-            log.warn("Invalid bound for numeric constraint" + this, e);
-        }
+    protected Double getBound(String bound) {
+        return  bound == null || bound.isEmpty()
+            ? null
+            : Double.parseDouble(bound);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/LongConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/LongConstraint.java?rev=1381982&r1=1381981&r2=1381982&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/LongConstraint.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/LongConstraint.java
Fri Sep  7 11:40:33 2012
@@ -30,21 +30,10 @@ public class LongConstraint extends Nume
     }
 
     @Override
-    protected void setBounds(String lowerBound, String upperBound) {
-        try {
-            this.lowerBound = lowerBound == null || lowerBound.isEmpty()
-                ? null
-                : Long.parseLong(lowerBound);
-
-            this.upperBound = upperBound == null || upperBound.isEmpty()
-                ? null
-                : Long.parseLong(upperBound);
-        }
-        catch (NumberFormatException e) {
-            this.lowerBound = 1L;
-            this.upperBound = 0L;
-            log.warn("Invalid bound for numeric constraint" + this, e);
-        }
+    protected Long getBound(String bound) {
+        return  bound == null || bound.isEmpty()
+            ? null
+            : Long.parseLong(bound);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/NumericConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/NumericConstraint.java?rev=1381982&r1=1381981&r2=1381982&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/NumericConstraint.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/constraint/NumericConstraint.java
Fri Sep  7 11:40:33 2012
@@ -30,9 +30,10 @@ import org.slf4j.LoggerFactory;
 public abstract class NumericConstraint<T> implements Predicate<Value> {
     private static final Logger log = LoggerFactory.getLogger(NumericConstraint.class);
 
+    private boolean invalid;
     private boolean lowerInclusive;
-    protected T lowerBound;
-    protected T upperBound;
+    private T lowerBound;
+    private T upperBound;
     private boolean upperInclusive;
 
     protected NumericConstraint(String definition) {
@@ -40,28 +41,38 @@ public abstract class NumericConstraint<
         Pattern pattern = Pattern.compile("([\\(\\[])[^,]*,[^\\)\\]]*([\\)\\]])");
         Matcher matcher = pattern.matcher(definition);
         if (matcher.matches()) {
-            // group 1 is lower inclusive/exclusive
-            String match = matcher.group(1);
-            lowerInclusive = "[".equals(match);
-
-            // group 2 is lower, group 3 is upper  bound
-            setBounds(matcher.group(2), matcher.group(3));
-
-            // group 4 is lower inclusive/exclusive
-            match = matcher.group(4);
-            upperInclusive = "]".equals(match);
+            try {
+                // group 1 is lower inclusive/exclusive
+                String match = matcher.group(1);
+                lowerInclusive = "[".equals(match);
+
+                // group 2 is lower, group 3 is upper  bound
+                lowerBound = getBound(matcher.group(2));
+                upperBound = getBound(matcher.group(3));
+
+                // group 4 is lower inclusive/exclusive
+                match = matcher.group(4);
+                upperInclusive = "]".equals(match);
+            }
+            catch (NumberFormatException e) {
+                invalid(definition);
+            }
         }
         else {
-            String msg = '\'' + definition + "' is not a valid value constraint format for
numeric values";
-            log.warn(msg);
+            invalid(definition);
         }
     }
 
-    protected abstract void setBounds(String lowerBound, String upperBound);
+    private void invalid(String definition) {
+        invalid = true;
+        log.warn('\'' + definition + "' is not a valid value constraint format for numeric
values");
+    }
+
+    protected abstract T getBound(String bound);
 
     @Override
     public boolean apply(@Nullable Value value) {
-        if (value == null) {
+        if (value == null || invalid) {
             return false;
         }
 



Mime
View raw message