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
66
67 | package Torello.JSON;
import Torello.Java.Additional.Counter;
import Torello.Java.Function.IntIntTConsumer;
import java.util.function.Consumer;
import java.util.function.ObjIntConsumer;
import javax.json.JsonValue;
public class ACCEPTOR<T>
{
private final Counter acceptCounter = new Counter(0);
private final T defaultValue;
private final ObjIntConsumer<T> MAIN_ACCEPTOR;
void accept(final T t, final int jsonArrayIndex)
{ MAIN_ACCEPTOR.accept(t, jsonArrayIndex); }
void reset()
{ this.acceptCounter.set(0); }
int retrieveCount()
{ return this.acceptCounter.size(); }
ACCEPTOR(final SETTINGS_REC_BUILDER<T, ?> b)
{
super();
this.defaultValue = b.defaultValue;
final Consumer<T> oneArgAcceptor = b.oneArgAcceptor();
final IntIntTConsumer<T> threeArgAcceptor = b.threeArgAcceptor();
if ( (oneArgAcceptor != null)
&& (threeArgAcceptor != null)
)
throw new RJArrSettingsError(
"The ACCEPTOR constructor seems to have been invoked with two non-null user " +
"consumers. It is expected that the ACCEPTOR constructor be invoked with " +
"precisely 1 user based consumer."
);
if (oneArgAcceptor != null) this.MAIN_ACCEPTOR =
(final T t, int jsonArrayIndex) ->
oneArgAcceptor.accept(t);
else if (threeArgAcceptor != null) this.MAIN_ACCEPTOR =
(final T t, int jsonArrayIndex) ->
threeArgAcceptor.accept(jsonArrayIndex, this.acceptCounter.addOne(), t);
else throw new RJArrSettingsError(
"While building the ACCEPTOR, there doesn't appear to be a non-null consumer. It " +
"is expected that the ACCEPTOR constructor be invoked with precisely 1 user based " +
"consumer."
);
}
void AN(int i) { MAIN_ACCEPTOR.accept(null, i); }
void AD(int i) { MAIN_ACCEPTOR.accept(defaultValue, i); }
void NOOP(int i) { }
void AN(JsonValue jv, int i) { MAIN_ACCEPTOR.accept(null, i); }
void AD(JsonValue jv, int i) { MAIN_ACCEPTOR.accept(defaultValue, i); }
void NOOP(JsonValue jv, int i) { }
}
|