@Override public boolean equals(Object obj) { if (obj instanceof HostAndPort) { HostAndPort hp = (HostAndPort) obj; String thisHost = convertHost(host); String hpHost = convertHost(hp.host); return port == hp.port && thisHost.equals(hpHost); } return false; }
@Override public int hashCode() { return 31 * convertHost(host).hashCode() + port; }
@Override public boolean equals(Object obj) { if (obj instanceof HostAndPort) { HostAndPort hp = (HostAndPort) obj; String thisHost = convertHost(host); String hpHost = convertHost(hp.host); return port == hp.port && thisHost.equals(hpHost); } return false; }
@Override public int hashCode() { return 31 * convertHost(host).hashCode() + port; }
/** * Creates HostAndPort instance from string. * String must be in ( host + ":" + port ) format. * Port is mandatory. Can convert host part. * @see #convertHost(String) * @param from String to parse * @return HostAndPort instance */ public static HostAndPort parseString(String from){ // NOTE: redis answers with // '99aa9999aa9a99aa099aaa990aa99a09aa9a9999 9a09:9a9:a090:9a::99a slave 8c88888888cc08088cc8c8c888c88c8888c88cc8 0 1468251272993 37 connected' // for CLUSTER NODES, ASK and MOVED scenarios. That's why there is no possibility to parse address in 'correct' way. // Redis should switch to 'bracketized' (RFC 3986) IPv6 address. try { String[] parts = extractParts(from); String host = parts[0]; int port = Integer.parseInt(parts[1]); return new HostAndPort(convertHost(host), port); } catch (NumberFormatException ex) { throw new IllegalArgumentException(ex); } }