Version.java

biz/hammurapi/util/Version.java

Violations

Inspector Message Severity Location
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 089 Undocumented parameter micro 2 45:9
Java Inspector 089 Javadoc contains tag for non-existent parameter rev 2 45:9
Java Inspector 089 Undocumented constructor 2 51:9
Java Inspector 089 Method is not properly documented 2 67:9
Java Inspector 089 Undocumented parameter o 2 67:9
Java Inspector 089 Javadoc contains tag for non-existent parameter other 2 67:9
Java Inspector 089 Method return value is not properly documented 2 67:9
Java Inspector 089 Undocumented method 2 85:9
Java Inspector 089 Undocumented method 2 102:9
Java Inspector 089 Undocumented method 2 106:9
Java Inspector 089 Undocumented method 2 110:9
Java Inspector 089 Undocumented method 2 114:9
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 53:39
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 52:65
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 58:60
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 82:32
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 82:46
Java Inspector 051 It is good practice to call in any case super() in a constructor. 3 45:9
Java Inspector 051 It is good practice to call in any case super() in a constructor. 3 51:9
Java Inspector 090 Unnecessary else part in if. The main part terminates control flow (return, break, throw, or continue). 3 68:17
Java Inspector 090 Unnecessary else part in if. The main part terminates control flow (return, break, throw, or continue). 3 89:33

Source code

1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.util;
24
25import java.util.StringTokenizer;
26
27/**
28 * Represents 3-digit version
29 * @author Pavel Vlasov
30 * @version $Revision: 1.2 $
31 */
32public final class Version implements Comparable {
33 private int major;
34 private int minor;
35 private int micro;
36
37 /**
38 * Create a new instance of a <code>Version</code> object with the
39 * specified version numbers.
40 *
41 * @param major Major version number.
42 * @param minor Minor version number.
43 * @param rev Micro version number.
44 */
45 public Version(int major, int minor, int micro) {
46 this.major = major;
47 this.minor = minor;
48 this.micro = micro;
49 }
50
51 public Version(String version) {
52 StringTokenizer st=new StringTokenizer(version, ".");
53 if (st.countTokens()==3) {
54 major=Integer.parseInt(st.nextToken());
55 minor=Integer.parseInt(st.nextToken());
56 micro=Integer.parseInt(st.nextToken());
57 } else {
58 throw new IllegalArgumentException("Invalid version format: "+version);
59 }
60 }
61
62 /**
63 *
64 * @param other
65 * @return
66 */
67 public boolean equals(Object o) {
68 if (o instanceof Version) {
69 Version v=(Version) o;
70 return v.major==major && v.minor==minor && v.micro==micro;
71 } else {
72 return super.equals(o);
73 }
74 }
75
76 /**
77 * Overload toString to report version correctly.
78 *
79 * @return the dot seperated version string
80 */
81 public String toString() {
82 return major + "." + minor + "." + micro;
83 }
84
85 public int compareTo(Object o) {
86 if (o instanceof Version) {
87 Version v=(Version) o;
88 if (v.major==major) {
89 if (v.minor==minor) {
90 return micro-v.micro;
91 } else {
92 return minor-v.minor;
93 }
94 } else {
95 return major-v.major;
96 }
97 } else {
98 return hashCode()-o.hashCode();
99 }
100 }
101
102 public int hashCode() {
103 return major ^ minor ^ micro;
104 }
105
106 public int getMajor() {
107 return major;
108 }
109
110 public int getMicro() {
111 return micro;
112 }
113
114 public int getMinor() {
115 return minor;
116 }
117}