MyOlciPixelOp extends PixelOperator { static String findWaveBand(Product product, boolean fail, double centralWavelength, double maxDeltaWavelength, String... bandNames) { Band[] bands = product.getBands(); String bestBand = null; double minDelta = Double.MAX_VALUE; for (Band band : bands) { double bandWavelength = band.getSpectralWavelength(); if (bandWavelength > 0.0) { double delta = Math.abs(bandWavelength - centralWavelength); if (delta < minDelta && delta <= maxDeltaWavelength) { bestBand = band.getName(); minDelta = delta; } } } if (bestBand != null) { return bestBand; } for (String bandName : bandNames) { Band band = product.getBand(bandName); if (band != null) { return band.getName(); } } if (fail) { throw new OperatorException("Missing band at " + centralWavelength + " nm"); } return null; }    }
@Test public void testFindBand() throws Exception { Product product = new Product("dummy", "dummy", 10, 10); addBand(product, "a", 500); addBand(product, "b", 600); addBand(product, "c", 620); addBand(product, "d", 700); addBand(product, "e", 712); addBand(product, "f", 715); addBand(product, "g", 799); addBand(product, "h", 800); addBand(product, "i", 801); addBand(product, "j", 899); addBand(product, "k", 900); addBand(product, "l", 16000); assertEquals("b", MyOlciPixelOp.findWaveBand(product, true, 600, 20)); assertEquals("h", MyOlciPixelOp.findWaveBand(product, true, 800, 10)); }
@Test public void testFindBand_nothingFound() throws Exception { Product product = new Product("dummy", "dummy", 10, 10); addBand(product, "a", 500); addBand(product, "b", 600); addBand(product, "c", 620); addBand(product, "d", 700); addBand(product, "e", 712); addBand(product, "f", 715); addBand(product, "g", 799); addBand(product, "h", 800); addBand(product, "i", 801); addBand(product, "j", 899); addBand(product, "k", 900); assertNull(MyOlciPixelOp.findWaveBand(product, false, 400, 40)); assertNull(MyOlciPixelOp.findWaveBand(product, false, 701, 0.5)); assertNull(MyOlciPixelOp.findWaveBand(product, false, 901, 0.5)); }
@Test public void testFindBand_nothingFound_2() throws Exception { Product product = new Product("dummy", "dummy", 10, 10); addBand(product, "a"); addBand(product, "b"); addBand(product, "c"); addBand(product, "d"); addBand(product, "e"); addBand(product, "f"); addBand(product, "g"); addBand(product, "h"); addBand(product, "i"); addBand(product, "j"); addBand(product, "k"); addBand(product, "l"); assertNull(MyOlciPixelOp.findWaveBand(product, false, 600, 10)); }