-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathInputProcessor.java
More file actions
38 lines (33 loc) · 1011 Bytes
/
InputProcessor.java
File metadata and controls
38 lines (33 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package chess.controller;
import java.util.function.Consumer;
import java.util.function.Supplier;
public class InputProcessor {
public static void processUntilSuccess(Runnable runnable, Consumer<String> printer) {
while(true) {
try {
runnable.run();
return;
} catch(Exception e) {
printer.accept(e.getMessage());
}
}
}
public static <T> void processUntilSuccess(Consumer<T> consumer, Consumer<String> printer, T t) {
while(true) {
try {
consumer.accept(t);
} catch(Exception e) {
printer.accept(e.getMessage());
}
}
}
public static <T> T processUntilSuccess(Supplier<T> supplier, Consumer<String> printer) {
while(true) {
try {
return supplier.get();
} catch(Exception e) {
printer.accept(e.getMessage());
}
}
}
}