Author: jason.greene(a)jboss.com
Date: 2007-08-15 18:02:36 -0400 (Wed, 15 Aug 2007)
New Revision: 4299
Modified:
core/trunk/src/main/java/org/jboss/cache/Version.java
Log:
Use regex for parsing
Modified: core/trunk/src/main/java/org/jboss/cache/Version.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Version.java 2007-08-15 18:30:00 UTC (rev
4298)
+++ core/trunk/src/main/java/org/jboss/cache/Version.java 2007-08-15 22:02:36 UTC (rev
4299)
@@ -102,22 +102,11 @@
else if ("1.2.4.SP1".equals(versionString))
return 1241;
- StringTokenizer tokenizer = new StringTokenizer(versionString, ".-");
+ String parts[] = versionString.split("[\\.\\-]");
+ if (parts.length < 3)
+ throw new IllegalArgumentException("versionString should be at least 3
parts!");
- int major = 0;
- int minor = 0;
- int patch = 0;
-
- if (tokenizer.hasMoreTokens())
- major = Integer.parseInt(tokenizer.nextToken());
- if (tokenizer.hasMoreTokens())
- minor = Integer.parseInt(tokenizer.nextToken());
- if (tokenizer.hasMoreTokens()) {
- String ps = tokenizer.nextToken();
- patch = Integer.parseInt(ps);
- }
-
- return encodeVersion(major, minor, patch);
+ return encodeVersion(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]),
Integer.parseInt(parts[2]));
}
public static String getVersionString(short versionShort)
Show replies by date