@Test public void testFindLiveItemsUpperBound_Descending() { DefaultXYDataset d = new DefaultXYDataset() { @Override public DomainOrder getDomainOrder() { return DomainOrder.DESCENDING; } }; d.addSeries("S1", new double[][] {{}, {}}); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 0, 10.0, 11.0)); d.addSeries("S2", new double[][] {{1.0}, {9.9}}); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 1, 0.0, 1.0)); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 1, 1.1, 2.0)); d.addSeries("S3", new double[][] {{2.0, 1.0}, {9.9, 9.9}}); assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 2, 0.1, 0.5)); assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 2, 0.1, 1.0)); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 2, 1.1, 2.0)); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 2, 2.2, 3.0)); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 2, 3.3, 4.0)); d.addSeries("S4", new double[][] {{3.0, 2.0, 1.0}, {9.9, 9.9, 9.9}}); assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 3, 0.0, 1.0)); assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 3, 1.0, 2.0)); assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 3, 2.0, 3.0)); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 3, 3.0, 4.0)); d.addSeries("S5", new double[][] {{4.0, 3.0, 2.0, 1.0}, {9.9, 9.9, 9.9, 9.9}}); assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.1, 0.5)); assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.1, 1.0)); assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 4, 1.1, 2.0)); assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 4, 2.2, 3.0)); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 4, 3.3, 4.0)); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 4, 4.4, 5.0)); d.addSeries("S6", new double[][] {{3.0, 2.0, 2.0, 2.0, 1.0}, {9.9, 9.9, 9.9, 9.9, 9.9}}); assertEquals(4, RendererUtilities.findLiveItemsUpperBound(d, 5, 0.0, 5.0)); assertEquals(4, RendererUtilities.findLiveItemsUpperBound(d, 5, 1.0, 5.0)); assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 5, 2.0, 5.0)); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 5, 3.0, 5.0)); }
public static int findLiveItemsUpperBound(XYDataset dataset, int series, double xLow, double xHigh) { if (dataset == null) { throw new IllegalArgumentException("Null 'dataset' argument."); } if (xLow >= xHigh) { throw new IllegalArgumentException("Requires xLow < xHigh."); } int itemCount = dataset.getItemCount(series); if (itemCount <= 1) { return 0; } if (dataset.getDomainOrder() == DomainOrder.ASCENDING) { int low = 0; int high = itemCount - 1; double lowValue = dataset.getXValue(series, low); if (lowValue > xHigh) { return low; } double highValue = dataset.getXValue(series, high); if (highValue <= xHigh) { return high; } int mid = (low + high) / 2; while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (midV <= xHigh) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return mid; } else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) { int low = 0; int high = itemCount - 1; int mid = (low + high) / 2; double lowValue = dataset.getXValue(series, low); if (lowValue < xLow) { return low; } double highValue = dataset.getXValue(series, high); if (highValue >= xLow) { return high; } while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (midV >= xLow) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return mid; } else { int index = itemCount - 1; double x = dataset.getXValue(series, index); while (index >= 0 && x > xHigh) { index--; if (index >= 0) { x = dataset.getXValue(series, index); } } return Math.max(index, 0); } }
RendererUtilities { public static int findLiveItemsUpperBound(XYDataset dataset, int series, double xLow, double xHigh) { if (dataset == null) { throw new IllegalArgumentException("Null 'dataset' argument."); } if (xLow >= xHigh) { throw new IllegalArgumentException("Requires xLow < xHigh."); } int itemCount = dataset.getItemCount(series); if (itemCount <= 1) { return 0; } if (dataset.getDomainOrder() == DomainOrder.ASCENDING) { int low = 0; int high = itemCount - 1; double lowValue = dataset.getXValue(series, low); if (lowValue > xHigh) { return low; } double highValue = dataset.getXValue(series, high); if (highValue <= xHigh) { return high; } int mid = (low + high) / 2; while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (midV <= xHigh) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return mid; } else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) { int low = 0; int high = itemCount - 1; int mid = (low + high) / 2; double lowValue = dataset.getXValue(series, low); if (lowValue < xLow) { return low; } double highValue = dataset.getXValue(series, high); if (highValue >= xLow) { return high; } while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (midV >= xLow) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return mid; } else { int index = itemCount - 1; double x = dataset.getXValue(series, index); while (index >= 0 && x > xHigh) { index--; if (index >= 0) { x = dataset.getXValue(series, index); } } return Math.max(index, 0); } } }
RendererUtilities { public static int findLiveItemsUpperBound(XYDataset dataset, int series, double xLow, double xHigh) { if (dataset == null) { throw new IllegalArgumentException("Null 'dataset' argument."); } if (xLow >= xHigh) { throw new IllegalArgumentException("Requires xLow < xHigh."); } int itemCount = dataset.getItemCount(series); if (itemCount <= 1) { return 0; } if (dataset.getDomainOrder() == DomainOrder.ASCENDING) { int low = 0; int high = itemCount - 1; double lowValue = dataset.getXValue(series, low); if (lowValue > xHigh) { return low; } double highValue = dataset.getXValue(series, high); if (highValue <= xHigh) { return high; } int mid = (low + high) / 2; while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (midV <= xHigh) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return mid; } else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) { int low = 0; int high = itemCount - 1; int mid = (low + high) / 2; double lowValue = dataset.getXValue(series, low); if (lowValue < xLow) { return low; } double highValue = dataset.getXValue(series, high); if (highValue >= xLow) { return high; } while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (midV >= xLow) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return mid; } else { int index = itemCount - 1; double x = dataset.getXValue(series, index); while (index >= 0 && x > xHigh) { index--; if (index >= 0) { x = dataset.getXValue(series, index); } } return Math.max(index, 0); } }  }
RendererUtilities { public static int findLiveItemsUpperBound(XYDataset dataset, int series, double xLow, double xHigh) { if (dataset == null) { throw new IllegalArgumentException("Null 'dataset' argument."); } if (xLow >= xHigh) { throw new IllegalArgumentException("Requires xLow < xHigh."); } int itemCount = dataset.getItemCount(series); if (itemCount <= 1) { return 0; } if (dataset.getDomainOrder() == DomainOrder.ASCENDING) { int low = 0; int high = itemCount - 1; double lowValue = dataset.getXValue(series, low); if (lowValue > xHigh) { return low; } double highValue = dataset.getXValue(series, high); if (highValue <= xHigh) { return high; } int mid = (low + high) / 2; while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (midV <= xHigh) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return mid; } else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) { int low = 0; int high = itemCount - 1; int mid = (low + high) / 2; double lowValue = dataset.getXValue(series, low); if (lowValue < xLow) { return low; } double highValue = dataset.getXValue(series, high); if (highValue >= xLow) { return high; } while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (midV >= xLow) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return mid; } else { int index = itemCount - 1; double x = dataset.getXValue(series, index); while (index >= 0 && x > xHigh) { index--; if (index >= 0) { x = dataset.getXValue(series, index); } } return Math.max(index, 0); } }  static int findLiveItemsLowerBound(XYDataset dataset, int series,
            double xLow, double xHigh); static int findLiveItemsUpperBound(XYDataset dataset, int series,
            double xLow, double xHigh); static int[] findLiveItems(XYDataset dataset, int series,
            double xLow, double xHigh); }
