4347d302deec1b90efa7c2a51e3b9a4b7d04024a
[jSite.git] / src / main / java / de / todesbaum / util / freenet / fcp2 / Node.java
1 /*
2  * jSite - Node.java - Copyright © 2006–2012 David Roden
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 package de.todesbaum.util.freenet.fcp2;
20
21 /**
22  * Contains the hostname and port number of the Freenet node.
23  *
24  * @author David Roden <droden@gmail.com>
25  * @version $Id$
26  */
27 public class Node {
28
29         /** The default port of FCPv2. */
30         public static final int DEFAULT_PORT = 9481;
31
32         /** The hostname of the node. */
33         protected String hostname;
34
35         /** The port number of the node. */
36         protected int port;
37
38         /**
39          * Creates a new node with the specified hostname and the default port
40          * number.
41          *
42          * @param hostname
43          *            The hostname of the node
44          * @see #DEFAULT_PORT
45          */
46         public Node(String hostname) {
47                 this(hostname, DEFAULT_PORT);
48         }
49
50         /**
51          * Creates a new node with the specified hostname and port number.
52          *
53          * @param hostname
54          *            The hostname of the node
55          * @param port
56          *            The port number of the node
57          */
58         public Node(String hostname, int port) {
59                 this.hostname = hostname;
60                 this.port = port;
61         }
62
63         /**
64          * Returns the hostname of the node.
65          *
66          * @return The hostname of the node
67          */
68         public String getHostname() {
69                 return hostname;
70         }
71
72         /**
73          * Returns the port number of the node.
74          *
75          * @return The port number of the node
76          */
77         public int getPort() {
78                 return port;
79         }
80
81         //
82         // OBJECT METHODS
83         //
84
85         /**
86          * {@inheritDoc}
87          */
88         @Override
89         public String toString() {
90                 return String.format("%s:%d", getHostname(), getPort());
91         }
92
93 }