brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [20/27] brooklyn-server git commit: tidy esp javadoc and regexes, as per PR comments
Date Fri, 30 Jun 2017 14:03:08 GMT
tidy esp javadoc and regexes, as per PR comments


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/ee853f58
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/ee853f58
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/ee853f58

Branch: refs/heads/master
Commit: ee853f5806f3d2d89f2c76521ec236695f61f80d
Parents: 14aa748
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Jun 28 12:24:36 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Jun 28 12:24:57 2017 +0100

----------------------------------------------------------------------
 .../util/text/BrooklynVersionSyntax.java        | 29 ++++++++++----------
 .../util/text/NaturalOrderComparator.java       |  2 ++
 .../brooklyn/util/text/VersionComparator.java   | 13 ++++-----
 3 files changed, 23 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ee853f58/utils/common/src/main/java/org/apache/brooklyn/util/text/BrooklynVersionSyntax.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/text/BrooklynVersionSyntax.java
b/utils/common/src/main/java/org/apache/brooklyn/util/text/BrooklynVersionSyntax.java
index 63c69e1..e16dcf8 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/text/BrooklynVersionSyntax.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/text/BrooklynVersionSyntax.java
@@ -31,26 +31,27 @@ import com.google.common.base.Preconditions;
  */
 public class BrooklynVersionSyntax {
 
-    private static final String USABLE_REGEX = "[^:\\s/\\\\]+";
+    public static final String USABLE_REGEX = "[^:\\s/\\\\]+";
+    public static final String DOT = "\\.";
 
-    private final static String OSGI_TOKEN_CHARS = "A-Za-z0-9_-";
-    private final static String OSGI_TOKEN_REGEX = "[" + OSGI_TOKEN_CHARS + "]+";
-    private final static String NUMBER = "[0-9]+";
-    private final static String QUALIFIER = OSGI_TOKEN_REGEX;
+    public final static String OSGI_TOKEN_CHARS = "A-Za-z0-9_-";
+    public final static String OSGI_TOKEN_REGEX = "[" + OSGI_TOKEN_CHARS + "]+";
+    public final static String NUMBER = "[0-9]+";
+    public final static String QUALIFIER = OSGI_TOKEN_REGEX;
     
     public final static String VALID_OSGI_VERSION_REGEX = 
         NUMBER + 
-            "(" + "\\." + NUMBER +  
-                "(" + "\\." + NUMBER +  
-                    "(" + "\\." + QUALIFIER +  
+            "(" + DOT + NUMBER +  
+                "(" + DOT + NUMBER +  
+                    "(" + DOT + QUALIFIER +  
                     ")?" +
                 ")?" +
             ")?";
     
     public final static String GOOD_BROOKLYN_VERSION_REGEX = 
         NUMBER + 
-            "(" + "\\." + NUMBER +  
-                "(" + "\\." + NUMBER +  
+            "(" + DOT + NUMBER +  
+                "(" + DOT + NUMBER +  
                     "(" + "-" + QUALIFIER +  
                     ")?" +
                 ")?" +
@@ -72,7 +73,7 @@ public class BrooklynVersionSyntax {
     /** True if the argument matches the Brooklyn version syntax, 
      * <code>MAJOR.MINOR.POINT-QUALIFIER</code> or part thereof (not ending in
a period though),
      * where the first three are whole numbers and the final piece is any valid OSGi token
-     * (something satisfying {@link #isGoodTypeName(String)} with no periods).
+     * (containing letters, numbers, _ and -; no full stops).
      * See also {@link #isValidOsgiVersion(String)} and note this _requires_ a different
separator to OSGi.
      */
     public static boolean isGoodBrooklynVersion(String candidate) {
@@ -82,8 +83,8 @@ public class BrooklynVersionSyntax {
     /** True if the argument matches the OSGi version spec, of the form 
      * <code>MAJOR.MINOR.POINT.QUALIFIER</code> or part thereof (not ending in
a period though),
      * where the first three are whole numbers and the final piece is any valid OSGi token
-     * (something satisfying {@link #isGoodTypeName(String)} with no periods).
-     * See also {@link #isGoodVersion(String)}.
+     * (containing letters, numbers, _ and -; no full stops).
+     * See also {@link #isGoodBrooklynVersion(String)}.
      */
     public static boolean isValidOsgiVersion(String candidate) {
         return candidate!=null && candidate.matches(VALID_OSGI_VERSION_REGEX);
@@ -118,7 +119,7 @@ public class BrooklynVersionSyntax {
     private static String toGoodVersion(String input, String qualifierSeparator, boolean
requireMinorAndPatch) {
         Preconditions.checkNotNull(input);
         final String FUZZY_REGEX = 
-            "(" + NUMBER + "(" + "\\." + NUMBER + "(" + "\\." + NUMBER + ")?)?)?" +  
+            "(" + NUMBER + "(" + DOT + NUMBER + "(" + DOT + NUMBER + ")?)?)?" +  
             "(" + ".*)";
         Matcher m = Pattern.compile(FUZZY_REGEX).matcher(input);
         if (!m.matches()) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ee853f58/utils/common/src/main/java/org/apache/brooklyn/util/text/NaturalOrderComparator.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/text/NaturalOrderComparator.java
b/utils/common/src/main/java/org/apache/brooklyn/util/text/NaturalOrderComparator.java
index 82f4e86..bade244 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/text/NaturalOrderComparator.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/text/NaturalOrderComparator.java
@@ -58,6 +58,8 @@ import java.util.Comparator;
  * but after considering the remainder of the string, so "09.b" > "9.a".
  * decimals are treated like a word-split, not a decimal point, i.e. "1.9" < "1.10".
  * <p>
+ * this does not return anything as equal unless they are the same string.
+ * <p>
  * class is thread-safe.
  * <p>
  * nulls not supported. to support nulls, wrap in guava:

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ee853f58/utils/common/src/main/java/org/apache/brooklyn/util/text/VersionComparator.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/text/VersionComparator.java
b/utils/common/src/main/java/org/apache/brooklyn/util/text/VersionComparator.java
index 09f430d..120a210 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/text/VersionComparator.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/text/VersionComparator.java
@@ -82,8 +82,8 @@ public class VersionComparator implements Comparator<String> {
         TwoBooleans snapshots = TwoBooleans.of(isSnapshot(v1), isSnapshot(v2));
         if (snapshots.different()) return snapshots.compare(true);
 
-        String u1 = versionWithQualifier(v1);
-        String u2 = versionWithQualifier(v2);
+        String u1 = versionWithoutQualifier(v1);
+        String u2 = versionWithoutQualifier(v2);
         int uq = NaturalOrderComparator.INSTANCE.compare(u1, u2);
         if (uq!=0) return uq;
         
@@ -111,13 +111,12 @@ public class VersionComparator implements Comparator<String> {
         
         // finally, do normal comparison if both have qualifier or both unqualified (in case
leading 0's are used)
         return NaturalOrderComparator.INSTANCE.compare(v1, v2);
-        
-        // (previously we did this but don't think we need any of that complexity)
-        //return compareDotSplitParts(splitOnDot(v1), splitOnDot(v2));
     }
 
-    private String versionWithQualifier(String v1) {
-        Matcher q = Pattern.compile("([0-9]+(\\.[0-9]+(\\.[0-9])?)?)(.*)").matcher(v1);
+    private String versionWithoutQualifier(String v1) {
+        Matcher q = Pattern.compile("("+BrooklynVersionSyntax.NUMBER+
+            "("+BrooklynVersionSyntax.DOT+BrooklynVersionSyntax.NUMBER+
+                "("+BrooklynVersionSyntax.DOT+BrooklynVersionSyntax.NUMBER+")?)?)(.*)").matcher(v1);
         return q.matches() ? q.group(1) : "";
     }
 


Mime
View raw message