1 package net.pterodactylus.util.fcp;
3 import java.util.StringTokenizer;
6 * Container for the “lastGoodVersion” field.
8 * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
11 public class Version {
13 /** The name of the node implementation. */
14 private final String nodeName;
16 /** The tree version of the node. */
17 private final String treeVersion;
19 /** The protocol version of the node. */
20 private final String protocolVersion;
22 /** The build number of the node. */
23 private final int buildNumber;
26 * Creates a new Version from the given string. The string consists of the
27 * four required fields node name, tree version, protocol version, and build
28 * number, separated by a comma.
32 * @throws NullPointerException
33 * if <code>version</code> is <code>null</code>
34 * @throws IllegalArgumentException
35 * if <code>version</code> is not in the right format
37 public Version(String version) {
38 if (version == null) {
39 throw new NullPointerException("version must not be null");
41 StringTokenizer versionTokens = new StringTokenizer(version, ",");
42 if (versionTokens.countTokens() != 4) {
43 throw new IllegalArgumentException("version must consist of four fields");
45 this.nodeName = versionTokens.nextToken();
46 this.treeVersion = versionTokens.nextToken();
47 this.protocolVersion = versionTokens.nextToken();
49 this.buildNumber = Integer.valueOf(versionTokens.nextToken());
50 } catch (NumberFormatException nfe1) {
51 throw new IllegalArgumentException("last part of version must be numeric", nfe1);
56 * Creates a new Version from the given parts.
59 * The name of the node implementation
62 * @param protocolVersion
63 * The protocol version
65 * The build number of the node
67 public Version(String nodeName, String treeVersion, String protocolVersion, int buildNumber) {
68 this.nodeName = nodeName;
69 this.treeVersion = treeVersion;
70 this.protocolVersion = protocolVersion;
71 this.buildNumber = buildNumber;
75 * Returns the name of the node implementation.
77 * @return The node name
79 public String getNodeName() {
84 * The tree version of the node.
86 * @return The tree version of the node
88 public String getTreeVersion() {
93 * The protocol version of the node
95 * @return The protocol version of the node
97 public String getProtocolVersion() {
98 return protocolVersion;
102 * The build number of the node.
104 * @return The build number of the node
106 public int getBuildNumber() {
111 * @see java.lang.Object#toString()
114 public String toString() {
115 return nodeName + "," + treeVersion + "," + protocolVersion + "," + buildNumber;