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 { 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); } } SampledXYSeries(XYSeries rawData, XOrder xOrder, float ratio, int threshold);  SampledXYSeries(XYSeries rawData, float ratio, int threshold); void resample(); void setZoomFactor(double factor); double getMaxZoomFactor(); Sampler getAlgorithm(); void setAlgorithm(Sampler algorithm); @Override String getTitle(); @Override int size(); @Override Number getX(int index); @Override Number getY(int index); int getThreshold(); void setThreshold(int threshold); RectRegion getBounds(); void setBounds(RectRegion bounds); @Override RectRegion minMax(); @Override XOrder getXOrder(); float getRatio(); void setRatio(float ratio);  }
@Test public void testResample() { XYSeries rawData = TestUtils.generateXYSeries("my series", 10000); SampledXYSeries sampledXYSeries = new SampledXYSeries(rawData, 2, 200); assertEquals(5, sampledXYSeries.getZoomLevels().size()); }