List of usage examples for org.jfree.data DomainOrder DESCENDING
DomainOrder DESCENDING
To view the source code for org.jfree.data DomainOrder DESCENDING.
Click Source Link
From source file:org.jfree.data.DomainOrderTest.java
/** * Some checks for the equals() method./*from w w w . ja va 2s .c om*/ */ @Test public void testEquals() { assertEquals(DomainOrder.NONE, DomainOrder.NONE); assertEquals(DomainOrder.ASCENDING, DomainOrder.ASCENDING); assertEquals(DomainOrder.DESCENDING, DomainOrder.DESCENDING); assertFalse(DomainOrder.NONE.equals(DomainOrder.ASCENDING)); assertFalse(DomainOrder.NONE.equals(DomainOrder.DESCENDING)); assertFalse(DomainOrder.NONE.equals(null)); assertFalse(DomainOrder.ASCENDING.equals(DomainOrder.NONE)); assertFalse(DomainOrder.ASCENDING.equals(DomainOrder.DESCENDING)); assertFalse(DomainOrder.ASCENDING.equals(null)); assertFalse(DomainOrder.DESCENDING.equals(DomainOrder.NONE)); assertFalse(DomainOrder.DESCENDING.equals(DomainOrder.ASCENDING)); assertFalse(DomainOrder.DESCENDING.equals(null)); }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Finds the indices of the the items in the dataset that span the * specified x-value. There are three cases for the return value: * <ul>//from w w w .j a v a 2s . c o m * <li>there is an exact match for the x-value at index i * (returns {@code int[] {i, i}});</li> * <li>the x-value falls between two (adjacent) items at index i and i+1 * (returns {@code int[] {i, i+1}});</li> * <li>the x-value falls outside the domain bounds, in which case the * method returns {@code int[] {-1, -1}}.</li> * </ul> * @param dataset the dataset ({@code null} not permitted). * @param series the series index. * @param x the x-value. * * @return The indices of the two items that span the x-value. * * @since 1.0.16 * * @see #findYValue(org.jfree.data.xy.XYDataset, int, double) */ public static int[] findItemIndicesForX(XYDataset dataset, int series, double x) { Args.nullNotPermitted(dataset, "dataset"); int itemCount = dataset.getItemCount(series); if (itemCount == 0) { return new int[] { -1, -1 }; } if (itemCount == 1) { if (x == dataset.getXValue(series, 0)) { return new int[] { 0, 0 }; } else { return new int[] { -1, -1 }; } } if (dataset.getDomainOrder() == DomainOrder.ASCENDING) { int low = 0; int high = itemCount - 1; double lowValue = dataset.getXValue(series, low); if (lowValue > x) { return new int[] { -1, -1 }; } if (lowValue == x) { return new int[] { low, low }; } double highValue = dataset.getXValue(series, high); if (highValue < x) { return new int[] { -1, -1 }; } if (highValue == x) { return new int[] { high, high }; } int mid = (low + high) / 2; while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (x == midV) { return new int[] { mid, mid }; } if (midV < x) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return new int[] { low, high }; } else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) { int high = 0; int low = itemCount - 1; double lowValue = dataset.getXValue(series, low); if (lowValue > x) { return new int[] { -1, -1 }; } double highValue = dataset.getXValue(series, high); if (highValue < x) { return new int[] { -1, -1 }; } int mid = (low + high) / 2; while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (x == midV) { return new int[] { mid, mid }; } if (midV < x) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return new int[] { low, high }; } else { // we don't know anything about the ordering of the x-values, // so we iterate until we find the first crossing of x (if any) // we know there are at least 2 items in the series at this point double prev = dataset.getXValue(series, 0); if (x == prev) { return new int[] { 0, 0 }; // exact match on first item } for (int i = 1; i < itemCount; i++) { double next = dataset.getXValue(series, i); if (x == next) { return new int[] { i, i }; // exact match } if ((x > prev && x < next) || (x < prev && x > next)) { return new int[] { i - 1, i }; // spanning match } } return new int[] { -1, -1 }; // no crossing of x } }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Finds the indices of the the items in the dataset that span the * specified x-value. There are three cases for the return value: * <ul>/*from ww w. ja v a 2 s . co m*/ * <li>there is an exact match for the x-value at index i * (returns <code>int[] {i, i}</code>);</li> * <li>the x-value falls between two (adjacent) items at index i and i+1 * (returns <code>int[] {i, i+1}</code>);</li> * <li>the x-value falls outside the domain bounds, in which case the * method returns <code>int[] {-1, -1}</code>.</li> * </ul> * @param dataset the dataset (<code>null</code> not permitted). * @param series the series index. * @param x the x-value. * * @return The indices of the two items that span the x-value. * * @since 1.0.16 * * @see #findYValue(org.jfree.data.xy.XYDataset, int, double) */ public static int[] findItemIndicesForX(XYDataset dataset, int series, double x) { ParamChecks.nullNotPermitted(dataset, "dataset"); int itemCount = dataset.getItemCount(series); if (itemCount == 0) { return new int[] { -1, -1 }; } if (itemCount == 1) { if (x == dataset.getXValue(series, 0)) { return new int[] { 0, 0 }; } else { return new int[] { -1, -1 }; } } if (dataset.getDomainOrder() == DomainOrder.ASCENDING) { int low = 0; int high = itemCount - 1; double lowValue = dataset.getXValue(series, low); if (lowValue > x) { return new int[] { -1, -1 }; } if (lowValue == x) { return new int[] { low, low }; } double highValue = dataset.getXValue(series, high); if (highValue < x) { return new int[] { -1, -1 }; } if (highValue == x) { return new int[] { high, high }; } int mid = (low + high) / 2; while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (x == midV) { return new int[] { mid, mid }; } if (midV < x) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return new int[] { low, high }; } else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) { int high = 0; int low = itemCount - 1; double lowValue = dataset.getXValue(series, low); if (lowValue > x) { return new int[] { -1, -1 }; } double highValue = dataset.getXValue(series, high); if (highValue < x) { return new int[] { -1, -1 }; } int mid = (low + high) / 2; while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (x == midV) { return new int[] { mid, mid }; } if (midV < x) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return new int[] { low, high }; } else { // we don't know anything about the ordering of the x-values, // so we iterate until we find the first crossing of x (if any) // we know there are at least 2 items in the series at this point double prev = dataset.getXValue(series, 0); if (x == prev) { return new int[] { 0, 0 }; // exact match on first item } for (int i = 1; i < itemCount; i++) { double next = dataset.getXValue(series, i); if (x == next) { return new int[] { i, i }; // exact match } if ((x > prev && x < next) || (x < prev && x > next)) { return new int[] { i - 1, i }; // spanning match } } return new int[] { -1, -1 }; // no crossing of x } }