@Test public void aggregateTimeInterval3() { Instant time = Instant.now(); TimeInterval interval1 = TimeInterval.before(Duration.ofSeconds(1), time); TimeInterval interval2 = TimeInterval.after(Duration.ofSeconds(1), time.plus(Duration.ofSeconds(1))); TimeInterval total = TimeInterval.between(interval1.getStart(), interval2.getEnd()); assertThat(TemporalGraph2DRenderer.aggregateTimeInterval(interval1, interval2), equalTo(total)); assertThat(TemporalGraph2DRenderer.aggregateTimeInterval(interval2, interval1), equalTo(total)); }
static TimeInterval aggregateTimeInterval(TimeInterval dataTimeInterval, TimeInterval aggregatedTimeInterval) { if (aggregatedTimeInterval == null) { return dataTimeInterval; } else { if (aggregatedTimeInterval.contains(dataTimeInterval.getEnd()) && aggregatedTimeInterval.contains(dataTimeInterval.getStart())) { return aggregatedTimeInterval; } if (dataTimeInterval.contains(aggregatedTimeInterval.getEnd()) && dataTimeInterval.contains(aggregatedTimeInterval.getStart())) { return dataTimeInterval; } Instant start; Instant end; if (dataTimeInterval.getStart().compareTo(aggregatedTimeInterval.getStart()) > 0) { start = aggregatedTimeInterval.getStart(); } else { start = dataTimeInterval.getStart(); } if (dataTimeInterval.getEnd().compareTo(aggregatedTimeInterval.getEnd()) < 0) { end = aggregatedTimeInterval.getEnd(); } else { end = dataTimeInterval.getEnd(); } return TimeInterval.between(start, end); } }
TemporalGraph2DRenderer { static TimeInterval aggregateTimeInterval(TimeInterval dataTimeInterval, TimeInterval aggregatedTimeInterval) { if (aggregatedTimeInterval == null) { return dataTimeInterval; } else { if (aggregatedTimeInterval.contains(dataTimeInterval.getEnd()) && aggregatedTimeInterval.contains(dataTimeInterval.getStart())) { return aggregatedTimeInterval; } if (dataTimeInterval.contains(aggregatedTimeInterval.getEnd()) && dataTimeInterval.contains(aggregatedTimeInterval.getStart())) { return dataTimeInterval; } Instant start; Instant end; if (dataTimeInterval.getStart().compareTo(aggregatedTimeInterval.getStart()) > 0) { start = aggregatedTimeInterval.getStart(); } else { start = dataTimeInterval.getStart(); } if (dataTimeInterval.getEnd().compareTo(aggregatedTimeInterval.getEnd()) < 0) { end = aggregatedTimeInterval.getEnd(); } else { end = dataTimeInterval.getEnd(); } return TimeInterval.between(start, end); } } }
TemporalGraph2DRenderer { static TimeInterval aggregateTimeInterval(TimeInterval dataTimeInterval, TimeInterval aggregatedTimeInterval) { if (aggregatedTimeInterval == null) { return dataTimeInterval; } else { if (aggregatedTimeInterval.contains(dataTimeInterval.getEnd()) && aggregatedTimeInterval.contains(dataTimeInterval.getStart())) { return aggregatedTimeInterval; } if (dataTimeInterval.contains(aggregatedTimeInterval.getEnd()) && dataTimeInterval.contains(aggregatedTimeInterval.getStart())) { return dataTimeInterval; } Instant start; Instant end; if (dataTimeInterval.getStart().compareTo(aggregatedTimeInterval.getStart()) > 0) { start = aggregatedTimeInterval.getStart(); } else { start = dataTimeInterval.getStart(); } if (dataTimeInterval.getEnd().compareTo(aggregatedTimeInterval.getEnd()) < 0) { end = aggregatedTimeInterval.getEnd(); } else { end = dataTimeInterval.getEnd(); } return TimeInterval.between(start, end); } } TemporalGraph2DRenderer(int graphWidth, int graphHeight); }
TemporalGraph2DRenderer { static TimeInterval aggregateTimeInterval(TimeInterval dataTimeInterval, TimeInterval aggregatedTimeInterval) { if (aggregatedTimeInterval == null) { return dataTimeInterval; } else { if (aggregatedTimeInterval.contains(dataTimeInterval.getEnd()) && aggregatedTimeInterval.contains(dataTimeInterval.getStart())) { return aggregatedTimeInterval; } if (dataTimeInterval.contains(aggregatedTimeInterval.getEnd()) && dataTimeInterval.contains(aggregatedTimeInterval.getStart())) { return dataTimeInterval; } Instant start; Instant end; if (dataTimeInterval.getStart().compareTo(aggregatedTimeInterval.getStart()) > 0) { start = aggregatedTimeInterval.getStart(); } else { start = dataTimeInterval.getStart(); } if (dataTimeInterval.getEnd().compareTo(aggregatedTimeInterval.getEnd()) < 0) { end = aggregatedTimeInterval.getEnd(); } else { end = dataTimeInterval.getEnd(); } return TimeInterval.between(start, end); } } TemporalGraph2DRenderer(int graphWidth, int graphHeight); int getImageHeight(); int getImageWidth(); AxisRange getAxisRange(); TimeAxisRange getTimeAxisRange(); Range getAggregatedRange(); TimeInterval getAggregatedTimeInterval(); Range getPlotRange(); TimeInterval getPlotTimeInterval(); void update(T update); abstract T newUpdate(); }
TemporalGraph2DRenderer { static TimeInterval aggregateTimeInterval(TimeInterval dataTimeInterval, TimeInterval aggregatedTimeInterval) { if (aggregatedTimeInterval == null) { return dataTimeInterval; } else { if (aggregatedTimeInterval.contains(dataTimeInterval.getEnd()) && aggregatedTimeInterval.contains(dataTimeInterval.getStart())) { return aggregatedTimeInterval; } if (dataTimeInterval.contains(aggregatedTimeInterval.getEnd()) && dataTimeInterval.contains(aggregatedTimeInterval.getStart())) { return dataTimeInterval; } Instant start; Instant end; if (dataTimeInterval.getStart().compareTo(aggregatedTimeInterval.getStart()) > 0) { start = aggregatedTimeInterval.getStart(); } else { start = dataTimeInterval.getStart(); } if (dataTimeInterval.getEnd().compareTo(aggregatedTimeInterval.getEnd()) < 0) { end = aggregatedTimeInterval.getEnd(); } else { end = dataTimeInterval.getEnd(); } return TimeInterval.between(start, end); } } TemporalGraph2DRenderer(int graphWidth, int graphHeight); int getImageHeight(); int getImageWidth(); AxisRange getAxisRange(); TimeAxisRange getTimeAxisRange(); Range getAggregatedRange(); TimeInterval getAggregatedTimeInterval(); Range getPlotRange(); TimeInterval getPlotTimeInterval(); void update(T update); abstract T newUpdate();  }