@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), new Category("Foo", null, 100, 120) }; CategoryList list; boolean searchNearest = false; do { list = new CategoryList(categories, null, searchNearest); assertTrue("containsAll", list.containsAll(Arrays.asList(categories))); 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)); } } while ((searchNearest = !searchNearest) == true); }
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 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 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 extends AbstractList<Category> implements 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); final int compare(final Category o1, final Category o2); 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); @Override int hashCode(); final int getSourceDimensions(); final int getTargetDimensions(); boolean isIdentity(); String toWKT(); }
CategoryList extends AbstractList<Category> implements 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); final int compare(final Category o1, final Category o2); 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); @Override int hashCode(); final int getSourceDimensions(); final int getTargetDimensions(); boolean isIdentity(); String toWKT();  }