public static List<Bar> sortBars(List<Bar> bars) {
        if (!bars.isEmpty()) {
            Collections.sort(bars, BarSeriesUtils.sortBarsByTime);
        }
        return bars;
    }
@Test
    public void sortBars() {
        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);
        final Bar bar3 = new MockBar(time.plusDays(3), 1d, 1d, 1d, 1d, 1d, 1d, 1, numFunction);

        final List<Bar> sortedBars = new ArrayList<>();
        sortedBars.add(bar0);
        sortedBars.add(bar1);
        sortedBars.add(bar2);
        sortedBars.add(bar3);

        BarSeriesUtils.sortBars(sortedBars);
        assertEquals(bar0.getEndTime(), sortedBars.get(0).getEndTime());
        assertEquals(bar1.getEndTime(), sortedBars.get(1).getEndTime());
        assertEquals(bar2.getEndTime(), sortedBars.get(2).getEndTime());
        assertEquals(bar3.getEndTime(), sortedBars.get(3).getEndTime());

        final List<Bar> unsortedBars = new ArrayList<>();
        unsortedBars.add(bar3);
        unsortedBars.add(bar2);
        unsortedBars.add(bar1);
        unsortedBars.add(bar0);

        BarSeriesUtils.sortBars(unsortedBars);
        assertEquals(bar0.getEndTime(), unsortedBars.get(0).getEndTime());
        assertEquals(bar1.getEndTime(), unsortedBars.get(1).getEndTime());
        assertEquals(bar2.getEndTime(), unsortedBars.get(2).getEndTime());
        assertEquals(bar3.getEndTime(), unsortedBars.get(3).getEndTime());

        final List<Bar> unsortedBars2 = new ArrayList<>();
        unsortedBars2.add(bar2);
        unsortedBars2.add(bar1);
        unsortedBars2.add(bar3);
        unsortedBars2.add(bar0);

        BarSeriesUtils.sortBars(unsortedBars2);
        assertEquals(bar0.getEndTime(), unsortedBars2.get(0).getEndTime());
        assertEquals(bar1.getEndTime(), unsortedBars2.get(1).getEndTime());
        assertEquals(bar2.getEndTime(), unsortedBars2.get(2).getEndTime());
        assertEquals(bar3.getEndTime(), unsortedBars2.get(3).getEndTime());

        Collections.shuffle(unsortedBars2);
        BarSeriesUtils.sortBars(unsortedBars2);
        assertEquals(bar0.getEndTime(), unsortedBars2.get(0).getEndTime());
        assertEquals(bar1.getEndTime(), unsortedBars2.get(1).getEndTime());
        assertEquals(bar2.getEndTime(), unsortedBars2.get(2).getEndTime());
        assertEquals(bar3.getEndTime(), unsortedBars2.get(3).getEndTime());
    }