@Test public void testGetCategory() throws TransformException { final Category[] categories = new Category[] { new Category("No data", null, 0), new Category("Land", null, 7), new Category("Clouds", null, 3), new Category("Temperature", null, 10, 100, 0.1, 5), new Category("Foo", null, 100, 120, -1, 3) }; CategoryList list; boolean searchNearest = false; do { list = new CategoryList(categories, null, searchNearest, null); assertTrue("containsAll", list.containsAll(Arrays.asList(categories))); assertSame(list.geophysics(true), list.inverse()); assertSame(list.geophysics(true).geophysics(false), list); assertSame(list.geophysics(false), list); final Range range = list.getRange(); assertEquals("min", 0, ((Number)range.getMinValue()).doubleValue(), 0); assertEquals("max", 120, ((Number)range.getMaxValue()).doubleValue(), 0); assertTrue ("min included", range.isMinIncluded() == true); assertTrue ("max included", range.isMaxIncluded() == false); assertSame( "0", list.getCategory( 0), categories[0]); assertSame( "7", list.getCategory( 7), categories[1]); assertSame( "3", list.getCategory( 3), categories[2]); assertSame(" 10", list.getCategory( 10), categories[3]); assertSame(" 50", list.getCategory( 50), categories[3]); assertSame("100", list.getCategory(100), categories[4]); assertSame("110", list.getCategory(110), categories[4]); if (searchNearest) { assertSame( "-1", list.getCategory( -1), categories[0]); assertSame( "2", list.getCategory( 2), categories[2]); assertSame( "4", list.getCategory( 4), categories[2]); assertSame( "9", list.getCategory( 9), categories[3]); assertSame("120", list.getCategory(120), categories[4]); assertSame("200", list.getCategory(200), categories[4]); } else { assertNull( "-1", list.getCategory( -1)); assertNull( "2", list.getCategory( 2)); assertNull( "4", list.getCategory( 4)); assertNull( "9", list.getCategory( 9)); assertNull("120", list.getCategory(120)); assertNull("200", list.getCategory(200)); } assertTrue ( "0", Double.isNaN(list.transform(0))); assertTrue ( "7", Double.isNaN(list.transform(7))); assertTrue ( "3", Double.isNaN(list.transform(3))); assertEquals( "10", 6, list.transform( 10), EPS); assertEquals( "50", 10, list.transform( 50), EPS); assertEquals("100", -97, list.transform(100), EPS); assertEquals("110", -107, list.transform(110), EPS); try { assertEquals("9", searchNearest ? 6 : 5.9, list.transform(9), EPS); if (!searchNearest) { fail(); } } catch (TransformException exception) { if (searchNearest) { throw exception; } } } while ((searchNearest = !searchNearest) == true); final double[] input = new double[512]; final double[] output0 = new double[input.length]; final double[] output1 = new double[input.length]; for (int i=0; i<input.length; i++) { input [i] = random.nextInt(130)-5; output0[i] = list.transform(input[i]); } list.transform(input, 0, output1, 0, input.length); compare(output0, output1, EPS); System.arraycopy(input, 0, output1, 3, input.length-3); list.transform (output1, 3, output1, 0, input.length-3); System.arraycopy(output0, input.length-3, output1, input.length-3, 3); compare(output0, output1, EPS); System.arraycopy(input, 3, output1, 0, input.length-3); list.transform (output1, 0, output1, 3, input.length-3); System.arraycopy(output0, 0, output1, 0, 3); compare(output0, output1, EPS); list.inverse().transform(output0, 0, output0, 0, output0.length); for (int i=0; i<output0.length; i++) { final double expected = input[i]; if (expected >= 10 && expected < 120) { assertEquals("inverse", expected, output0[i], EPS); } } }
public final Category getCategory(final double sample) { int i = binarySearch(minimums, sample); if (i >= 0) { assert Double.doubleToRawLongBits(sample) == Double.doubleToRawLongBits(minimums[i]); return categories[i]; } if (Double.isNaN(sample)) { return null; } assert i == Arrays.binarySearch(minimums, sample) : i; i = ~i-1; if (i >= 0) { final Category category = categories[i]; assert sample > category.minimum : sample; if (sample <= category.maximum) { return category; } if (overflowFallback != null) { if (++i < categories.length) { final Category upper = categories[i]; assert !(upper.minimum <= sample) : sample; return (upper.minimum-sample < sample-category.maximum) ? upper : category; } return overflowFallback; } } else if (overflowFallback != null) { if (categories.length != 0) { final Category category = categories[0]; if (!Double.isNaN(category.minimum)) { return category; } } } return null; }
CategoryList extends AbstractList<Category> implements MathTransform1D, Comparator<Category>, Serializable { public final Category getCategory(final double sample) { int i = binarySearch(minimums, sample); if (i >= 0) { assert Double.doubleToRawLongBits(sample) == Double.doubleToRawLongBits(minimums[i]); return categories[i]; } if (Double.isNaN(sample)) { return null; } assert i == Arrays.binarySearch(minimums, sample) : i; i = ~i-1; if (i >= 0) { final Category category = categories[i]; assert sample > category.minimum : sample; if (sample <= category.maximum) { return category; } if (overflowFallback != null) { if (++i < categories.length) { final Category upper = categories[i]; assert !(upper.minimum <= sample) : sample; return (upper.minimum-sample < sample-category.maximum) ? upper : category; } return overflowFallback; } } else if (overflowFallback != null) { if (categories.length != 0) { final Category category = categories[0]; if (!Double.isNaN(category.minimum)) { return category; } } } return null; } }
CategoryList extends AbstractList<Category> implements MathTransform1D, Comparator<Category>, Serializable { public final Category getCategory(final double sample) { int i = binarySearch(minimums, sample); if (i >= 0) { assert Double.doubleToRawLongBits(sample) == Double.doubleToRawLongBits(minimums[i]); return categories[i]; } if (Double.isNaN(sample)) { return null; } assert i == Arrays.binarySearch(minimums, sample) : i; i = ~i-1; if (i >= 0) { final Category category = categories[i]; assert sample > category.minimum : sample; if (sample <= category.maximum) { return category; } if (overflowFallback != null) { if (++i < categories.length) { final Category upper = categories[i]; assert !(upper.minimum <= sample) : sample; return (upper.minimum-sample < sample-category.maximum) ? upper : category; } return overflowFallback; } } else if (overflowFallback != null) { if (categories.length != 0) { final Category category = categories[0]; if (!Double.isNaN(category.minimum)) { return category; } } } return null; } CategoryList(final Category[] categories, final Unit<?> units);   CategoryList(Category[] categories, Unit<?> units, boolean searchNearest, CategoryList inverse); }
CategoryList extends AbstractList<Category> implements MathTransform1D, Comparator<Category>, Serializable { public final Category getCategory(final double sample) { int i = binarySearch(minimums, sample); if (i >= 0) { assert Double.doubleToRawLongBits(sample) == Double.doubleToRawLongBits(minimums[i]); return categories[i]; } if (Double.isNaN(sample)) { return null; } assert i == Arrays.binarySearch(minimums, sample) : i; i = ~i-1; if (i >= 0) { final Category category = categories[i]; assert sample > category.minimum : sample; if (sample <= category.maximum) { return category; } if (overflowFallback != null) { if (++i < categories.length) { final Category upper = categories[i]; assert !(upper.minimum <= sample) : sample; return (upper.minimum-sample < sample-category.maximum) ? upper : category; } return overflowFallback; } } else if (overflowFallback != null) { if (categories.length != 0) { final Category category = categories[0]; if (!Double.isNaN(category.minimum)) { return category; } } } return null; } CategoryList(final Category[] categories, final Unit<?> units);   CategoryList(Category[] categories, Unit<?> units, boolean searchNearest, CategoryList inverse); final int compare(final Category o1, final Category o2); CategoryList geophysics(final boolean geo); final InternationalString getName(); Unit<?> getUnits(); final NumberRange<?> getRange(); final ColorModel getColorModel(final int visibleBand, final int numBands); final ColorModel getColorModel(final int visibleBand, final int numBands, final int type); final Category getCategory(final double sample); final String format(final double value, final Locale locale); final int size(); final Category get(final int i); @Override final Category[] toArray(); @Override final String toString(); @Override boolean equals(final Object object); final int getSourceDimensions(); final int getTargetDimensions(); boolean isIdentity(); final MathTransform1D inverse(); final DirectPosition transform(final DirectPosition ptSrc, DirectPosition ptDst); final Matrix derivative(final DirectPosition point); final double derivative(final double value); final double transform(double value); final void transform(double[] srcPts, int srcOff,
                                double[] dstPts, int dstOff, int numPts); final void transform(float[] srcPts, int srcOff,
                                float[] dstPts, int dstOff, int numPts); final void transform(float[] srcPts, int srcOff,
                                double[] dstPts, int dstOff, int numPts); final void transform(double[] srcPts, int srcOff,
                                float[] dstPts, int dstOff, int numPts); final void transform(final WritableRectIter iterator); String toWKT(); }
