1 package org.gffs.version;
4 import java.io.FileInputStream;
5 import java.util.Properties;
6 import java.util.regex.Matcher;
7 import java.util.regex.Pattern;
9 public class Version implements Comparable<Version>
11 static final private Pattern VERSION_PATTERN = Pattern.compile(
"^(\\d+)\\.(\\d+)\\.(\\d+)\\s+Build\\s+(\\d+)$");
13 private int _majorVersion;
14 private int _minorVersion;
15 private int _subMinorVersion;
16 private int _buildNumber;
18 public Version(
int major,
int minor,
int subminor,
int buildNumber)
20 _majorVersion = major;
21 _minorVersion = minor;
22 _subMinorVersion = subminor;
23 _buildNumber = buildNumber;
33 Matcher matcher = VERSION_PATTERN.matcher(verString);
34 if (!matcher.matches())
35 throw new IllegalArgumentException(
"Version string wasn't of the form ###.###.### Build ####");
37 _majorVersion = Integer.parseInt(matcher.group(1));
38 _minorVersion = Integer.parseInt(matcher.group(2));
39 _subMinorVersion = Integer.parseInt(matcher.group(3));
40 _buildNumber = Integer.parseInt(matcher.group(4));
45 Properties props =
new Properties();
47 FileInputStream fis =
new FileInputStream(propFile);
49 String appVer = props.getProperty(
"genii.app-version");
50 String buildNum = props.getProperty(
"genii.build-number");
51 String formattedString = appVer +
" Build " + buildNum;
53 }
catch (Throwable t) {
54 throw new RuntimeException(
"failure to parse version from file: " + propFile, t);
75 return (_majorVersion << 3) ^ (_minorVersion << 2) ^ (_subMinorVersion << 1) ^ _buildNumber;
81 return String.format(
"%d.%d.%d Build %d", _majorVersion, _minorVersion, _subMinorVersion, _buildNumber);
87 int diff = _majorVersion - o._majorVersion;
90 diff = _minorVersion - o._minorVersion;
93 diff = _subMinorVersion - o._subMinorVersion;
96 return _buildNumber - o._buildNumber;
static Version EMPTY_VERSION
boolean equals(Version other)
boolean equals(Object other)
Version(int major, int minor, int subminor, int buildNumber)
void parseString(String verString)