MetricDescriptor extends AbstractRegisteredItem { @Override public int hashCode() { return super.hashCode() + Objects.hash(label, function, unitLabel); } MetricDescriptor(String theId, String theLabel, Function<? extends Object, ? extends Object> theFunction, String aUnitLabel, String theDescription); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); final String label; final Function<? extends Object, ? extends Object> function; final String unitLabel; }
@Test public void hashCodeTest() { MetricDescriptor md1 = new MetricDescriptor("beatFrequency", "Beat frequency", null, "Hz", "The interference resulting from the union of two signals"); MetricDescriptor md2 = new MetricDescriptor("beatFrequency", "Beat frequency", null, "Hz", "The interference resulting from the union of two signals"); assertEquals(md1.hashCode(), md2.hashCode()); md2 = new MetricDescriptor("beatFrequency", "Beat Frequency", null, "Hz", "The interference resulting from the union of two signals"); assertNotSame(md1.hashCode(), md2.hashCode()); }