CategoryList extends AbstractList<Category> implements MathTransform1D, Comparator<Category>, Serializable { public final Category getCategory(final double sample) { int i = binarySearch(minimums, sample); if (i >= 0) { assert Double.doubleToRawLongBits(sample) == Double.doubleToRawLongBits(minimums[i]); return categories[i]; } if (Double.isNaN(sample)) { return null; } assert i == Arrays.binarySearch(minimums, sample) : i; i = ~i-1; if (i >= 0) { final Category category = categories[i]; assert sample > category.minimum : sample; if (sample <= category.maximum) { return category; } if (overflowFallback != null) { if (++i < categories.length) { final Category upper = categories[i]; assert !(upper.minimum <= sample) : sample; return (upper.minimum-sample < sample-category.maximum) ? upper : category; } return overflowFallback; } } else if (overflowFallback != null) { if (categories.length != 0) { final Category category = categories[0]; if (!Double.isNaN(category.minimum)) { return category; } } } return null; } CategoryList(final Category[] categories, final Unit<?> units);   CategoryList(Category[] categories, Unit<?> units, boolean searchNearest, CategoryList inverse); final int compare(final Category o1, final Category o2); CategoryList geophysics(final boolean geo); final InternationalString getName(); Unit<?> getUnits(); final NumberRange<?> getRange(); final ColorModel getColorModel(final int visibleBand, final int numBands); final ColorModel getColorModel(final int visibleBand, final int numBands, final int type); final Category getCategory(final double sample); final String format(final double value, final Locale locale); final int size(); final Category get(final int i); @Override final Category[] toArray(); @Override final String toString(); @Override boolean equals(final Object object); final int getSourceDimensions(); final int getTargetDimensions(); boolean isIdentity(); final MathTransform1D inverse(); final DirectPosition transform(final DirectPosition ptSrc, DirectPosition ptDst); final Matrix derivative(final DirectPosition point); final double derivative(final double value); final double transform(double value); final void transform(double[] srcPts, int srcOff,
                                double[] dstPts, int dstOff, int numPts); final void transform(float[] srcPts, int srcOff,
                                float[] dstPts, int dstOff, int numPts); final void transform(float[] srcPts, int srcOff,
                                double[] dstPts, int dstOff, int numPts); final void transform(double[] srcPts, int srcOff,
                                float[] dstPts, int dstOff, int numPts); final void transform(final WritableRectIter iterator); String toWKT();  }