IntervalMap implements TimeMap<Interval, T> { protected double[] getIntervalsWeight(double intervalStart, double intervalEnd, int[] intervals) { double[] res = new double[intervals.length]; for (int i = 0; i < intervals.length; i++) { double start = array[i * 2]; double end = array[i * 2 + 1]; if (start != end) { start = Math.max(intervalStart, start); end = Math.min(intervalEnd, end); res[i] = end - start; } } return res; } 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 getIntervalsWeight() { IntervalIntegerMap j = new IntervalIntegerMap(); j.put(new Interval(2000, 2002), 42); j.put(new Interval(2003, 2004), 42); j.put(new Interval(2005, 2006), 42); Assert.assertEquals(j.getIntervalsWeight(2000, 2002, j.getOverlappingIntervals(2000, 2002)), new double[] { 2.0 }); Assert.assertEquals(j.getIntervalsWeight(2001, 2002, j.getOverlappingIntervals(2001, 2002)), new double[] { 1.0 }); Assert.assertEquals(j.getIntervalsWeight(2000, 2001, j.getOverlappingIntervals(2000, 2001)), new double[] { 1.0 }); Assert.assertEquals(j.getIntervalsWeight(2000.5, 2001.5, j.getOverlappingIntervals(2000.5, 2001.5)), new double[] { 1.0 }); Assert.assertEquals(j.getIntervalsWeight(1999, 2000, j.getOverlappingIntervals(1999, 2000)), new double[] { 0 }); Assert.assertEquals(j.getIntervalsWeight(1999, 2001, j.getOverlappingIntervals(1999, 2001)), new double[] { 1.0 }); Assert.assertEquals(j.getIntervalsWeight(2000, 2003, j.getOverlappingIntervals(2000, 2003)), new double[] { 2.0, 0 }); Assert.assertEquals(j.getIntervalsWeight(2000, 2004, j.getOverlappingIntervals(2000, 2004)), new double[] { 2.0, 1.0 }); }