rename fcplib to jFCPlib
[jFCPlib.git] / src / net / pterodactylus / fcp / NodeHello.java
1 /*
2  * jSite2 - NodeHello.java -
3  * Copyright © 2008 David Roden
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 package net.pterodactylus.fcp;
21
22 /**
23  * Some convenience methods for parsing a “NodeHello” message from the node.
24  * 
25  * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
26  * @version $Id$
27  */
28 public class NodeHello extends BaseMessage {
29
30         /**
31          * Createa a new “NodeHello” message that wraps the received message.
32          * 
33          * @param receivedMessage
34          *            The received FCP message
35          */
36         NodeHello(FcpMessage receivedMessage) {
37                 super(receivedMessage);
38         }
39
40         /**
41          * Returns the build of the node. This may not be a number but also a string
42          * like “@custom@” in case you built the node yourself.
43          * 
44          * @return The build of the node
45          */
46         public String getBuild() {
47                 return getField("Build");
48         }
49
50         /**
51          * Returns the build number of the node. This may not be a number but also a
52          * string like “@custom@” in case you built the node yourself.
53          * 
54          * @return The build number of the node, or <code>-1</code> if the build
55          *         number could not be determined
56          */
57         public int getBuildNumber() {
58                 return FcpUtils.safeParseInt(getBuild());
59         }
60
61         /**
62          * Returns the number of compression codecs.
63          * 
64          * @return The number of compression codecs
65          */
66         public String getCompressionCodecs() {
67                 return getField("CompressionCodecs");
68         }
69
70         /**
71          * Returns the number of compression codecs.
72          * 
73          * @return The number of compression codecs, or <code>-1</code> if the
74          *         number of compression codecs could not be determined
75          */
76         public int getCompressionCodecsNumber() {
77                 return FcpUtils.safeParseInt(getCompressionCodecs());
78         }
79
80         /**
81          * Returns the unique connection identifier.
82          * 
83          * @return The connection identifier
84          */
85         public String getConnectionIdentifier() {
86                 return getField("ConnectionIdentifier");
87         }
88
89         /**
90          * Returns the build of the external library file.
91          * 
92          * @return The build of the external library file
93          */
94         public String getExtBuild() {
95                 return getField("ExtBuild");
96         }
97
98         /**
99          * Returns the build number of the external library file.
100          * 
101          * @return The build number of the external library file, or <code>-1</code>
102          *         if the build number could not be determined
103          */
104         public int getExtBuildNumber() {
105                 return FcpUtils.safeParseInt(getExtBuild());
106         }
107
108         /**
109          * Returns the revision of the external library file.
110          * 
111          * @return The revision of the external library file
112          */
113         public String getExtRevision() {
114                 return getField("ExtRevision");
115         }
116
117         /**
118          * Returns the revision number of the external library file.
119          * 
120          * @return The revision number of the external library file, or
121          *         <code>-1</code> if the revision number could not be determined
122          */
123         public int getExtRevisionNumber() {
124                 return FcpUtils.safeParseInt(getExtRevision());
125         }
126
127         /**
128          * Returns the FCP version the node speaks.
129          * 
130          * @return The FCP version the node speaks
131          */
132         public String getFCPVersion() {
133                 return getField("FCPVersion");
134         }
135
136         /**
137          * Returns the make of the node, e.g. “Fred” (freenet reference
138          * implementation).
139          * 
140          * @return The make of the node
141          */
142         public String getNode() {
143                 return getField("Node");
144         }
145
146         /**
147          * Returns the language of the node as 2-letter code, e.g. “en” or “de”.
148          * 
149          * @return The language of the node
150          */
151         public String getNodeLanguage() {
152                 return getField("NodeLanguage");
153         }
154
155         /**
156          * Returns the revision of the node.
157          * 
158          * @return The revision of the node
159          */
160         public String getRevision() {
161                 return getField("Revision");
162         }
163
164         /**
165          * Returns the revision number of the node.
166          * 
167          * @return The revision number of the node, or <code>-1</code> if the
168          *         revision number coult not be determined
169          */
170         public int getRevisionNumber() {
171                 return FcpUtils.safeParseInt(getRevision());
172         }
173
174         /**
175          * Returns whether the node is currently is testnet mode.
176          * 
177          * @return <code>true</code> if the node is currently in testnet mode,
178          *         <code>false</code> otherwise
179          */
180         public boolean getTestnet() {
181                 return Boolean.valueOf(getField("Testnet"));
182         }
183
184         /**
185          * Returns the version of the node.
186          * 
187          * @return The version of the node
188          */
189         public String getVersion() {
190                 return getField("Version");
191         }
192
193 }