IntervalMap implements TimeMap<Interval, T> { @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final IntervalMap<?> other = (IntervalMap<?>) obj; if (this.size != other.size) { return false; } int realSize = size * 2; for (int i = 0; i < realSize; i++) { double i1 = this.array[i]; double i2 = other.array[i]; if (i1 != i2) { return false; } if (i % 2 == 0) { Object o1 = this.getValue(i / 2); Object o2 = other.getValue(i / 2); if ((o1 == null && o2 != null) || (o1 != null && o2 == null) || (o1 != null && o2 != null && !o1 .equals(o2))) { return false; } } } return true; } IntervalMap();  IntervalMap(int capacity); protected  IntervalMap(double[] keys); @Override boolean put(Interval interval, T value); @Override boolean remove(Interval interval); @Override Object get(Interval interval, Estimator estimator); @Override T get(Interval interval, T defaultValue); @Override T[] toValuesArray(); @Override int size(); @Override boolean isEmpty(); boolean contains(double timestamp); @Override boolean contains(Interval interval); @Override Interval[] toKeysArray(); double[] getIntervals(); @Override void clear(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(TimeFormat timeFormat, DateTimeZone timeZone); @Override String toString(TimeFormat timeFormat); @Override String toString();  }
@Test public void testEquals() { Interval[] indices = new Interval[] { new Interval(1.0, 2.0), new Interval(3.0, 4.0), new Interval(2.0, 2.0), new Interval( 2.0, 3.0) }; String[] values = new String[] { "a", "z", "e" }; IntervalStringMap set1 = new IntervalStringMap(); IntervalStringMap set2 = new IntervalStringMap(); IntervalStringMap set3 = new IntervalStringMap(); IntervalStringMap set4 = new IntervalStringMap(); IntervalStringMap set5 = new IntervalStringMap(); set1.put(indices[0], values[0]); set1.put(indices[1], values[1]); set1.put(indices[2], values[2]); set2.put(indices[2], values[2]); set2.put(indices[1], values[1]); set2.put(indices[0], values[0]); set3.put(indices[0], "f"); set3.put(indices[1], "o"); set3.put(indices[2], "o"); Assert.assertTrue(set1.equals(set2)); Assert.assertTrue(set2.equals(set1)); Assert.assertFalse(set1.equals(set3)); Assert.assertFalse(set1.equals(set4)); Assert.assertFalse(set1.equals(set5)); Assert.assertTrue(set1.hashCode() == set2.hashCode()); Assert.assertFalse(set1.hashCode() == set3.hashCode()); Assert.assertFalse(set1.hashCode() == set4.hashCode()); }