@Test public void testHashCode() throws Exception { ProviderInfo p1 = new ProviderInfo(); ProviderInfo p2 = new ProviderInfo(); p1.setHost("127.0.0.1"); Assert.assertFalse(p1.hashCode() == p2.hashCode()); p2.setHost("127.0.0.2"); Assert.assertFalse(p1.hashCode() == p2.hashCode()); p2.setHost("127.0.0.1"); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p1.setPort(12200); Assert.assertFalse(p1.hashCode() == p2.hashCode()); p2.setPort(12201); Assert.assertFalse(p1.hashCode() == p2.hashCode()); p2.setPort(12200); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p1.setRpcVersion(4420); Assert.assertFalse(p1.hashCode() == p2.hashCode()); p2.setRpcVersion(4421); Assert.assertFalse(p1.hashCode() == p2.hashCode()); p2.setRpcVersion(4420); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p1.setProtocolType("p1"); Assert.assertFalse(p1.hashCode() == p2.hashCode()); p2.setProtocolType("p2"); Assert.assertFalse(p1.hashCode() == p2.hashCode()); p2.setProtocolType("p1"); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p1.setSerializationType("zzz"); Assert.assertFalse(p1.hashCode() == p2.hashCode()); p2.setSerializationType("yyy"); Assert.assertFalse(p1.hashCode() == p2.hashCode()); p2.setSerializationType("zzz"); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p1.setPath("/aaa"); Assert.assertFalse(p1.hashCode() == p2.hashCode()); p2.setPath("/bbb"); Assert.assertFalse(p1.hashCode() == p2.hashCode()); p2.setPath("/aaa"); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p1.setWeight(200); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p2.setWeight(300); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p2.setWeight(200); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p1.setDynamicAttr("x1", "y1"); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p2.setDynamicAttr("x1", "y1"); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p2.setDynamicAttr("x2", "y2"); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p1.setStaticAttr("x1", "y1"); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p2.setStaticAttr("x1", "y1"); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p1.setStaticAttr("x2", "y2"); Assert.assertTrue(p1.hashCode() == p2.hashCode()); p2.setStaticAttr("x2", "y2"); Assert.assertTrue(p1.hashCode() == p2.hashCode()); List<ProviderInfo> ps = new ArrayList<ProviderInfo>(); ps.add(p1); ps.remove(p2); Assert.assertEquals(ps.size(), 0); Set<ProviderInfo> set = new HashSet<ProviderInfo>(); set.add(p1); set.add(p2); Assert.assertEquals(set.size(), 1); set.remove(p2); Assert.assertEquals(set.size(), 0); Map<ProviderInfo, String> map = new HashMap<ProviderInfo, String>(); map.put(p1, "xx"); map.put(p2, "yy"); Assert.assertEquals(map.get(p1), "yy"); map.remove(p2); Assert.assertEquals(map.size(), 0); }
@Override public int hashCode() { int result = (protocolType != null ? protocolType.hashCode() : 0); result = 31 * result + (host != null ? host.hashCode() : 0); result = 31 * result + port; result = 31 * result + (path != null ? path.hashCode() : 0); result = 31 * result + (serializationType != null ? serializationType.hashCode() : 0); result = 31 * result + rpcVersion; return result; }
ProviderInfo implements Serializable { @Override public int hashCode() { int result = (protocolType != null ? protocolType.hashCode() : 0); result = 31 * result + (host != null ? host.hashCode() : 0); result = 31 * result + port; result = 31 * result + (path != null ? path.hashCode() : 0); result = 31 * result + (serializationType != null ? serializationType.hashCode() : 0); result = 31 * result + rpcVersion; return result; } }
ProviderInfo implements Serializable { @Override public int hashCode() { int result = (protocolType != null ? protocolType.hashCode() : 0); result = 31 * result + (host != null ? host.hashCode() : 0); result = 31 * result + port; result = 31 * result + (path != null ? path.hashCode() : 0); result = 31 * result + (serializationType != null ? serializationType.hashCode() : 0); result = 31 * result + rpcVersion; return result; } ProviderInfo();  ProviderInfo(String host, int port);  ProviderInfo(String host, int port, String originUrl); }
ProviderInfo implements Serializable { @Override public int hashCode() { int result = (protocolType != null ? protocolType.hashCode() : 0); result = 31 * result + (host != null ? host.hashCode() : 0); result = 31 * result + port; result = 31 * result + (path != null ? path.hashCode() : 0); result = 31 * result + (serializationType != null ? serializationType.hashCode() : 0); result = 31 * result + rpcVersion; return result; } ProviderInfo();  ProviderInfo(String host, int port);  ProviderInfo(String host, int port, String originUrl); @Deprecated static ProviderInfo valueOf(String url); @Deprecated String toUrl(); @Override boolean equals(Object o); @Override int hashCode(); String getOriginUrl(); ProviderInfo setOriginUrl(String originUrl); String getProtocolType(); ProviderInfo setProtocolType(String protocolType); String getHost(); ProviderInfo setHost(String host); int getPort(); ProviderInfo setPort(int port); String getPath(); ProviderInfo setPath(String path); String getSerializationType(); ProviderInfo setSerializationType(String serializationType); int getWeight(); ProviderInfo setWeight(int weight); int getRpcVersion(); ProviderInfo setRpcVersion(int rpcVersion); ProviderStatus getStatus(); ProviderInfo setStatus(ProviderStatus status); ConcurrentMap<String, String> getStaticAttrs(); ProviderInfo setStaticAttrs(Map<String, String> staticAttrs); ConcurrentMap<String, Object> getDynamicAttrs(); ProviderInfo setDynamicAttrs(Map<String, Object> dynamicAttrs); String getStaticAttr(String staticAttrKey); ProviderInfo setStaticAttr(String staticAttrKey, String staticAttrValue); Object getDynamicAttr(String dynamicAttrKey); ProviderInfo setDynamicAttr(String dynamicAttrKey, Object dynamicAttrValue); @Override String toString(); String getAttr(String key); }
ProviderInfo implements Serializable { @Override public int hashCode() { int result = (protocolType != null ? protocolType.hashCode() : 0); result = 31 * result + (host != null ? host.hashCode() : 0); result = 31 * result + port; result = 31 * result + (path != null ? path.hashCode() : 0); result = 31 * result + (serializationType != null ? serializationType.hashCode() : 0); result = 31 * result + rpcVersion; return result; } ProviderInfo();  ProviderInfo(String host, int port);  ProviderInfo(String host, int port, String originUrl); @Deprecated static ProviderInfo valueOf(String url); @Deprecated String toUrl(); @Override boolean equals(Object o); @Override int hashCode(); String getOriginUrl(); ProviderInfo setOriginUrl(String originUrl); String getProtocolType(); ProviderInfo setProtocolType(String protocolType); String getHost(); ProviderInfo setHost(String host); int getPort(); ProviderInfo setPort(int port); String getPath(); ProviderInfo setPath(String path); String getSerializationType(); ProviderInfo setSerializationType(String serializationType); int getWeight(); ProviderInfo setWeight(int weight); int getRpcVersion(); ProviderInfo setRpcVersion(int rpcVersion); ProviderStatus getStatus(); ProviderInfo setStatus(ProviderStatus status); ConcurrentMap<String, String> getStaticAttrs(); ProviderInfo setStaticAttrs(Map<String, String> staticAttrs); ConcurrentMap<String, Object> getDynamicAttrs(); ProviderInfo setDynamicAttrs(Map<String, Object> dynamicAttrs); String getStaticAttr(String staticAttrKey); ProviderInfo setStaticAttr(String staticAttrKey, String staticAttrValue); Object getDynamicAttr(String dynamicAttrKey); ProviderInfo setDynamicAttr(String dynamicAttrKey, Object dynamicAttrValue); @Override String toString(); String getAttr(String key);  }