@Test public void resolveRepeatYear() { Map<String, Object> map = make("{repeat:{year:2}}"); Calendar c = Calendar.getInstance(); c.setTime(now.getTime()); c.add(Calendar.YEAR, 2); long expectedDur = 2L * 365 * 24 * 3600 * 1000; resolver.resolveRepeat(map, reminder, now); assertEquals(expectedDur, reminder.repeatDuration, 100); assertNotNull(reminder.startTime); assertEquals(c.getTimeInMillis(), reminder.startTime.getTime(), 100); }
void resolveRepeat(Map<String, Object> map, ReminderImpl reminder, Calendar now){ if(!map.containsKey(Constants.KEY_REPEAT)){ reminder.repeatDuration = -1; return; } Map<String, Object> repeatMap = (Map<String, Object>) map.get(Constants.KEY_REPEAT); zip(Constants.KEYS_TIME, Constants.KEYS_MUL, Constants.KEYS_CAL_FIELD) .forEach((key, mul, field) -> { if(repeatMap.containsKey(key)){ int duration = ((Number) repeatMap.get(key)).intValue(); reminder.repeatDuration += duration * mul; if(key.equals(Constants.KEY_WEEK)) duration *= 7; now.add(field, duration); } return true; }); if(repeatMap.containsKey(Constants.KEY_DOW)) resolveRepeatDow(((Number) repeatMap.get(Constants.KEY_DOW)).intValue(), reminder, now); if(repeatMap.containsKey(Constants.KEY_SHIFT)) getOrDefault(map, Constants.KEY_START_TIME, new HashMap<String, Object>()) .put(Constants.KEY_SHIFT, repeatMap.get(Constants.KEY_SHIFT)); reminder.startTime = now.getTime(); }
ArgumentResolver { void resolveRepeat(Map<String, Object> map, ReminderImpl reminder, Calendar now){ if(!map.containsKey(Constants.KEY_REPEAT)){ reminder.repeatDuration = -1; return; } Map<String, Object> repeatMap = (Map<String, Object>) map.get(Constants.KEY_REPEAT); zip(Constants.KEYS_TIME, Constants.KEYS_MUL, Constants.KEYS_CAL_FIELD) .forEach((key, mul, field) -> { if(repeatMap.containsKey(key)){ int duration = ((Number) repeatMap.get(key)).intValue(); reminder.repeatDuration += duration * mul; if(key.equals(Constants.KEY_WEEK)) duration *= 7; now.add(field, duration); } return true; }); if(repeatMap.containsKey(Constants.KEY_DOW)) resolveRepeatDow(((Number) repeatMap.get(Constants.KEY_DOW)).intValue(), reminder, now); if(repeatMap.containsKey(Constants.KEY_SHIFT)) getOrDefault(map, Constants.KEY_START_TIME, new HashMap<String, Object>()) .put(Constants.KEY_SHIFT, repeatMap.get(Constants.KEY_SHIFT)); reminder.startTime = now.getTime(); } }
ArgumentResolver { void resolveRepeat(Map<String, Object> map, ReminderImpl reminder, Calendar now){ if(!map.containsKey(Constants.KEY_REPEAT)){ reminder.repeatDuration = -1; return; } Map<String, Object> repeatMap = (Map<String, Object>) map.get(Constants.KEY_REPEAT); zip(Constants.KEYS_TIME, Constants.KEYS_MUL, Constants.KEYS_CAL_FIELD) .forEach((key, mul, field) -> { if(repeatMap.containsKey(key)){ int duration = ((Number) repeatMap.get(key)).intValue(); reminder.repeatDuration += duration * mul; if(key.equals(Constants.KEY_WEEK)) duration *= 7; now.add(field, duration); } return true; }); if(repeatMap.containsKey(Constants.KEY_DOW)) resolveRepeatDow(((Number) repeatMap.get(Constants.KEY_DOW)).intValue(), reminder, now); if(repeatMap.containsKey(Constants.KEY_SHIFT)) getOrDefault(map, Constants.KEY_START_TIME, new HashMap<String, Object>()) .put(Constants.KEY_SHIFT, repeatMap.get(Constants.KEY_SHIFT)); reminder.startTime = now.getTime(); } ArgumentResolver(Context context); }
ArgumentResolver { void resolveRepeat(Map<String, Object> map, ReminderImpl reminder, Calendar now){ if(!map.containsKey(Constants.KEY_REPEAT)){ reminder.repeatDuration = -1; return; } Map<String, Object> repeatMap = (Map<String, Object>) map.get(Constants.KEY_REPEAT); zip(Constants.KEYS_TIME, Constants.KEYS_MUL, Constants.KEYS_CAL_FIELD) .forEach((key, mul, field) -> { if(repeatMap.containsKey(key)){ int duration = ((Number) repeatMap.get(key)).intValue(); reminder.repeatDuration += duration * mul; if(key.equals(Constants.KEY_WEEK)) duration *= 7; now.add(field, duration); } return true; }); if(repeatMap.containsKey(Constants.KEY_DOW)) resolveRepeatDow(((Number) repeatMap.get(Constants.KEY_DOW)).intValue(), reminder, now); if(repeatMap.containsKey(Constants.KEY_SHIFT)) getOrDefault(map, Constants.KEY_START_TIME, new HashMap<String, Object>()) .put(Constants.KEY_SHIFT, repeatMap.get(Constants.KEY_SHIFT)); reminder.startTime = now.getTime(); } ArgumentResolver(Context context); Reminder resolve(Map<String, Object> map, String rawText, Calendar now); }
ArgumentResolver { void resolveRepeat(Map<String, Object> map, ReminderImpl reminder, Calendar now){ if(!map.containsKey(Constants.KEY_REPEAT)){ reminder.repeatDuration = -1; return; } Map<String, Object> repeatMap = (Map<String, Object>) map.get(Constants.KEY_REPEAT); zip(Constants.KEYS_TIME, Constants.KEYS_MUL, Constants.KEYS_CAL_FIELD) .forEach((key, mul, field) -> { if(repeatMap.containsKey(key)){ int duration = ((Number) repeatMap.get(key)).intValue(); reminder.repeatDuration += duration * mul; if(key.equals(Constants.KEY_WEEK)) duration *= 7; now.add(field, duration); } return true; }); if(repeatMap.containsKey(Constants.KEY_DOW)) resolveRepeatDow(((Number) repeatMap.get(Constants.KEY_DOW)).intValue(), reminder, now); if(repeatMap.containsKey(Constants.KEY_SHIFT)) getOrDefault(map, Constants.KEY_START_TIME, new HashMap<String, Object>()) .put(Constants.KEY_SHIFT, repeatMap.get(Constants.KEY_SHIFT)); reminder.startTime = now.getTime(); } ArgumentResolver(Context context); Reminder resolve(Map<String, Object> map, String rawText, Calendar now);  }