projects
/
demos
/
kafka
/
training
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ROT: (Erwartet!) Merge der Korrigierten Test-Logik und Erwartungen
[demos/kafka/training]
/
src
/
main
/
java
/
de
/
juplo
/
kafka
/
AdderBusinessLogic.java
diff --git
a/src/main/java/de/juplo/kafka/AdderBusinessLogic.java
b/src/main/java/de/juplo/kafka/AdderBusinessLogic.java
index
64fdb8c
..
d525182
100644
(file)
--- a/
src/main/java/de/juplo/kafka/AdderBusinessLogic.java
+++ b/
src/main/java/de/juplo/kafka/AdderBusinessLogic.java
@@
-8,7
+8,7
@@
import java.util.Optional;
public class AdderBusinessLogic
{
public class AdderBusinessLogic
{
- private final Map<String,
Long
> state;
+ private final Map<String,
AdderResult
> state;
public AdderBusinessLogic()
public AdderBusinessLogic()
@@
-16,7
+16,7
@@
public class AdderBusinessLogic
this(new HashMap<>());
}
this(new HashMap<>());
}
- public AdderBusinessLogic(Map<String,
Long
> state)
+ public AdderBusinessLogic(Map<String,
AdderResult
> state)
{
this.state = state;
}
{
this.state = state;
}
@@
-24,7
+24,7
@@
public class AdderBusinessLogic
public synchronized Optional<Long> getSum(String user)
{
public synchronized Optional<Long> getSum(String user)
{
- return Optional.ofNullable(state.get(user));
+ return Optional.ofNullable(state.get(user))
.map(result -> result.sum)
;
}
public synchronized void addToSum(String user, Integer value)
}
public synchronized void addToSum(String user, Integer value)
@@
-35,8
+35,9
@@
public class AdderBusinessLogic
long sum =
Optional
.ofNullable(state.get(user))
long sum =
Optional
.ofNullable(state.get(user))
+ .map(result -> result.sum)
.orElse(0l);
.orElse(0l);
- state.put(user,
sum + value
);
+ state.put(user,
new AdderResult(value, sum + value)
);
}
public synchronized AdderResult calculate(String user)
}
public synchronized AdderResult calculate(String user)
@@
-44,10
+45,10
@@
public class AdderBusinessLogic
if (!state.containsKey(user))
throw new IllegalStateException("No sumation for " + user + " in progress");
if (!state.containsKey(user))
throw new IllegalStateException("No sumation for " + user + " in progress");
- return
new AdderResult(66, state.remove(user)
);
+ return
state.remove(user
);
}
}
- protected Map<String,
Long
> getState()
+ protected Map<String,
AdderResult
> getState()
{
return state;
}
{
return state;
}