blob: 318362c796308676b8fed9f240c59cc7259190b8 (
plain)
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
68
69
70
71
72
73
74
75
|
//package org.acmsl.pocs.lambdafor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
public class ControlFlowDriver {
private static boolean m__bUsed = false;
public ControlFlowDriver() {
}
protected static void immutableSetUsed(final boolean used) {
m__bUsed = used;
}
protected static void setUsed(final boolean used) {
immutableSetUsed(used);
}
public static boolean isUsed() {
return m__bUsed;
}
public <C extends Collection<I>, I, R> Collection<R> forloop(final C items,
final Function<I, R> lambda) {
setUsed(true);
final List<R> result = new ArrayList<R>(items.size());
final List<I> list = new ArrayList<I>(items);
int position = -1;
while (true) {
ControlFlowCommand command = waitForCommand();
switch (command) {
case NEXT:
position++;
break;
case PREVIOUS:
position++;
break;
case RELOAD:
break;
default:
break;
}
if (position < 0) {
position = 0;
} else if (position > list.size() - 1) {
break;
}
result.set(position, lambda.apply(list.get(position)));
}
return result;
}
protected ControlFlowCommand waitForCommand() {
try {
Thread.sleep(1000);
} catch (final InterruptedException interruptedException) {
// whatever
}
return ControlFlowCommand.NEXT;
}
}
|