4148fc7e2496460d22e4499df2c93d27c99383be
[jSite2.git] / src / net / pterodactylus / jsite / main / Version.java
1 /*
2  * jSite2 - Version.java -
3  * Copyright © 2008 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package net.pterodactylus.jsite.main;
21
22 /**
23  * Container for version information.
24  * 
25  * @author David Roden <bombe@freenetproject.org>
26  * @version $Id$
27  */
28 public class Version implements Comparable<Version> {
29
30         /** The version of the application. */
31         private static final Version VERSION = new Version(0, 9, 0);
32
33         /** The major level of the version. */
34         private final int major;
35
36         /** The minor level of the version. */
37         private final int minor;
38
39         /** The patch level of the version. */
40         private final int patch;
41
42         /**
43          * Creates a new version with the given major level and minor and patch
44          * levels set to <code>0</code>.
45          * 
46          * @param major
47          *            The major level of the version
48          */
49         public Version(int major) {
50                 this(major, 0);
51         }
52
53         /**
54          * Creates a new version with the given major and minor level and the patch
55          * level set to <code>0</code>.
56          * 
57          * @param major
58          *            The major level of the version
59          * @param minor
60          *            The minor level of the version
61          */
62         public Version(int major, int minor) {
63                 this(major, minor, 0);
64         }
65
66         /**
67          * Creates a new version with the given major, minor, and patch level.
68          * 
69          * @param major
70          *            The major level of the version
71          * @param minor
72          *            The minor level of the version
73          * @param patch
74          *            The patch level of the version
75          */
76         public Version(int major, int minor, int patch) {
77                 this.major = major;
78                 this.minor = minor;
79                 this.patch = patch;
80         }
81
82         /**
83          * Returns the version of the application.
84          * 
85          * @return The version of the application
86          */
87         public static Version getVersion() {
88                 return VERSION;
89         }
90
91         /**
92          * Returns the major level of the version.
93          * 
94          * @return The major level of the version
95          */
96         public int getMajor() {
97                 return major;
98         }
99
100         /**
101          * Returns the minor level of the version.
102          * 
103          * @return The minor level of the version
104          */
105         public int getMinor() {
106                 return minor;
107         }
108
109         /**
110          * Returns the patch level of the version.
111          * 
112          * @return The patch level of the version
113          */
114         public int getPatch() {
115                 return patch;
116         }
117
118         /**
119          * {@inheritDoc}
120          */
121         public int compareTo(Version version) {
122                 return (major != version.major) ? (major - version.major) : ((minor != version.minor) ? (minor - version.minor) : (patch - version.patch));
123         }
124
125         /**
126          * {@inheritDoc}
127          */
128         @Override
129         public String toString() {
130                 return major + "." + minor + "." + patch;
131         }
132
133 }