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