1 package org.mortbay.start; 16 17 22 23 public class Version { 24 25 int _version = 0; 26 int _revision = 0; 27 int _subrevision = 0; 28 String _suffix = ""; 29 30 public Version() { 31 } 32 33 public Version(String version_string) { 34 parse(version_string); 35 } 36 37 41 public void parse(String version_string) { 42 _version = 0; 43 _revision = 0; 44 _subrevision = 0; 45 _suffix = ""; 46 int pos = 0; 47 int startpos = 0; 48 int endpos = version_string.length(); 49 while ( (pos < endpos) && Character.isDigit(version_string.charAt(pos))) { 50 pos++; 51 } 52 _version = Integer.parseInt(version_string.substring(startpos,pos)); 53 if ((pos < endpos) && version_string.charAt(pos)=='.') { 54 startpos = ++pos; 55 while ( (pos < endpos) && Character.isDigit(version_string.charAt(pos))) { 56 pos++; 57 } 58 _revision = Integer.parseInt(version_string.substring(startpos,pos)); 59 } 60 if ((pos < endpos) && version_string.charAt(pos)=='.') { 61 startpos = ++pos; 62 while ( (pos < endpos) && Character.isDigit(version_string.charAt(pos))) { 63 pos++; 64 } 65 _subrevision = Integer.parseInt(version_string.substring(startpos,pos)); 66 } 67 if (pos < endpos) { 68 _suffix = version_string.substring(pos); 69 } 70 } 71 72 75 public String toString() { 76 StringBuffer sb = new StringBuffer (10); 77 sb.append(_version); 78 sb.append('.'); 79 sb.append(_revision); 80 sb.append('.'); 81 sb.append(_subrevision); 82 sb.append(_suffix); 83 return sb.toString(); 84 } 85 86 94 public int compare(Version other) { 95 if (other == null) throw new NullPointerException ("other version is null"); 96 if (this._version < other._version) return -1; 97 if (this._version > other._version) return 1; 98 if (this._revision < other._revision) return -1; 99 if (this._revision > other._revision) return 1; 100 if (this._subrevision < other._subrevision) return -1; 101 if (this._subrevision > other._subrevision) return 1; 102 return 0; 103 } 104 105 108 public boolean isInRange(Version low, Version high) { 109 return (compare(low)>=0 && compare(high)<=0); 110 } 111 } 112 | Popular Tags |