public static void addBars(BarSeries barSeries, List<Bar> newBars) {
        if (newBars != null && !newBars.isEmpty()) {
            sortBars(newBars);
            for (Bar bar : newBars) {
                if (barSeries.isEmpty() || bar.getEndTime().isAfter(barSeries.getLastBar().getEndTime())) {
                    barSeries.addBar(bar);
                }
            }
        }
    }
@Test
    public void addBars() {
        BarSeries barSeries = new BaseBarSeries("1day", numFunction.apply(0));

        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.plusDays(1), 1d, 1d, 1d, 1d, 1d, 1d, 1, numFunction);
        final Bar bar2 = new MockBar(time.plusDays(2), 1d, 1d, 1d, 1d, 1d, 1d, 1, numFunction);
        bars.add(bar2);
        bars.add(bar0);
        bars.add(bar1);

        // add 3 bars to empty barSeries
        BarSeriesUtils.addBars(barSeries, bars);

        assertEquals(bar0.getEndTime(), barSeries.getFirstBar().getEndTime());
        assertEquals(bar2.getEndTime(), barSeries.getLastBar().getEndTime());

        final Bar bar3 = new MockBar(time.plusDays(3), 1d, 1d, 1d, 1d, 1d, 1d, 1, numFunction);
        bars.add(bar3);

        // add 1 bar to non empty barSeries
        BarSeriesUtils.addBars(barSeries, bars);
        assertEquals(bar3.getEndTime(), barSeries.getLastBar().getEndTime());
    }