PixExMeasurementReader implements Iterator<Measurement>, Closeable { static Measurement readMeasurement(String line, boolean withExpression) { final Scanner scanner = new Scanner(line); scanner.useLocale(Locale.ENGLISH); scanner.useDelimiter("\t"); boolean isValid = true; if (withExpression) { isValid = scanner.nextBoolean(); } final int productId = scanner.nextInt(); final int coordId = scanner.nextInt(); final String name = scanner.next(); final float lat = scanner.nextFloat(); final float lon = scanner.nextFloat(); final float pixelX = scanner.nextFloat(); final float pixelY = scanner.nextFloat(); final String date = scanner.next().trim(); final String time = scanner.next().trim(); ProductData.UTC dateTime = null; if (!date.isEmpty() && !time.isEmpty()) { try { dateTime = ProductData.UTC.parse(date + " " + time, "yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) { e.printStackTrace(); } } List<Number> valueList = new ArrayList<Number>(); while (scanner.hasNext()) { if (scanner.hasNextDouble()) { valueList.add(scanner.nextDouble()); } else { final String next = scanner.next().trim(); if (next.isEmpty()) { valueList.add(Double.NaN); } } } final Number[] values = valueList.toArray(new Number[valueList.size()]); return new Measurement(coordId, name, productId, pixelX, pixelY, dateTime, new GeoPos(lat, lon), values, isValid); } PixExMeasurementReader(File inputDir); @Override boolean hasNext(); @Override Measurement next(); @Override void remove(); @Override void close();  }
@Test public void testReadingWithEmptyColumns() throws Exception { final Measurement measurement = PixExMeasurementReader.readMeasurement( "12\t83744\t10083743\t57.936592\t10.130839\t520.5\t240.5\t2005-07-09\t10:12:03\t65.272634\t \t42.278252\t0\t500", false); assertEquals(12, measurement.getProductId()); assertEquals(83744, measurement.getCoordinateID()); assertEquals("10083743", measurement.getCoordinateName()); assertEquals(57.936592f, measurement.getLat(), 1.0e-6); assertEquals(10.130839, measurement.getLon(), 1.0e-6); assertEquals(520.5, measurement.getPixelX(), 1.0e-6); assertEquals(240.5, measurement.getPixelY(), 1.0e-6); final Date expectedDate = ProductData.UTC.parse("2005-07-09T10:12:03", "yyyy-MM-dd'T'hh:mm:ss").getAsDate(); assertEquals(expectedDate, measurement.getTime().getAsDate()); final Object[] values = measurement.getValues(); assertEquals(65.272634, ((Number) values[0]).doubleValue(), 1.0e-6); assertEquals(Double.NaN, ((Number) values[1]).doubleValue(), 1.0e-6); assertEquals(42.278252, ((Number) values[2]).doubleValue(), 1.0e-6); assertEquals(0, ((Number) values[3]).intValue()); assertEquals(500, ((Number) values[4]).intValue()); }