SeasonalCompositingMapper extends Mapper<NullWritable, NullWritable, IntWritable, BandTileWritable> { static Date nextWeek(Date week, Calendar start, Calendar stop, int daysPerWeek) { GregorianCalendar c = DateUtils.createCalendar(); c.setTime(week); c.add(Calendar.DATE, daysPerWeek == 7 ? lengthOfWeek(c) : daysPerWeek); if (c.after(stop)) { start.add(Calendar.YEAR, 1); stop.add(Calendar.YEAR, 1); c.setTime(start.getTime()); } return c.getTime(); }  @Override void run(Context context); static final int STATUS_CLOUD_SHADOW; static final int DEBUG_X; static final int DEBUG_Y; static final int DEBUG_X2; static final int DEBUG_Y2; static final boolean DEBUG; }
@Test public void testNextWeek() throws Exception { Date d = DATE_FORMAT.parse("2012-01-01"); Calendar start = DateUtils.createCalendar(); start.setTime(DATE_FORMAT.parse("2012-01-01")); Calendar stop = DateUtils.createCalendar(); stop.setTime(DATE_FORMAT.parse("2012-12-31")); GregorianCalendar c = DateUtils.createCalendar(); c.setTime(d); assertEquals(0, c.get(Calendar.MONTH)) ; assertEquals(1, c.get(Calendar.DAY_OF_MONTH)) ; for (int i = 0; i < 52; i++) { final int l = SeasonalCompositingMapper.lengthOfWeek(c); if ((c.get(Calendar.MONTH) == Calendar.FEBRUARY && c.get(Calendar.DAY_OF_MONTH) == 26) || (c.get(Calendar.MONTH) == Calendar.DECEMBER && c.get(Calendar.DAY_OF_MONTH) == 24)) { assertEquals(8, l); } else { assertEquals(7, l); } d = SeasonalCompositingMapper.nextWeek(d, start, stop, 7); c.setTime(d); } assertEquals("2013-01-01", DATE_FORMAT.format(d)); }