OWTClassificationOp extends PixelOperator { static String getBestBandName(String reflectancesPrefix, float wavelength, Band[] bands) { String bestBandName = null; double maxDistance = 10.0; double wavelengthDist = Double.MAX_VALUE; for (Band band : bands) { float spectralWavelength = band.getSpectralWavelength(); boolean isSpectralBand = spectralWavelength > 0; if (isSpectralBand && band.getName().startsWith(reflectancesPrefix)) { float currentWavelengthDist = Math.abs(spectralWavelength - wavelength); if (currentWavelengthDist < wavelengthDist && currentWavelengthDist < maxDistance) { wavelengthDist = currentWavelengthDist; bestBandName = band.getName(); } } } return bestBandName; }    }
@Test public void testGetBestBandName() throws Exception { final Band band1 = new Band("reflec_10", ProductData.TYPE_FLOAT32, 10, 10); band1.setSpectralBandIndex(1); band1.setSpectralWavelength(195.0f); final Band band2 = new Band("reflec_20", ProductData.TYPE_FLOAT32, 10, 10); band2.setSpectralBandIndex(2); band2.setSpectralWavelength(204.0f); final String bestBandName1 = OWTClassificationOp.getBestBandName("reflec", 198, new Band[]{band1, band2}); final String bestBandName2 = OWTClassificationOp.getBestBandName("reflec", 201, new Band[]{band1, band2}); assertEquals("reflec_10", bestBandName1); assertEquals("reflec_20", bestBandName2); }