From: Kai Moritz Date: Sat, 13 Aug 2022 13:19:54 +0000 (+0200) Subject: GRÜN: Erwartungen implementiert X-Git-Tag: sumup-adder---lvm-2-tage~33 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=47657918b484fad60ac4062177cfeb569275d3d3;p=demos%2Fkafka%2Ftraining GRÜN: Erwartungen implementiert --- diff --git a/src/main/java/de/juplo/kafka/AdderBusinessLogic.java b/src/main/java/de/juplo/kafka/AdderBusinessLogic.java index 2e3d126..a3848c4 100644 --- a/src/main/java/de/juplo/kafka/AdderBusinessLogic.java +++ b/src/main/java/de/juplo/kafka/AdderBusinessLogic.java @@ -1,13 +1,31 @@ package de.juplo.kafka; +import java.util.HashMap; +import java.util.Map; + + public class AdderBusinessLogic { + private final Map state; + + public AdderBusinessLogic() { + this(new HashMap<>()); } + public AdderBusinessLogic(Map state) + { + this.state = state; + } + + public synchronized void startSum(String user) { + if (state.containsKey(user)) + throw new IllegalStateException("Sumation for " + user + " already in progress, state: " + state.get(user)); + + state.put(user, 0l); } }