2 * jSite2 - Version.java -
3 * Copyright © 2008 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 net.pterodactylus.fcp;
22 import java.util.StringTokenizer;
25 * Container for the “lastGoodVersion” field.
27 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
29 public class Version {
31 /** The name of the node implementation. */
32 private final String nodeName;
34 /** The tree version of the node. */
35 private final String treeVersion;
37 /** The protocol version of the node. */
38 private final String protocolVersion;
40 /** The build number of the node. */
41 private final int buildNumber;
44 * Creates a new Version from the given string. The string consists of the
45 * four required fields node name, tree version, protocol version, and build
46 * number, separated by a comma.
50 * @throws NullPointerException
51 * if <code>version</code> is <code>null</code>
52 * @throws IllegalArgumentException
53 * if <code>version</code> is not in the right format
55 public Version(String version) {
56 if (version == null) {
57 throw new NullPointerException("version must not be null");
59 StringTokenizer versionTokens = new StringTokenizer(version, ",");
60 if (versionTokens.countTokens() != 4) {
61 throw new IllegalArgumentException("version must consist of four fields");
63 this.nodeName = versionTokens.nextToken();
64 this.treeVersion = versionTokens.nextToken();
65 this.protocolVersion = versionTokens.nextToken();
67 this.buildNumber = Integer.valueOf(versionTokens.nextToken());
68 } catch (NumberFormatException nfe1) {
69 throw new IllegalArgumentException("last part of version must be numeric", nfe1);
74 * Creates a new Version from the given parts.
77 * The name of the node implementation
80 * @param protocolVersion
81 * The protocol version
83 * The build number of the node
85 public Version(String nodeName, String treeVersion, String protocolVersion, int buildNumber) {
86 this.nodeName = nodeName;
87 this.treeVersion = treeVersion;
88 this.protocolVersion = protocolVersion;
89 this.buildNumber = buildNumber;
93 * Returns the name of the node implementation.
95 * @return The node name
97 public String getNodeName() {
102 * The tree version of the node.
104 * @return The tree version of the node
106 public String getTreeVersion() {
111 * The protocol version of the node
113 * @return The protocol version of the node
115 public String getProtocolVersion() {
116 return protocolVersion;
120 * The build number of the node.
122 * @return The build number of the node
124 public int getBuildNumber() {
129 * @see java.lang.Object#toString()
132 public String toString() {
133 return nodeName + "," + treeVersion + "," + protocolVersion + "," + buildNumber;