1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.net;
19
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.classification.InterfaceStability;
22
23 import com.google.common.net.HostAndPort;
24
25
26
27
28
29
30
31
32
33 @InterfaceAudience.Public
34 @InterfaceStability.Stable
35 public class Address implements Comparable<Address> {
36 private HostAndPort hostAndPort;
37
38 private Address(HostAndPort hostAndPort) {
39 this.hostAndPort = hostAndPort;
40 }
41
42 public static Address fromParts(String hostname, int port) {
43 return new Address(HostAndPort.fromParts(hostname, port));
44 }
45
46 public static Address fromString(String hostnameAndPort) {
47 return new Address(HostAndPort.fromString(hostnameAndPort));
48 }
49
50 public String getHostname() {
51 return this.hostAndPort.getHostText();
52 }
53
54 public int getPort() {
55 return this.hostAndPort.getPort();
56 }
57
58 @Override
59 public String toString() {
60 return this.hostAndPort.toString();
61 }
62
63 @Override
64
65
66 public boolean equals(Object other) {
67 if (this == other) {
68 return true;
69 }
70 if (other instanceof Address) {
71 Address that = (Address)other;
72 return this.getHostname().equals(that.getHostname()) &&
73 this.getPort() == that.getPort();
74 }
75 return false;
76 }
77
78 @Override
79 public int hashCode() {
80 return this.getHostname().hashCode() ^ getPort();
81 }
82
83 @Override
84 public int compareTo(Address that) {
85 int compare = this.getHostname().compareTo(that.getHostname());
86 if (compare != 0) return compare;
87 return this.getPort() - that.getPort();
88 }
89 }