1 package org.textensor.report;
2
3
4
5 public class E {
6
7 public static long time0 = 0;
8
9 static String lastShortSource;
10 static String cachedAction;
11 static String lastErr;
12 static int nrep;
13
14 private static long getTime() {
15 return System.currentTimeMillis();
16 }
17
18
19 public static void zeroTime() {
20 time0 = getTime();
21 }
22
23 public static String getStringTime() {
24 if (time0 == 0) {
25 zeroTime();
26 }
27 long dt = (getTime() - time0);
28 return "" + dt;
29 }
30
31 public static void info(String s) {
32 System.out.println("INFO - " + s + getShortSource());
33 }
34
35 public static void infoTime(String s) {
36 System.out.println("INFO - " + s + " at " + getStringTime());
37 }
38
39
40 public static void longInfo(String s) {
41 System.out.println("INFO - " + s);
42 showSource(16);
43 }
44
45
46 public static void message(String s) {
47 System.out.println("MESSAGE - " + s);
48 }
49
50 public static void oneLineWarning(String s) {
51 System.out.println("WARNING - " + s + getShortSource());
52 }
53
54
55 public static void shortWarning(String s) {
56 System.out.println("WARNING - " + s + getShortSource());
57 }
58
59 public static void shortError(String s) {
60 System.out.println("ERROR - " + s + getShortSource());
61 }
62
63 public static void medWarning(String s) {
64 System.out.println("WARNING - " + s);
65 showSource(4);
66 }
67
68 public static void warning(String s) {
69 System.out.println("WARNING - " + s);
70 showSource(12);
71 }
72
73 public static void linkToWarning(String s, Object obj) {
74 System.out.println("WARNING - " + s);
75 String fcn = obj.getClass().getName();
76 String scn = fcn.substring(fcn.lastIndexOf(".") + 1, fcn.length());
77 System.out.println(" at " + fcn + ".nomethod(" + scn + ".java:1)");
78 }
79
80 public static void error(String s) {
81 if (lastErr != null && lastErr.equals(s)) {
82 nrep += 1;
83 if (nrep == 3 || nrep == 10 || nrep ==30 || nrep == 100) {
84 System.out.println(" ....... last error repeated " + nrep + " times");
85 }
86 } else {
87 if (nrep > 0) {
88 System.out.println("total repeats of last error " + nrep);
89 }
90 nrep = 0;
91 lastErr = s;
92 System.out.println("ERROR - " + s);
93 showSource();
94 }
95 }
96
97 public static void debugError(String s) {
98 System.out.println("ERROR - " + s);
99 System.out.println("stack trace follows: ");
100 stackTrace();
101 }
102
103
104 public static void fatalError(String s) {
105 System.out.println("FATAL - " + s);
106 stackTrace();
107 System.exit(0);
108 }
109
110
111 public static void override(String s) {
112 System.out.println("OVERRIDE - method should be overridden: " + s);
113 showSource();
114 }
115
116 public static void override() {
117 System.out.println("OVERRIDE - method should be overridden: ");
118 showSource();
119 }
120
121
122 public static void deprecate(String s) {
123 System.out.println("DEPRECATED - using deprecated class: " + s + " " +
124 getShortSource());
125 showShortSource();
126 }
127
128 public static void deprecate() {
129 System.out.println("DEPRECATED - using deprecated method " + getShortSource());
130 showShortSource();
131 }
132
133 public static void missing(String s) {
134 System.out.println("MISSING - missing code needed: " + s);
135 showSource();
136 }
137
138
139 public static void missing() {
140 System.out.println("MISSING - missing code needed");
141 showSource();
142 }
143
144
145 public static void stackTrace() {
146 (new Exception()).printStackTrace();
147 }
148
149
150
151
152 public static void showSource() {
153 showSource(10);
154 }
155
156 public static void showShortSource() {
157 showSource(2);
158 }
159
160 public static void showSource(int n) {
161 StackTraceElement[] stea = (new Exception()).getStackTrace();
162 for (int i = 2; i < 2 + n && i < stea.length; i++) {
163 System.out.println(" at " + stea[i].toString());
164
165
166
167
168
169 }
170 }
171
172
173 public static String getShortSource() {
174 StackTraceElement[] stea = (new Exception()).getStackTrace();
175 String ss = (" at " + stea[2].toString());
176 if (ss.equals(lastShortSource)) {
177 ss = "";
178 } else {
179 lastShortSource = ss;
180 }
181 return ss;
182 }
183
184
185
186 public static void delay() {
187 pause(200);
188 }
189
190
191 public static void pause(int n) {
192 try {
193
194 Thread.sleep(n);
195 } catch (Exception ex) {
196 }
197 }
198
199
200 public static void newLine() {
201 System.out.println("...");
202 }
203
204
205 public static void cacheAction(String s) {
206 cachedAction = s;
207 }
208
209 public static void reportCached() {
210 System.out.println("may relate to: " + cachedAction);
211 }
212
213
214 public static void dump(String[] labs) {
215 if (labs != null) {
216 for (int i = 0; i < labs.length; i++) {
217 System.out.println("element " + i + ": " + labs[i]);
218 }
219 }
220 }
221
222
223
224
225
226 public static void dump(String s, String[] labs) {
227 System.out.println(s + " " + labs + " " + getShortSource());
228 E.dump(labs);
229 }
230
231 public static void dump(String s, int[] ia) {
232 System.out.println("int[] array: " + s + " " + ia.length + " " + getShortSource());
233 for (int i = 0; i < ia.length; i++) {
234 System.out.println(" elt " + i + " = " + ia[i]);
235 }
236 }
237
238 public static void dump(String s, double[] ia) {
239 System.out.println("int[] array: " + s + " " + ia.length + " " + getShortSource());
240 for (int i = 0; i < ia.length; i++) {
241 System.out.println(" elt " + i + " = " + ia[i]);
242 }
243 }
244
245
246 public static void dump(String s, double[][] regcon) {
247 for (int i = 0; i < regcon.length; i++) {
248 dump(s + "-" + i, regcon[i]);
249 }
250 }
251
252
253 }