class 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));
    }

}