ChartSampleSearch { static public int findSampleGreaterOrEqual(ChartSampleSequence samples, double x) { synchronized (samples) { ChartSampleSearch binary = new ChartSampleSearch(); if (binary.search(samples, x)) return binary.mid; if (binary.cmp > 0) return binary.mid; if (binary.mid < samples.size()-2) return binary.mid+1; return -1; } }  static int findSampleLessOrEqual(ChartSampleSequence samples, double x); static int findSampleGreaterOrEqual(ChartSampleSequence samples, double x); static int findClosestSample(ChartSampleSequence samples, double x);  }
@Test public void testFindSampleGreaterOrEqual() throws Exception { double x; int i; x = 4.0; i = ChartSampleSearch.findSampleGreaterOrEqual(samples, x); assertTrue(i >= 0); assertTrue(i < samples.size()); assertTrue(samples.get(i).getX() == x); x = 5.0; i = ChartSampleSearch.findSampleGreaterOrEqual(samples, x); assertTrue(i >= 0); assertTrue(i < samples.size()); assertTrue(samples.get(i).getX() > x); x = 2.0; i = ChartSampleSearch.findSampleGreaterOrEqual(samples, x); assertTrue(i >= 0); assertTrue(i < samples.size()); assertTrue(samples.get(i).getX() == x); x = 18.0; i = ChartSampleSearch.findSampleGreaterOrEqual(samples, x); assertTrue(i >= 0); assertTrue(i < samples.size()); assertTrue(samples.get(i).getX() == x); x = 1.0; i = ChartSampleSearch.findSampleGreaterOrEqual(samples, x); assertTrue(i >= 0); assertTrue(i < samples.size()); assertTrue(samples.get(i).getX() > x); x = 20.0; i = ChartSampleSearch.findSampleGreaterOrEqual(samples, x); assertEquals(-1, i); }