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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 | package Torello.Java.JSON;
import java.util.function.Consumer;
import java.util.Objects;
import Torello.Java.Function.IntIntTConsumer;
class CHANGEABLE_CONSUMER<T>
{
private Consumer<T> acceptorV1 = null;
private IntIntTConsumer<T> accepterV2 = null;
final Consumer<T> wrappedAcceptorV1;
final IntIntTConsumer<T> wrappedAcceptorV2;
private final boolean V1_OR_V1;
CHANGEABLE_CONSUMER(final boolean V1_OR_V1)
{
this.V1_OR_V1 = V1_OR_V1;
if (V1_OR_V1)
{
this.wrappedAcceptorV1 = (T theValue) -> this.acceptorV1.accept(theValue);
this.wrappedAcceptorV2 = null;
}
else
{
this.wrappedAcceptorV1 = null;
this.wrappedAcceptorV2 =
(int jsonArrayIndex, int javaOutCount, T theValue) ->
this.accepterV2.accept(jsonArrayIndex, javaOutCount, theValue);
}
}
void setConsumer(Consumer<T> c)
{
if (! V1_OR_V1) throw new WrongModeException(
"This CHANGEABLE CONSUMER was initialized in V2 mode (IntIntTConsumer), " +
"but you're attempting to call a V1-specific method (Consumer<T>).\n" +
"To register a new Consumer with this SettingsRec, please provide one which also " +
"accepts two integer parameters, in addition to a datum.\n" +
"Expected Consumer Signature: (int jsonArrayIndex, int javaOutCount, T theValue)"
);
Objects.requireNonNull(c, "You have passed null to Consumer-Parameter 'c'");
this.acceptorV1 = c;
}
void setConsumer(IntIntTConsumer<T> c)
{
if (V1_OR_V1) throw new WrongModeException(
"This CHANGEABLE CONSUMER was initialized in V1 mode (Consumer<T>), " +
"but you're attempting to call a V2-specific method (IntIntTConsumer<T>).\n" +
"To register a new Consumer with this SettingsRec, please provide one which accepts " +
"only the datum.\n" +
"Expected Consumer Signature: (T theValue)"
);
Objects.requireNonNull(c, "You have passed null to IntIntTConsumer-Parameter 'c'");
this.accepterV2 = c;
}
}
|