01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.net.groups;
06:
07: public class Node {
08:
09: private final String host;
10: private final int port;
11: private final int hashCode;
12:
13: public Node(final String host, final int port) {
14: checkArgs(host, port);
15: this .host = host.trim();
16: this .port = port;
17: this .hashCode = (host + "-" + port).hashCode();
18: }
19:
20: public String getHost() {
21: return host;
22: }
23:
24: public int getPort() {
25: return port;
26: }
27:
28: public boolean equals(Object obj) {
29: if (obj instanceof Node) {
30: Node that = (Node) obj;
31: return this .port == that.port
32: && this .host.equals(that.host);
33: }
34: return false;
35: }
36:
37: public int hashCode() {
38: return hashCode;
39: }
40:
41: private static void checkArgs(final String host, final int port)
42: throws IllegalArgumentException {
43: if (host == null || host.trim().length() == 0) {
44: throw new IllegalArgumentException("Invalid host name: "
45: + host);
46: }
47: if (port < 0) {
48: throw new IllegalArgumentException("Invalid port number: "
49: + port);
50: }
51: }
52:
53: public String toString() {
54: return "Node{host=" + host + ":" + port + "}";
55: }
56: }
|