brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahgittin <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #740: New versioning rules prep
Date Wed, 28 Jun 2017 10:48:41 GMT
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/740#discussion_r124509326
  
    --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/text/NaturalOrderComparator.java
---
    @@ -140,6 +147,32 @@ public int compare(String a, String b) {
                     if ((result = compareRight(a.substring(ia), b.substring(ib))) != 0) {
                         return result;
                     }
    +                // numeric portion is the same; previously we incremented and checked
again
    +                // which is inefficient (we keep checking remaining numbers here);
    +                // also if we want to compare on 0's after comparing remainder of string
    +                // we need to recurse here after skipping the digits we just checked
above
    +                do {
    +                    ia++; ib++;
    +                    boolean aDigitsDone = ia >= a.length() || !Character.isDigit(charAt(a,
ia));
    +                    boolean bDigitsDone = ib >= b.length() || !Character.isDigit(charAt(b,
ib));
    +                    if (aDigitsDone != bDigitsDone) {
    +                        // sanity check
    +                        throw new IllegalStateException("Digit sequence lengths should
have matched, '"+a+"' v '"+b+"'");
    +                    }
    +                    if (aDigitsDone) break;
    +                } while (true);
    +                if (ia < a.length() || ib < b.length()) {
    +                    if (ia >= a.length()) return -1;  // only b has more chars
    +                    if (ib >= b.length()) return 1;  // only a has more chars
    +                    // both have remaining chars; neither is numeric due to compareRight;
recurse into remaining
    +                    if ((result = compare(a.substring(ia), b.substring(ib))) != 0) {
    +                        return result;
    +                    }
    +                }
    +                // numbers are equal value, remaining string compares identical; 
    +                // comes down to whether there are any leading zeroes here
    +                return nzb-nza;
    +                
                 } else if ((Character.isDigit(ca) || nza>0) && (Character.isDigit(cb)
|| nzb>0)) {
                     // both sides are numbers, but at least one is a sequence of zeros
                     if (nza==0) {
    --- End diff --
    
    his `charAt` returns 0 if we've gone beyond the string length, i think it might rely on
that


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message