1 package org.gnu.glpk;
2
3 import java.util.LinkedList;
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public final class GlpkTerminal {
23
24
25
26 private static ThreadLocal<LinkedList<GlpkTerminalListener>> listeners
27 = new ThreadLocal<LinkedList<GlpkTerminalListener>>() {
28 @Override
29 protected LinkedList<GlpkTerminalListener> initialValue() {
30 return new LinkedList<GlpkTerminalListener>();
31 }
32 };
33
34 static {
35 GLPK.glp_term_hook(null, null);
36 }
37
38
39
40
41 private GlpkTerminal() {
42 }
43
44
45
46
47
48
49
50 public static int callback(final String str) {
51 boolean output = false;
52
53 if (listeners.get().size() > 0) {
54 for (GlpkTerminalListener listener : listeners.get()) {
55 output |= listener.output(str);
56 }
57 if (output) {
58 return 0;
59 } else {
60 return 1;
61 }
62 }
63 return 0;
64 }
65
66
67
68
69
70 public static void addListener(final GlpkTerminalListener listener) {
71 listeners.get().add(listener);
72 }
73
74
75
76
77
78
79 public static boolean removeListener(final GlpkTerminalListener listener) {
80 return listeners.get().remove(listener);
81 }
82
83
84
85
86 public static void removeAllListeners() {
87 while (listeners.get().size() > 0) {
88 listeners.get().removeLast();
89 }
90 }
91 }