brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [09/27] brooklyn-server git commit: tidy version comparator, removing old code
Date Fri, 30 Jun 2017 14:02:57 GMT
tidy version comparator, removing old code


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

Branch: refs/heads/master
Commit: cc703928e1a2bd9c97795acab9a747a3733eb4a2
Parents: 5b2cc48
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Jun 20 16:49:57 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Jun 20 16:49:57 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/util/text/VersionComparator.java   | 143 -------------------
 .../util/text/VersionComparatorTest.java        |  21 ---
 2 files changed, 164 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cc703928/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 bac1929..e5d1fbf 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
@@ -18,17 +18,10 @@
  */
 package org.apache.brooklyn.util.text;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
 import java.util.Comparator;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.brooklyn.util.text.NaturalOrderComparator;
-import org.apache.brooklyn.util.text.Strings;
-
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Objects;
 
 /**
@@ -121,140 +114,4 @@ public class VersionComparator implements Comparator<String> {
         return q.matches() ? q.group(1) : "";
     }
 
-    private boolean isQualifiedAndUnqualifiedVariantOfSameVersion(String v1, String v2) {
-        Matcher q = Pattern.compile("([0-9]+(\\.[0-9]+(\\.[0-9])?)?)(.*)").matcher(v1);
-        return (q.matches() && q.group(1).equals(v2));
-    }
-
-    private static boolean hasQualifier(String v) {
-        return !v.matches("[0-9]+(\\.[0-9]+(\\.[0-9])?)?");
-    }
-    
-    @VisibleForTesting
-    static String[] splitOnDot(String v) {
-        return v.split("(?<=\\.)|(?=\\.)");
-    }
-    
-    private int compareDotSplitParts(String[] v1Parts, String[] v2Parts) {
-        for (int i = 0; ; i++) {
-            if (i >= v1Parts.length && i >= v2Parts.length) {
-                // end of both
-                return 0;
-            }
-            if (i == v1Parts.length) {
-                // sequence depends whether the extra part *starts with* a number
-                // ie
-                //                   2.0 < 2.0.0
-                // and
-                //   2.0.qualifier < 2.0 < 2.0.0qualifier < 2.0.0-qualifier <
2.0.0.qualifier < 2.0.0 < 2.0.9-qualifier
-                return isNumberInFirstCharPossiblyAfterADot(v2Parts, i) ? -1 : 1;
-            }
-            if (i == v2Parts.length) {
-                // as above but inverted
-                return isNumberInFirstCharPossiblyAfterADot(v1Parts, i) ? 1 : -1;
-            }
-            // not at end; compare this dot split part
-            
-            int result = compareDotSplitPart(v1Parts[i], v2Parts[i]);
-            if (result!=0) return result;
-        }
-    }
-    
-    private int compareDotSplitPart(String v1, String v2) {
-        String[] v1Parts = splitOnNonWordChar(v1);
-        String[] v2Parts = splitOnNonWordChar(v2);
-        
-        for (int i = 0; ; i++) {
-            if (i >= v1Parts.length && i >= v2Parts.length) {
-                // end of both
-                return 0;
-            }
-            if (i == v1Parts.length) {
-                // shorter set always wins here; i.e.
-                // 1-qualifier < 1
-                return 1;
-            }
-            if (i == v2Parts.length) {
-                // as above but inverted
-                return -1;
-            }
-            // not at end; compare this dot split part
-            
-            String v1p = v1Parts[i];
-            String v2p = v2Parts[i];
-            
-            if (v1p.equals(v2p)) continue;
-            
-            if (isNumberInFirstChar(v1p) || isNumberInFirstChar(v2p)) {
-                // something starting with a number is higher than something not
-                if (!isNumberInFirstChar(v1p)) return -1;
-                if (!isNumberInFirstChar(v2p)) return 1;
-                
-                // both start with numbers; can use natural order comparison *unless*
-                // one is purely a number AND the other *begins* with that number,
-                // followed by non-digit chars, in which case prefer the pure number
-                // ie:
-                //           1beta < 1
-                // but note
-                //            1 < 2beta < 11beta
-                if (isNumber(v1p) || isNumber(v2p)) {
-                    if (!isNumber(v1p)) {
-                        if (v1p.startsWith(v2p)) {
-                            if (!isNumberInFirstChar(Strings.removeFromStart(v1p, v2p)))
{
-                                // v2 is a number, and v1 is the same followed by non-numbers
-                                return -1;
-                            }
-                        }
-                    }
-                    if (!isNumber(v2p)) {
-                        // as above but inverted
-                        if (v2p.startsWith(v1p)) {
-                            if (!isNumberInFirstChar(Strings.removeFromStart(v2p, v1p)))
{
-                                return 1;
-                            }
-                        }
-                    }
-                    // both numbers, skip to natural order comparison
-                }
-            }
-            
-            // otherwise it is in-order
-            int result = NaturalOrderComparator.INSTANCE.compare(v1p, v2p);
-            if (result!=0) return result;
-        }
-    }
-
-    @VisibleForTesting
-    static String[] splitOnNonWordChar(String v) {
-        Collection<String> parts = new ArrayList<String>();
-        String remaining = v;
-        
-        // use lookahead to split on all non-letter non-numbers, putting them into their
own buckets 
-        parts.addAll(Arrays.asList(remaining.split("(?<=[^0-9\\p{L}])|(?=[^0-9\\p{L}])")));
-        return parts.toArray(new String[parts.size()]);
-    }
-
-    @VisibleForTesting
-    static boolean isNumberInFirstCharPossiblyAfterADot(String[] parts, int i) {
-        if (parts==null || parts.length<=i) return false;
-        if (isNumberInFirstChar(parts[i])) return true;
-        if (".".equals(parts[i])) {
-            if (parts.length>i+1)
-                if (isNumberInFirstChar(parts[i+1])) 
-                    return true;
-        }
-        return false;
-    }
-
-    @VisibleForTesting
-    static boolean isNumberInFirstChar(String v) {
-        if (v==null || v.length()==0) return false;
-        return Character.isDigit(v.charAt(0));
-    }
-    
-    @VisibleForTesting
-    static boolean isNumber(String v) {
-        if (v==null || v.length()==0) return false;
-        return v.matches("[\\d]+");
-    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cc703928/utils/common/src/test/java/org/apache/brooklyn/util/text/VersionComparatorTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/text/VersionComparatorTest.java
b/utils/common/src/test/java/org/apache/brooklyn/util/text/VersionComparatorTest.java
index 0821267..aa01c79 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/text/VersionComparatorTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/text/VersionComparatorTest.java
@@ -27,27 +27,6 @@ import org.testng.Assert;
 import org.testng.annotations.Test;
 
 public class VersionComparatorTest {
-
-    @Test
-    public void testStaticHelpers() {
-        Assert.assertEquals(VersionComparator.splitOnDot("a.b.cc"), new String[] { "a", ".",
"b", ".", "cc" });
-        Assert.assertEquals(VersionComparator.splitOnDot("a..b-c"), new String[] { "a", ".",
".", "b-c" });
-
-        Assert.assertEquals(VersionComparator.splitOnNonWordChar("a1-b__cc9c"), new String[]
{ 
-            "a1", "-", "b", "_", "_", "cc9c" });
-
-        Assert.assertEquals(VersionComparator.isNumberInFirstChar("1a"), true);
-        Assert.assertEquals(VersionComparator.isNumberInFirstChar("a1"), false);
-        Assert.assertEquals(VersionComparator.isNumberInFirstChar(""), false);
-        Assert.assertEquals(VersionComparator.isNumberInFirstChar(null), false);
-        
-        Assert.assertEquals(VersionComparator.isNumber("1"), true);
-        Assert.assertEquals(VersionComparator.isNumber("1111"), true);
-        Assert.assertEquals(VersionComparator.isNumber("1a"), false);
-        Assert.assertEquals(VersionComparator.isNumber("a1"), false);
-        Assert.assertEquals(VersionComparator.isNumber(""), false);
-        Assert.assertEquals(VersionComparator.isNumber(null), false);
-    }
     
     @Test
     public void testSnapshotSuffixComparison() {


Mime
View raw message