X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fde%2Ftodesbaum%2Fjsite%2Fmain%2FVersion.java;h=ec7df392b6f5b5ebe9e457069910c6f297f06ad8;hb=61db8327999361bf9154236a8713bf72c06bc3d7;hp=7c36c9e4050d82f6ad6f4a774f5be228fa049d1a;hpb=0bf8d542053724e3ac96435d00f437889b0a9953;p=jSite.git
diff --git a/src/de/todesbaum/jsite/main/Version.java b/src/de/todesbaum/jsite/main/Version.java
index 7c36c9e..ec7df39 100644
--- a/src/de/todesbaum/jsite/main/Version.java
+++ b/src/de/todesbaum/jsite/main/Version.java
@@ -20,15 +20,85 @@
package de.todesbaum.jsite.main;
/**
- * @author David Roden
- * @version $Id$
+ * Container for version information.
+ *
+ * @author David âBombeâ Roden <bombe@freenetproject.org>
*/
-public class Version {
+public class Version implements Comparable {
+
+ /** The version. */
+ private static final Version VERSION = new Version(0, 6, 2);
+
+ /** The components of the version information. */
+ private final int[] components;
+
+ /**
+ * Creates a new version container with the given components.
+ *
+ * @param components
+ * The version components
+ */
+ public Version(int... components) {
+ this.components = new int[components.length];
+ System.arraycopy(components, 0, this.components, 0, components.length);
+ }
+
+ /**
+ * Returns the number of version components.
+ *
+ * @return The number of version components
+ */
+ public int size() {
+ return components.length;
+ }
- private static final String VERSION = "0.4.9.6";
+ /**
+ * Returns the version component with the given index.
+ *
+ * @param index
+ * The index of the version component
+ * @return The version component
+ */
+ public int getComponent(int index) {
+ return components[index];
+ }
+ /**
+ * Returns the version.
+ *
+ * @return The version
+ */
public static final String getVersion() {
- return VERSION;
+ return VERSION.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ StringBuilder versionString = new StringBuilder();
+ for (int component : components) {
+ if (versionString.length() != 0) {
+ versionString.append('.');
+ }
+ versionString.append(component);
+ }
+ return versionString.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo(Version version) {
+ int lessComponents = Math.min(components.length, version.components.length);
+ for (int index = 0; index < lessComponents; index++) {
+ if (version.components[index] == components[index]) {
+ continue;
+ }
+ return components[index] - version.components[index];
+ }
+ return components.length - version.components.length;
}
}