1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class PlanningExemple {
private static final Map<LocalTime,Integer> PLANNING_ACTIONS = createPlanning();
private static Map<LocalTime, Integer> createPlanning() {
Map<LocalTime,Integer> actions = new HashMap<LocalTime,Integer>();
actions.put(LocalTime.of(5, 30), 1);
actions.put(LocalTime.of(11, 30), 3);
actions.put(LocalTime.of(14, 0), 2);
actions.put(LocalTime.of(16, 30), 1);
actions.put(LocalTime.of(19, 30), 2);
actions.put(LocalTime.of(21, 45), 3);
return Collections.unmodifiableMap(actions);
}
public static int getAction(LocalTime time) {
return PLANNING_ACTIONS.getOrDefault(time, 0);
}
public static int getAction(String time) {
return getAction(LocalTime.parse(time,DateTimeFormatter.ofPattern("HH:mm")));
}
public static int getAction(int hours, int minutes) {
return getAction(LocalTime.of(hours, minutes));
}
public static int getAction(java.util.Date time) {
return getAction(time.toInstant().atZone(ZoneId.systemDefault()).toLocalTime());
}
public static void main(String[] args) {
LocalTime localTime = LocalTime.of(19, 30);
int indic = PlanningExemple.getAction(localTime);
System.out.println(localTime + " : " + indic);
}
} |
Partager