2 * jSite - a tool for uploading websites into Freenet
3 * Copyright (C) 2006 David Roden
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.
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.
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.
20 package de.todesbaum.jsite.main;
23 * Container for version information.
25 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
27 public class Version implements Comparable<Version> {
30 private static final Version VERSION = new Version(0, 6, 2);
32 /** The components of the version information. */
33 private final int[] components;
36 * Creates a new version container with the given components.
39 * The version components
41 public Version(int... components) {
42 this.components = new int[components.length];
43 System.arraycopy(components, 0, this.components, 0, components.length);
47 * Returns the number of version components.
49 * @return The number of version components
52 return components.length;
56 * Returns the version component with the given index.
59 * The index of the version component
60 * @return The version component
62 public int getComponent(int index) {
63 return components[index];
67 * Returns the version.
71 public static final String getVersion() {
72 return VERSION.toString();
79 public String toString() {
80 StringBuilder versionString = new StringBuilder();
81 for (int component : components) {
82 if (versionString.length() != 0) {
83 versionString.append('.');
85 versionString.append(component);
87 return versionString.toString();
93 public int compareTo(Version version) {
94 int lessComponents = Math.min(components.length, version.components.length);
95 for (int index = 0; index < lessComponents; index++) {
96 if (version.components[index] == components[index]) {
99 return components[index] - version.components[index];
101 return components.length - version.components.length;