2 * jFCPlib - Version.java - Copyright © 2008–2016 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 3 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, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.fcp;
20 import java.util.StringTokenizer;
23 * Container for the “lastGoodVersion” field.
25 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
27 public class Version {
29 /** The name of the node implementation. */
30 private final String nodeName;
32 /** The tree version of the node. */
33 private final String treeVersion;
35 /** The protocol version of the node. */
36 private final String protocolVersion;
38 /** The build number of the node. */
39 private final int buildNumber;
42 * Creates a new Version from the given string. The string consists of the
43 * four required fields node name, tree version, protocol version, and
44 * build number, separated by a comma.
48 * @throws NullPointerException
49 * if <code>version</code> is <code>null</code>
50 * @throws IllegalArgumentException
51 * if <code>version</code> is not in the right format
53 public Version(String version) {
54 if (version == null) {
55 throw new NullPointerException("version must not be null");
57 StringTokenizer versionTokens = new StringTokenizer(version, ",");
58 if (versionTokens.countTokens() != 4) {
59 throw new IllegalArgumentException("version must consist of four fields");
61 this.nodeName = versionTokens.nextToken();
62 this.treeVersion = versionTokens.nextToken();
63 this.protocolVersion = versionTokens.nextToken();
65 this.buildNumber = Integer.valueOf(versionTokens.nextToken());
66 } catch (NumberFormatException nfe1) {
67 throw new IllegalArgumentException("last part of version must be numeric", nfe1);
72 * Creates a new Version from the given parts.
75 * The name of the node implementation
78 * @param protocolVersion
79 * The protocol version
81 * The build number of the node
83 public Version(String nodeName, String treeVersion, String protocolVersion, int buildNumber) {
84 this.nodeName = nodeName;
85 this.treeVersion = treeVersion;
86 this.protocolVersion = protocolVersion;
87 this.buildNumber = buildNumber;
91 * Returns the name of the node implementation.
93 * @return The node name
95 public String getNodeName() {
100 * The tree version of the node.
102 * @return The tree version of the node
104 public String getTreeVersion() {
109 * The protocol version of the node
111 * @return The protocol version of the node
113 public String getProtocolVersion() {
114 return protocolVersion;
118 * The build number of the node.
120 * @return The build number of the node
122 public int getBuildNumber() {
127 * @see java.lang.Object#toString()
130 public String toString() {
131 return nodeName + "," + treeVersion + "," + protocolVersion + "," + buildNumber;