2 * jFCPlib - Version.java - Copyright © 2008 David Roden
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package net.pterodactylus.fcp;
21 import java.util.StringTokenizer;
24 * Container for the “lastGoodVersion” field.
26 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
28 public class Version {
30 /** The name of the node implementation. */
31 private final String nodeName;
33 /** The tree version of the node. */
34 private final String treeVersion;
36 /** The protocol version of the node. */
37 private final String protocolVersion;
39 /** The build number of the node. */
40 private final int buildNumber;
43 * Creates a new Version from the given string. The string consists of the
44 * four required fields node name, tree version, protocol version, and build
45 * number, separated by a comma.
49 * @throws NullPointerException
50 * if <code>version</code> is <code>null</code>
51 * @throws IllegalArgumentException
52 * if <code>version</code> is not in the right format
54 public Version(String version) {
55 if (version == null) {
56 throw new NullPointerException("version must not be null");
58 StringTokenizer versionTokens = new StringTokenizer(version, ",");
59 if (versionTokens.countTokens() != 4) {
60 throw new IllegalArgumentException("version must consist of four fields");
62 this.nodeName = versionTokens.nextToken();
63 this.treeVersion = versionTokens.nextToken();
64 this.protocolVersion = versionTokens.nextToken();
66 this.buildNumber = Integer.valueOf(versionTokens.nextToken());
67 } catch (NumberFormatException nfe1) {
68 throw new IllegalArgumentException("last part of version must be numeric", nfe1);
73 * Creates a new Version from the given parts.
76 * The name of the node implementation
79 * @param protocolVersion
80 * The protocol version
82 * The build number of the node
84 public Version(String nodeName, String treeVersion, String protocolVersion, int buildNumber) {
85 this.nodeName = nodeName;
86 this.treeVersion = treeVersion;
87 this.protocolVersion = protocolVersion;
88 this.buildNumber = buildNumber;
92 * Returns the name of the node implementation.
94 * @return The node name
96 public String getNodeName() {
101 * The tree version of the node.
103 * @return The tree version of the node
105 public String getTreeVersion() {
110 * The protocol version of the node
112 * @return The protocol version of the node
114 public String getProtocolVersion() {
115 return protocolVersion;
119 * The build number of the node.
121 * @return The build number of the node
123 public int getBuildNumber() {
128 * @see java.lang.Object#toString()
131 public String toString() {
132 return nodeName + "," + treeVersion + "," + protocolVersion + "," + buildNumber;