Skip to content

Method: getZeitEinheit(ChronoUnit)

1: package simulation.SimulationsHelper;
2:
3: import simulation.exceptions.SimulationsException;
4: import tec.uom.se.ComparableQuantity;
5: import tec.uom.se.quantity.Quantities;
6: import tec.uom.se.unit.Units;
7:
8: import javax.measure.Unit;
9: import javax.measure.quantity.Time;
10: import java.time.temporal.ChronoUnit;
11: import java.util.HashMap;
12: import java.util.Map;
13: import java.util.Objects;
14:
15: /**
16: * Konstanten für die simulation.
17: */
18: public final class SimulationsKonstanten {
19:         
20:         private SimulationsKonstanten() {
21:                 // nicht initialisierbar
22:         }
23:         
24: private static final Map<ChronoUnit, Unit<Time>> ZEIT_EINHEITEN_ZUORDNUNG = new HashMap<>();
25:
26: static {
27: SimulationsKonstanten.ZEIT_EINHEITEN_ZUORDNUNG.put(ChronoUnit.SECONDS, Units.SECOND);
28: SimulationsKonstanten.ZEIT_EINHEITEN_ZUORDNUNG.put(ChronoUnit.MINUTES, Units.MINUTE);
29: SimulationsKonstanten.ZEIT_EINHEITEN_ZUORDNUNG.put(ChronoUnit.HOURS, Units.HOUR);
30: }
31:
32:
33: static final String SIMULATION_NICHT_MOEGLICH = "Simulation nicht möglich, wenn keine Belegungen geplant wurden";
34:
35: public static final ChronoUnit DEFAULT_JAVA_ZEIT_EINHEIT = ChronoUnit.MINUTES;
36:
37: public static final ComparableQuantity<Time> NEUTRALE_ZEIT = Quantities.getQuantity(0, Units.SECOND);
38:
39: /**
40: *
41: * @param berechnungsZeitEinheit Java Zeiteinheit
42: * @return die passende Zeiteinheit für das Quantity Pattern.
43: */
44: static Unit<Time> getZeitEinheit(final ChronoUnit berechnungsZeitEinheit) {
45: final Unit<Time> result = SimulationsKonstanten.ZEIT_EINHEITEN_ZUORDNUNG.get(berechnungsZeitEinheit);
46:• if (Objects.isNull(result)) {
47: throw new SimulationsException(String.format("Die Zeiteinheit %s wird nicht unterstützt."
48:                  + " Nur folgende Zeiteinheiten werden unterstützt: %s",
49: berechnungsZeitEinheit,
50: SimulationsKonstanten.ZEIT_EINHEITEN_ZUORDNUNG.keySet()));
51: }
52: return result;
53: }
54: }