class SampledXYSeries implements FastXYSeries, OrderedXYSeries {

    public void resample() {
        bounds = null;
        zoomLevels = new ArrayList<>();
        int t = (int) Math.ceil(rawData.size() / getRatio());
        List<Thread> threads = new ArrayList<>(zoomLevels.size());
        while (t > threshold) {
            final int thisThreshold = t;
            final EditableXYSeries thisSeries = new FixedSizeEditableXYSeries(getTitle(), thisThreshold);
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        // TODO: make bounds a param to prevent calculating on each setZoomFactor level:
                        RectRegion b = getAlgorithm()
                                .run(rawData, thisSeries);
                        if (bounds == null) {
                            bounds = b;
                        }
                    } catch(Exception ex) {
                        lastResamplingException = ex;
                    }
                }
            }, "Androidplot XY Series Sampler");
            getZoomLevels().add(thisSeries);
            threads.add(thread);
            thread.start();

            t = (int) Math.ceil(t / getRatio());
        }
        for(Thread thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        if(lastResamplingException != null) {
            throw new RuntimeException("Exception encountered during resampling", lastResamplingException);
        }

    }

    public  SampledXYSeries(XYSeries rawData, XOrder xOrder, float ratio, int threshold);
    public  SampledXYSeries(XYSeries rawData, float ratio, int threshold);

}