PixExMeasurementFactory extends AbstractMeasurementFactory { @Override public Measurement[] createMeasurements(int centerX, int centerY, int coordinateID, String coordinateName, Product product, Raster validData) throws IOException { final long productId = productRegistry.getProductId(product); final int numPixels = windowSize * windowSize; final List<Measurement> measurements = new ArrayList<>(); final String[] rasterNames = rasterNamesFactory.getRasterNames(product); final Number[] values = new Number[rasterNames.length]; final int windowBorder = windowSize / 2; for (int idx = 0; idx < numPixels; idx++) { final int offsetX = idx % windowSize; final int offsetY = idx / windowSize; int x = centerX - windowBorder + offsetX; int y = centerY - windowBorder + offsetY; setBandValues(product, rasterNames, x, y, values); final boolean isValid = validData == null || validData.getSample(x, y, 0) != 0; measurements.add(createMeasurement(product, productId, coordinateID, coordinateName, values, isValid, x, y)); } return measurements.toArray(new Measurement[measurements.size()]); } PixExMeasurementFactory(final RasterNamesFactory rasterNamesFactory,
                                   final int windowSize, final ProductRegistry productRegistry); @Override Measurement[] createMeasurements(int centerX, int centerY, int coordinateID, String coordinateName,
                                            Product product, Raster validData); @Override void close();  }
@Test public void testMeasurementCreation() throws IOException { final int windowSize = 3; final PixExMeasurementFactory factory = new PixExMeasurementFactory(rasterNamesFactory, windowSize, productRegistry); final int pixelX = 3; final int pixelY = 4; final int coordinateID = 2345; final String cordName = "CordName"; final Measurement[] measurements = factory.createMeasurements(pixelX, pixelY, coordinateID, cordName, product, null); assertThat(measurements.length, equalTo(9)); final Measurement[] expectedMeasurements = new Measurement[9]; for (int i = 0; i < expectedMeasurements.length; i++) { expectedMeasurements[i] = createExpectedMeasurement(windowSize, pixelX, pixelY, coordinateID, cordName, i); } assertThat(measurements, equalTo(expectedMeasurements)); }