RendererUtilities { public static int findLiveItemsUpperBound(XYDataset dataset, int series, double xLow, double xHigh) { if (dataset == null) { throw new IllegalArgumentException("Null 'dataset' argument."); } if (xLow >= xHigh) { throw new IllegalArgumentException("Requires xLow < xHigh."); } int itemCount = dataset.getItemCount(series); if (itemCount <= 1) { return 0; } if (dataset.getDomainOrder() == DomainOrder.ASCENDING) { int low = 0; int high = itemCount - 1; double lowValue = dataset.getXValue(series, low); if (lowValue > xHigh) { return low; } double highValue = dataset.getXValue(series, high); if (highValue <= xHigh) { return high; } int mid = (low + high) / 2; while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (midV <= xHigh) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return mid; } else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) { int low = 0; int high = itemCount - 1; int mid = (low + high) / 2; double lowValue = dataset.getXValue(series, low); if (lowValue < xLow) { return low; } double highValue = dataset.getXValue(series, high); if (highValue >= xLow) { return high; } while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (midV >= xLow) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return mid; } else { int index = itemCount - 1; double x = dataset.getXValue(series, index); while (index >= 0 && x > xHigh) { index--; if (index >= 0) { x = dataset.getXValue(series, index); } } return Math.max(index, 0); } }  static int findLiveItemsLowerBound(XYDataset dataset, int series,
            double xLow, double xHigh); static int findLiveItemsUpperBound(XYDataset dataset, int series,
            double xLow, double xHigh); static int[] findLiveItems(XYDataset dataset, int series,
            double xLow, double xHigh);  }