MOD08FileFactory implements TemporalFileFactory { public TemporalFile createTemporalFile(final File file) { final String filename = file.getName(); if (!filename.endsWith(FILENAME_SUFFIX)) { return null; } if ((filename.indexOf(FILENAME_PART) == -1) || filename.indexOf(FILENAME_DATE_START) == -1) { return null; } final int dateStart = filename.indexOf(FILENAME_DATE_START); final int yearOffset = dateStart + FILENAME_DATE_START.length(); final int dayOffset = yearOffset + 4; int year; int dayOfYear; try { year = Integer.parseInt(filename.substring(yearOffset, yearOffset + 4)); dayOfYear = Integer.parseInt(filename.substring(dayOffset, dayOffset + 3)); } catch (NumberFormatException e) { return null; } final long startTime = computeTime(year, dayOfYear); final long endTime = startTime + AVG_PERIOD_IN_MILLIS - 1; return new TemporalFile(file, new Date(startTime), new Date(endTime)); }  TemporalFile createTemporalFile(final File file);  }
@Test public void testCreateTemporalFile() { final DateFormat dateFormat = UTCTest.getDateTimeFormat(); final MOD08FileFactory ff = new MOD08FileFactory(); File f; TemporalFile tf; f = new File("MOD08_E3.A2003001.004.2003337033342.hdf_FUB.hdf"); tf = ff.createTemporalFile(f); assertNotNull(tf); assertEquals("01.01.2003 00:00:00", dateFormat.format(tf.getStartDate())); assertEquals("08.01.2003 23:59:59", dateFormat.format(tf.getEndDate())); f = new File("MOD08_E3.A2003169.004.2003343085247.hdf_FUB.hdf"); tf = ff.createTemporalFile(f); assertNotNull(tf); assertEquals("18.06.2003 00:00:00", dateFormat.format(tf.getStartDate())); assertEquals("25.06.2003 23:59:59", dateFormat.format(tf.getEndDate())); f = new File("MOD08_E3.A2003365.004.2003343085247.hdf_FUB.hdf"); tf = ff.createTemporalFile(f); assertNotNull(tf); assertEquals("31.12.2003 00:00:00", dateFormat.format(tf.getStartDate())); assertEquals("07.01.2004 23:59:59", dateFormat.format(tf.getEndDate())); f = new File("MOD08PSMOD08_E3.A2005001.004.2005011171600.hdf"); tf = ff.createTemporalFile(f); assertNotNull(tf); assertEquals("01.01.2005 00:00:00", dateFormat.format(tf.getStartDate())); f = new File("MOD08_E3_MOD08SUB.A2006025.0000.001.2006038141658.hdf"); tf = ff.createTemporalFile(f); assertNotNull(tf); assertEquals("25.01.2006 00:00:00", dateFormat.format(tf.getStartDate())); }