summaryrefslogtreecommitdiff
path: root/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@zancanaro.id.au>2015-06-06 16:40:04 +1000
committerCarlo Zancanaro <carlo@zancanaro.id.au>2015-06-06 16:40:04 +1000
commit84f0f216b4643601e4b8760d190b087bbce98bd4 (patch)
tree5f9ea5c1087b5da6611c9a9c51ba076e55e4e9e3 /src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java
parent05ec409ce96da92d430c4a8e58b08d46f42d667a (diff)
Lots of work on the stateful checking stuff: it's a fair bit nicer now
Diffstat (limited to 'src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java')
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java b/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java
index 8d3f272..8584fc7 100644
--- a/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java
+++ b/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java
@@ -5,13 +5,31 @@ import java.util.NoSuchElementException;
import java.util.function.Supplier;
public class CommandValue<T> {
+ public static interface Action<T> {
+ T doAction() throws Throwable;
+ }
+
+ public static interface VoidAction {
+ void doAction() throws Throwable;
+ }
+
private static Map<Integer, Object> values = null;
- public static <T> T withValues(Map<Integer, Object> newValues, Supplier<T> action) {
+ public static <T> T withValues(Map<Integer, Object> newValues, Action<T> action) throws Throwable {
+ Map<Integer,Object> oldValues = values;
+ try {
+ values = newValues;
+ return action.doAction();
+ } finally {
+ values = oldValues;
+ }
+ }
+
+ public static void withValues(Map<Integer, Object> newValues, VoidAction action) throws Throwable {
Map<Integer,Object> oldValues = values;
try {
values = newValues;
- return action.get();
+ action.doAction();
} finally {
values = oldValues;
}