@Test public void testUnableToParse() { PropertiesCollectorSPI spi = getTimestampSpi(); PropertiesCollector collector = spi.create("regex=[0-9]{8}T[0-9]{6}", Arrays.asList("time")); File file = new File("polyphemus_20130301T00000.nc"); boolean parsed = true; try { collector.collect(file); collector.setProperties(feature); } catch (IllegalArgumentException ie) { parsed = false; } assertFalse(parsed); }
@Override public void setProperties(SimpleFeature feature) { final List<Date> dates = new ArrayList<Date>(); for (String match : getMatches()) { try { if (customFormat != null) { Date parsed = customFormat.parse(match); if (useHighTime) { format = format.replace("t", "T").replace("z", "Z"); parsed = FormatAndPrecision.expandFromCustomFormat(parsed, format) .getMaxValue(); } dates.add(parsed); } else { Collection parsed = PARSER.parse(match); parsed.stream() .forEach( d -> { DateRange range = (DateRange) d; Date date = useHighTime ? range.getMaxValue() : range.getMinValue(); dates.add(date); }); } } catch (ParseException e) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, e.getLocalizedMessage(), e); } } if (dates.size() <= 0) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("No matches found for this property extractor:"); } throw new IllegalArgumentException("No matches found for this property extractor"); } int index = 0; for (String propertyName : getPropertyNames()) { feature.setAttribute(propertyName, dates.get(index++)); if (index >= dates.size()) return; } }
TimestampFileNameExtractor extends RegExPropertiesCollector { @Override public void setProperties(SimpleFeature feature) { final List<Date> dates = new ArrayList<Date>(); for (String match : getMatches()) { try { if (customFormat != null) { Date parsed = customFormat.parse(match); if (useHighTime) { format = format.replace("t", "T").replace("z", "Z"); parsed = FormatAndPrecision.expandFromCustomFormat(parsed, format) .getMaxValue(); } dates.add(parsed); } else { Collection parsed = PARSER.parse(match); parsed.stream() .forEach( d -> { DateRange range = (DateRange) d; Date date = useHighTime ? range.getMaxValue() : range.getMinValue(); dates.add(date); }); } } catch (ParseException e) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, e.getLocalizedMessage(), e); } } if (dates.size() <= 0) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("No matches found for this property extractor:"); } throw new IllegalArgumentException("No matches found for this property extractor"); } int index = 0; for (String propertyName : getPropertyNames()) { feature.setAttribute(propertyName, dates.get(index++)); if (index >= dates.size()) return; } } }
TimestampFileNameExtractor extends RegExPropertiesCollector { @Override public void setProperties(SimpleFeature feature) { final List<Date> dates = new ArrayList<Date>(); for (String match : getMatches()) { try { if (customFormat != null) { Date parsed = customFormat.parse(match); if (useHighTime) { format = format.replace("t", "T").replace("z", "Z"); parsed = FormatAndPrecision.expandFromCustomFormat(parsed, format) .getMaxValue(); } dates.add(parsed); } else { Collection parsed = PARSER.parse(match); parsed.stream() .forEach( d -> { DateRange range = (DateRange) d; Date date = useHighTime ? range.getMaxValue() : range.getMinValue(); dates.add(date); }); } } catch (ParseException e) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, e.getLocalizedMessage(), e); } } if (dates.size() <= 0) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("No matches found for this property extractor:"); } throw new IllegalArgumentException("No matches found for this property extractor"); } int index = 0; for (String propertyName : getPropertyNames()) { feature.setAttribute(propertyName, dates.get(index++)); if (index >= dates.size()) return; } } TimestampFileNameExtractor(
            PropertiesCollectorSPI spi,
            List<String> propertyNames,
            String regex,
            String format,
            boolean fullPath,
            boolean useHighTime); }
TimestampFileNameExtractor extends RegExPropertiesCollector { @Override public void setProperties(SimpleFeature feature) { final List<Date> dates = new ArrayList<Date>(); for (String match : getMatches()) { try { if (customFormat != null) { Date parsed = customFormat.parse(match); if (useHighTime) { format = format.replace("t", "T").replace("z", "Z"); parsed = FormatAndPrecision.expandFromCustomFormat(parsed, format) .getMaxValue(); } dates.add(parsed); } else { Collection parsed = PARSER.parse(match); parsed.stream() .forEach( d -> { DateRange range = (DateRange) d; Date date = useHighTime ? range.getMaxValue() : range.getMinValue(); dates.add(date); }); } } catch (ParseException e) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, e.getLocalizedMessage(), e); } } if (dates.size() <= 0) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("No matches found for this property extractor:"); } throw new IllegalArgumentException("No matches found for this property extractor"); } int index = 0; for (String propertyName : getPropertyNames()) { feature.setAttribute(propertyName, dates.get(index++)); if (index >= dates.size()) return; } } TimestampFileNameExtractor(
            PropertiesCollectorSPI spi,
            List<String> propertyNames,
            String regex,
            String format,
            boolean fullPath,
            boolean useHighTime); @Override void setProperties(SimpleFeature feature); }
TimestampFileNameExtractor extends RegExPropertiesCollector { @Override public void setProperties(SimpleFeature feature) { final List<Date> dates = new ArrayList<Date>(); for (String match : getMatches()) { try { if (customFormat != null) { Date parsed = customFormat.parse(match); if (useHighTime) { format = format.replace("t", "T").replace("z", "Z"); parsed = FormatAndPrecision.expandFromCustomFormat(parsed, format) .getMaxValue(); } dates.add(parsed); } else { Collection parsed = PARSER.parse(match); parsed.stream() .forEach( d -> { DateRange range = (DateRange) d; Date date = useHighTime ? range.getMaxValue() : range.getMinValue(); dates.add(date); }); } } catch (ParseException e) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, e.getLocalizedMessage(), e); } } if (dates.size() <= 0) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("No matches found for this property extractor:"); } throw new IllegalArgumentException("No matches found for this property extractor"); } int index = 0; for (String propertyName : getPropertyNames()) { feature.setAttribute(propertyName, dates.get(index++)); if (index >= dates.size()) return; } } TimestampFileNameExtractor(
            PropertiesCollectorSPI spi,
            List<String> propertyNames,
            String regex,
            String format,
            boolean fullPath,
            boolean useHighTime); @Override void setProperties(SimpleFeature feature);  }