1 26 27 package com.opensugar.cube.packageAdmin; 28 29 import java.util.StringTokenizer ; 30 31 public class GoRoCoVersion { 34 35 40 42 private Integer generation = null; 44 private Integer revision = new Integer ( Integer.MIN_VALUE ); 46 private Integer correction = new Integer ( Integer.MIN_VALUE ); 48 49 public GoRoCoVersion( String value ) { 51 if ( value != null ) { 52 if ( ( value.startsWith( "\"" ) && value.endsWith( "\"" ) ) || ( value.startsWith( "'" ) && value.endsWith( "'" ) ) ) { 54 value = value.substring( 1, value.length() - 1 ); 55 } 56 StringTokenizer tokens = new StringTokenizer ( value, "." ); 58 try { 59 generation = Integer.valueOf( tokens.nextToken() ); 61 if ( tokens.hasMoreTokens() ) { 63 revision = Integer.valueOf( tokens.nextToken() ); 64 } 65 if ( tokens.hasMoreTokens() ) { 67 correction = Integer.valueOf( tokens.nextToken() ); 68 } 69 if ( tokens.hasMoreTokens() ) { 72 } 75 } 76 catch( NumberFormatException e ) { 77 generation = null; 81 revision = new Integer ( Integer.MIN_VALUE ); 82 correction = new Integer ( Integer.MIN_VALUE ); 83 } 84 } 85 } 86 87 protected Integer getGeneration() { 89 return generation; 90 } 91 92 protected Integer getRevision() { 94 return revision; 95 } 96 97 protected Integer getCorrection() { 99 return correction; 100 } 101 102 public int compareTo( Object obj ) { 110 GoRoCoVersion versionToCompareTo = (GoRoCoVersion)obj; 111 112 if ( isUndefined() && versionToCompareTo.isUndefined() ) { 113 return 0; 115 } 116 else if ( isUndefined() || versionToCompareTo.isUndefined() ) { 117 return 1; 120 } 121 122 Integer generation2 = versionToCompareTo.getGeneration(); 123 Integer revision2 = versionToCompareTo.getRevision(); 124 Integer correction2 = versionToCompareTo.getCorrection(); 125 126 int n = generation.intValue() - generation2.intValue(); 128 if ( n == 0 ) { 129 n = revision.intValue() - revision2.intValue(); 131 if ( n == 0 ) { 132 return correction.intValue() - correction2.intValue(); 134 } 135 return n; 136 } 137 return n; 138 } 139 140 public boolean equals( Object obj ) { 142 if ( compareTo( obj ) == 0 ) { 143 return true; 144 } 145 return false; 146 } 147 148 public String toString() { 150 if ( isUndefined() ) { 151 return "Undefined"; 152 } 153 else { 154 StringBuffer sb = new StringBuffer ( generation.toString() ); 155 if ( revision.intValue() >= 0 ) { 157 sb.append( "." + revision.toString() ); 158 if ( correction.intValue() >= 0 ) { 160 sb.append( "." + correction.toString() ); 161 } 162 } 163 return sb.toString(); 164 } 165 } 166 167 public boolean isUndefined() { 169 if ( generation == null ) { 170 return true; 171 } 172 return false; 173 } 174 175 } | Popular Tags |