Statistics implements Serializable { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Statistics other = (Statistics) obj; if (application == null) { if (other.application != null) return false; } else if (!application.equals(other.application)) return false; if (client == null) { if (other.client != null) return false; } else if (!client.equals(other.client)) return false; if (group == null) { if (other.group != null) return false; } else if (!group.equals(other.group)) return false; if (method == null) { if (other.method != null) return false; } else if (!method.equals(other.method)) return false; if (server == null) { if (other.server != null) return false; } else if (!server.equals(other.server)) return false; if (service == null) { if (other.service != null) return false; } else if (!service.equals(other.service)) return false; if (version == null) { if (other.version != null) return false; } else if (!version.equals(other.version)) return false; return true; } Statistics(URL url); URL getUrl(); void setUrl(URL url); String getApplication(); Statistics setApplication(String application); String getService(); Statistics setService(String service); String getGroup(); void setGroup(String group); String getVersion(); void setVersion(String version); String getMethod(); Statistics setMethod(String method); String getClient(); Statistics setClient(String client); String getServer(); Statistics setServer(String server); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testEquals() { URL statistics = new URL("dubbo", "10.20.153.10", 0) .addParameter(MonitorService.APPLICATION, "morgan") .addParameter(MonitorService.INTERFACE, "MemberService") .addParameter(MonitorService.METHOD, "findPerson") .addParameter(MonitorService.CONSUMER, "10.20.153.11") .addParameter(MonitorService.SUCCESS, 1) .addParameter(MonitorService.FAILURE, 0) .addParameter(MonitorService.ELAPSED, 3) .addParameter(MonitorService.MAX_ELAPSED, 3) .addParameter(MonitorService.CONCURRENT, 1) .addParameter(MonitorService.MAX_CONCURRENT, 1); Statistics statistics1 = new Statistics(statistics); Statistics statistics2 = new Statistics(statistics); Assert.assertThat(statistics1, equalTo(statistics1)); Assert.assertThat(statistics1, equalTo(statistics2)); statistics1.setVersion("2"); Assert.assertThat(statistics1, not(equalTo(statistics2))); Assert.assertThat(statistics1.hashCode(), not(equalTo(statistics2.hashCode()))); statistics1.setMethod("anotherMethod"); Assert.assertThat(statistics1, not(equalTo(statistics2))); Assert.assertThat(statistics1.hashCode(), not(equalTo(statistics2.hashCode()))); statistics1.setClient("anotherClient"); Assert.assertThat(statistics1, not(equalTo(statistics2))); Assert.assertThat(statistics1.hashCode(), not(equalTo(statistics2.hashCode()))); }