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>
30 public class Version {
32 /** The name of the node implementation. */
33 private final String nodeName;
35 /** The tree version of the node. */
36 private final String treeVersion;
38 /** The protocol version of the node. */
39 private final String protocolVersion;
41 /** The build number of the node. */
42 private final int buildNumber;
45 * Creates a new Version from the given string. The string consists of the
46 * four required fields node name, tree version, protocol version, and build
47 * number, separated by a comma.
51 * @throws NullPointerException
52 * if <code>version</code> is <code>null</code>
53 * @throws IllegalArgumentException
54 * if <code>version</code> is not in the right format
56 public Version(String version) {
57 if (version == null) {
58 throw new NullPointerException("version must not be null");
60 StringTokenizer versionTokens = new StringTokenizer(version, ",");
61 if (versionTokens.countTokens() != 4) {
62 throw new IllegalArgumentException("version must consist of four fields");
64 this.nodeName = versionTokens.nextToken();
65 this.treeVersion = versionTokens.nextToken();
66 this.protocolVersion = versionTokens.nextToken();
68 this.buildNumber = Integer.valueOf(versionTokens.nextToken());
69 } catch (NumberFormatException nfe1) {
70 throw new IllegalArgumentException("last part of version must be numeric", nfe1);
75 * Creates a new Version from the given parts.
78 * The name of the node implementation
81 * @param protocolVersion
82 * The protocol version
84 * The build number of the node
86 public Version(String nodeName, String treeVersion, String protocolVersion, int buildNumber) {
87 this.nodeName = nodeName;
88 this.treeVersion = treeVersion;
89 this.protocolVersion = protocolVersion;
90 this.buildNumber = buildNumber;
94 * Returns the name of the node implementation.
96 * @return The node name
98 public String getNodeName() {
103 * The tree version of the node.
105 * @return The tree version of the node
107 public String getTreeVersion() {
112 * The protocol version of the node
114 * @return The protocol version of the node
116 public String getProtocolVersion() {
117 return protocolVersion;
121 * The build number of the node.
123 * @return The build number of the node
125 public int getBuildNumber() {
130 * @see java.lang.Object#toString()
133 public String toString() {
134 return nodeName + "," + treeVersion + "," + protocolVersion + "," + buildNumber;