01: /*
02: * VersionNumber.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.util;
13:
14: /**
15: * @author support@sql-workbench.net
16: */
17: public class VersionNumber {
18: private int major = -1;
19: private int minor = -1;
20:
21: public VersionNumber(int majorVersion, int minorVersion) {
22: this .major = majorVersion;
23: this .minor = minorVersion;
24: }
25:
26: public VersionNumber(String number) {
27: if (StringUtil.isEmptyString(number)) {
28: return;
29: }
30:
31: if ("@BUILD_NUMBER@".equals(number)) {
32: major = 999;
33: minor = 999;
34: } else {
35: try {
36: String[] numbers = number.split("\\.");
37:
38: major = Integer.parseInt(numbers[0]);
39:
40: if (numbers.length > 1) {
41: minor = Integer.parseInt(numbers[1]);
42: } else {
43: minor = -1;
44: }
45: } catch (Exception e) {
46: minor = -1;
47: major = -1;
48: }
49: }
50: }
51:
52: public boolean isValid() {
53: return this .major != -1;
54: }
55:
56: public int getMajorVersion() {
57: return this .major;
58: }
59:
60: public int getMinorVersion() {
61: return this .minor;
62: }
63:
64: public boolean isNewerThan(VersionNumber other) {
65: if (!this .isValid())
66: return false;
67: if (this .major > other.major)
68: return true;
69: if (this .major == other.major) {
70: if (this .minor > other.minor)
71: return true;
72: }
73: return false;
74: }
75:
76: public boolean isNewerOrEqual(VersionNumber other) {
77: if (isNewerThan(other))
78: return true;
79: if (this .major == other.major && this .minor == other.minor)
80: return true;
81: return false;
82: }
83:
84: public String toString() {
85: if (minor == -1 && major == -1)
86: return "n/a";
87:
88: if (minor == -1)
89: return Integer.toString(major);
90: return Integer.toString(major) + "." + Integer.toString(minor);
91: }
92: }
|