public static List<Bar> findOverlappingBars(BarSeries barSeries) {
        List<Bar> bars = barSeries.getBarData();
        if (bars == null || bars.isEmpty())
            return new ArrayList<>();
        Duration period = bars.iterator().next().getTimePeriod();
        List<Bar> overlappingBars = new ArrayList<>();
        for (int i = 0; i < bars.size(); i++) {
            Bar bar = bars.get(i);
            Bar nextBar = i + 1 < bars.size() ? bars.get(i + 1) : null;
            if (nextBar != null) {
                if (bar.getEndTime().isAfter(nextBar.getBeginTime())
                        || bar.getBeginTime().plus(period).isBefore(nextBar.getBeginTime())) {
                    overlappingBars.add(nextBar);
                }
            }
        }
        return overlappingBars;
    }
@Test
    public void findOverlappingBarsTest() {

        final List<Bar> bars = new ArrayList<>();
        time = ZonedDateTime.of(2019, 6, 1, 1, 1, 0, 0, ZoneId.systemDefault());

        final Bar bar0 = new MockBar(time, 1d, 2d, 3d, 4d, 5d, 0d, 7, numFunction);
        final Bar bar1 = new MockBar(time, 1d, 1d, 1d, 1d, 1d, 1d, 1, numFunction);
        Bar bar8 = BaseBar.builder(DoubleNum::valueOf, Double.class)
                .timePeriod(Duration.ofDays(1))
                .endTime(time.plusDays(8))
                .openPrice(NaN.NaN)
                .highPrice(NaN.NaN)
                .lowPrice(NaN.NaN)
                .closePrice(NaN.NaN)
                .volume(NaN.NaN)
                .build();

        bars.add(bar0);
        bars.add(bar1);
        bars.add(bar8);

        series = new BaseBarSeriesBuilder().withNumTypeOf(numFunction).withName("Series Name").withBars(bars).build();
        List<Bar> overlappingBars = BarSeriesUtils.findOverlappingBars(series);

        // there must be 1 overlapping bars (bar1)
        assertEquals(overlappingBars.get(0).getBeginTime(), bar1.getBeginTime());
    }