1 package de.juplo.kafka;
4 import java.util.HashMap;
6 import java.util.Optional;
9 public class AdderBusinessLogic
11 private final Map<String, Long> state;
14 public AdderBusinessLogic()
16 this(new HashMap<>());
19 public AdderBusinessLogic(Map<String, Long> state)
25 public synchronized Optional<Long> getSum(String user)
27 return Optional.ofNullable(state.get(user));
30 public synchronized void addToSum(String user, Integer value)
32 if (value == null || value < 1)
33 throw new IllegalArgumentException("Not a positive number: " + value);
37 .ofNullable(state.get(user))
39 state.put(user, sum + value);
42 public synchronized AdderResult calculate(String user)
44 if (!state.containsKey(user))
45 throw new IllegalStateException("No sumation for " + user + " in progress");
47 return new AdderResult(66, state.remove(user));
50 protected Map<String, Long> getState()