Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Private Member Functions | Static Private Member Functions
org.mozilla.xpcom.VersionComparator Class Reference

Version strings are dot-separated sequences of version-parts. More...

Inheritance diagram for org.mozilla.xpcom.VersionComparator:
Inheritance graph
[legend]
Collaboration diagram for org.mozilla.xpcom.VersionComparator:
Collaboration graph
[legend]

List of all members.

Classes

class  VersionPart

Public Member Functions

nsISupports queryInterface (String aIID)
int compare (String A, String B)
 Compare two version strings.

Private Member Functions

int compareVersionPart (VersionPart va, VersionPart vb)
int compareInt (int n1, int n2)
int compareString (String str1, String str2)

Static Private Member Functions

static String parseVersionPart (String aVersion, VersionPart result)

Detailed Description

Version strings are dot-separated sequences of version-parts.

A version-part consists of up to four parts, all of which are optional:
<number-a><string-b><number-c> <string-d (everything else)>

A version-part may also consist of a single asterisk "*" which indicates "infinity".

Numbers are base-10, and are zero if left out. Strings are compared bytewise.

For additional backwards compatibility, if "string-b" is "+" then "number-a" is incremented by 1 and "string-b" becomes "pre".

 1.0pre1
 < 1.0pre2  
   < 1.0 == 1.0.0 == 1.0.0.0
     < 1.1pre == 1.1pre0 == 1.0+
       < 1.1pre1a
         < 1.1pre1
           < 1.1pre10a
             < 1.1pre10
 

Although not required by this interface, it is recommended that numbers remain within the limits of a signed char, i.e. -127 to 128.

Definition at line 76 of file VersionComparator.java.


Member Function Documentation

Compare two version strings.

Parameters:
Aa version string
Ba version string
Returns:
a value less than 0 if A < B; the value 0 if A == B; or a value greater than 0 if A > B

Definition at line 90 of file VersionComparator.java.

                                         {
    int result;
    String a = A, b = B;

    do {
      VersionPart va = new VersionPart();
      VersionPart vb = new VersionPart();
      a = parseVersionPart(a, va);
      b = parseVersionPart(b, vb);

      result = compareVersionPart(va, vb);
      if (result != 0) {
        break;
      }
    } while (a != null || b != null);

    return result;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

int org.mozilla.xpcom.VersionComparator.compareInt ( int  n1,
int  n2 
) [inline, private]

Definition at line 188 of file VersionComparator.java.

                                         {
    return n1 - n2;
  }

Here is the caller graph for this function:

int org.mozilla.xpcom.VersionComparator.compareString ( String  str1,
String  str2 
) [inline, private]

Definition at line 192 of file VersionComparator.java.

                                                      {
    // any string is *before* no string
    if (str1 == null) {
      return (str2 != null) ? 1 : 0;
    }

    if (str2 == null) {
      return -1;
    }

    return str1.compareTo(str2);
  }

Here is the caller graph for this function:

Definition at line 169 of file VersionComparator.java.

                                                                 {
    int res = compareInt(va.numA, vb.numA);
    if (res != 0) {
      return res;
    }

    res = compareString(va.strB, vb.strB);
    if (res != 0) {
      return res;
    }

    res = compareInt(va.numC, vb.numC);
    if (res != 0) {
      return res;
    }

    return compareString(va.extraD, vb.extraD);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static String org.mozilla.xpcom.VersionComparator.parseVersionPart ( String  aVersion,
VersionPart  result 
) [inline, static, private]

Definition at line 116 of file VersionComparator.java.

                                                                              {
    if (aVersion == null || aVersion.length() == 0) {
      return aVersion;
    }

    StringTokenizer tok = new StringTokenizer(aVersion.trim(), ".");
    String part = tok.nextToken();

    if (part.equals("*")) {
      result.numA = Integer.MAX_VALUE;
      result.strB = "";
    } else {
      VersionPartTokenizer vertok = new VersionPartTokenizer(part);
      try {
        result.numA = Integer.parseInt(vertok.nextToken());
      } catch (NumberFormatException e) {
        // parsing error; default to zero like 'strtol' C function
        result.numA = 0;
      }

      if (vertok.hasMoreElements()) {
        String str = vertok.nextToken();

        // if part is of type "<num>+"
        if (str.charAt(0) == '+') {
          result.numA++;
          result.strB = "pre";
        } else {
          // else if part is of type "<num><alpha>..."
          result.strB = str;

          if (vertok.hasMoreTokens()) {
            try {
              result.numC = Integer.parseInt(vertok.nextToken());
            } catch (NumberFormatException e) {
              // parsing error; default to zero like 'strtol' C function
              result.numC = 0;
            }
            if (vertok.hasMoreTokens()) {
              result.extraD = vertok.getRemainder();
            }
          }
        }
      }
    }

    if (tok.hasMoreTokens()) {
      // return everything after "."
      return aVersion.substring(part.length() + 1);
    }
    return null;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 78 of file VersionComparator.java.

                                                 {
    return Mozilla.queryInterface(this, aIID);
  }

Here is the call graph for this function:


The documentation for this class was generated from the following file: