Warning : session_start(): open(/var/lib/php/sessions/sess_8d2nchifa9t9tksjrdeubradod, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning : session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
import javax.net.ssl.*;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import javax.swing.undo.UndoManager;
import java.text.NumberFormat;
import java.awt.datatransfer.StringSelection;
import java.nio.file.Files;
import java.nio.file.Path;
public class main {
public static String data = "\r\n\r\n -- Rule\r\n \r\n What does a driver do? => He drives, dummie.\r\n \r\n -- Test\r\n \r\n What does a catcher do? => He catches, dummie.\r\n \r\n -- Helper Table\r\n \r\n driver, drive, drives, driving\r\n sleeper, sleep, sleeps, sleeping\r\n murderer, murder, murders, murdering\r\n catcher, catch, catches, catching\r\n\r\n";
public static void main(final String[] args) throws Exception {
pExperiment();
Map sections = minusSignSectionsCI(data);
pnlStruct(sections);
List> rules = ai_findDoubleArrowRulesAsPairs(sections.get("Rule"));
GazelleEvalContext ctx = gazelle_stdEvalContext(map(rules, new F1, T3>() {
public T3 get(Pair inOut) {
try {
return t3(joinPairWithDoubleArrow(inOut), "", aGlobalID());
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "t3(joinPairWithDoubleArrow(inOut), \"\", aGlobalID())";
}
}));
pnlStruct(ctx.engine.rules);
final List> helperTable = map("tok_splitAtComma", tlft(sections.get("Helper Table")));
final Map> helperIndex = indexTwoDArrayIC(helperTable);
final RuleEngine2.Rule rule = first(ctx.engine.rules);
rule.massageMap = new Object() {
public Map get(Map map, List tokC, List tokI, RuleEngine2_MatchedRule matched) {
try {
print("Massaging: " + map + " " + sfu(tokC) + " / " + sfu(tokI));
for (String t : codeTokens(matched.tokenize(rule.out))) {
if (map.containsKey(t))
continue;
Pair idx = helperIndex.get(t);
if (idx == null)
continue;
{
final Map __0 = cloneMap(map);
for (String key : keys(__0)) {
String val = __0.get(key);
int idx2 = indexOfIC(helperTable.get(idx.a), key);
if (idx2 < 0)
continue;
Pair idxVal = helperIndex.get(val);
print("Found: " + t + " <-> " + key);
mapPut(map, t, _get(_get(helperTable, idxVal.a), idx.b));
}
}
}
return map;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "print(\"Massaging: \" + map + \" \" + sfu(tokC) + \" / \" + sfu(tokI));\r\n for (S...";
}
};
List out = new ArrayList();
for (Pair inOut : ai_findDoubleArrowRulesAsPairs(sections.get("Test"))) {
nlPrintNL(inOut.a);
out.addAll(collect("line", pnl(gazelle_getChildren(new GazelleTree(ctx, inOut.a)))));
}
assertContainsIC(out, "He catches, dummie.");
print("OK!");
}
public static List tok_splitAtComma(String s) {
return tok_splitAtComma(javaTok(s));
}
public static List tok_splitAtComma(List tok) {
List out = new ArrayList();
for (int i = 0; i < l(tok); i++) {
int j = smartIndexOf(tok, ",", i);
out.add(joinSubList(tok, i + 1, j - 1));
i = j;
}
return out;
}
public static void pExperiment() {
if (!isMain())
return;
autoRestart(5);
experimentIcon();
centerHigherConsole();
tt();
}
public static Map minusSignSectionsCI(String text) {
return asCIMap(minusSignsSections(text));
}
public static void pnlStruct(Object o) {
if (o instanceof Collection)
pnlStruct(((Collection) o));
else if (o instanceof Map)
pnlStruct(((Map) o));
else
throw fail(_getClass(o));
}
public static Collection pnlStruct(Collection l) {
pnlStruct((Iterable ) l);
return l;
}
public static Iterable pnlStruct(Iterable l) {
int i = 0;
if (l != null)
for (A a : l) print((++i) + ". " + struct_noStringSharing(a));
return l;
}
public static A[] pnlStruct(A[] l) {
pnlStruct(asList(l));
return l;
}
public static Map pnlStruct(Map map) {
pnl(map(map, new F2 () {
public Object get(A a, B b) {
try {
return sfu(a) + " = " + sfu(b);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "sfu(a) + \" = \" + sfu(b)";
}
}));
return map;
}
public static List> ai_findDoubleArrowRulesAsPairs(String text) {
List rulesRaw = ai_splitEntriesWithMultipleDoubleArrows(splitAtEmptyLines(text));
return mapNonNulls("splitAtDoubleArrow_pair", rulesRaw);
}
public static GazelleEvalContext gazelle_stdEvalContext(List> rules) {
GazelleEvalContext ctx = new GazelleEvalContext();
ctx.engine = new RuleEngine2();
ctx.engine.addRules2(rules);
MultiMap statementsByRule = ai_gazelle_indexStatementsByRule(dm_gazelle_statementsFromAppliedRules());
ctx.dataByRule = mapValues("ai_gazelle_analyzeStatementsForRule", multiMapToMap(statementsByRule));
return ctx;
}
public static List map(Iterable l, Object f) {
return map(f, l);
}
public static List map(Object f, Iterable l) {
List x = emptyList(l);
if (l != null)
for (Object o : l) x.add(callF(f, o));
return x;
}
public static List map(Iterable l, F1 f) {
return map(f, l);
}
public static List map(F1 f, Iterable l) {
List x = emptyList(l);
if (l != null)
for (Object o : l) x.add(callF(f, o));
return x;
}
public static List map(Object f, Object[] l) {
return map(f, asList(l));
}
public static List map(Object[] l, Object f) {
return map(f, l);
}
public static List map(Object f, Map map) {
return map(map, f);
}
public static List map(Map map, Object f) {
List x = new ArrayList();
if (map != null)
for (Object _e : map.entrySet()) {
Map.Entry e = (Map.Entry) _e;
x.add(callF(f, e.getKey(), e.getValue()));
}
return x;
}
public static A get(List l, int idx) {
return l != null && idx >= 0 && idx < l(l) ? l.get(idx) : null;
}
public static A get(A[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : null;
}
public static boolean get(boolean[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : false;
}
public static Object get(Object o, String field) {
try {
if (o == null)
return null;
if (o instanceof Class)
return get((Class) o, field);
if (o instanceof Map)
return ((Map) o).get(field);
Field f = getOpt_findField(o.getClass(), field);
if (f != null) {
f.setAccessible(true);
return f.get(o);
}
if (o instanceof DynamicObject)
return ((DynamicObject) o).fieldValues.get(field);
} catch (Exception e) {
throw asRuntimeException(e);
}
throw new RuntimeException("Field '" + field + "' not found in " + o.getClass().getName());
}
public static Object get_raw(Object o, String field) {
try {
Field f = get_findField(o.getClass(), field);
f.setAccessible(true);
return f.get(o);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Object get(Class c, String field) {
try {
Field f = get_findStaticField(c, field);
f.setAccessible(true);
return f.get(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Field get_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Static field '" + field + "' not found in " + c.getName());
}
public static Field get_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Field '" + field + "' not found in " + c.getName());
}
public static Object get(String field, Object o) {
return get(o, field);
}
public static T3 t3(A a, B b, C c) {
return new T3(a, b, c);
}
public static String joinPairWithDoubleArrow(Pair p) {
return p == null ? "" : str(p.a) + " => " + str(p.b);
}
public static String aGlobalID() {
return randomID(globalIDLength());
}
public static RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
public static List tlft(String s) {
return toLinesFullTrim(s);
}
public static List tlft(File f) {
return toLinesFullTrim(f);
}
public static Map> indexTwoDArrayIC(List> table) {
if (table == null)
return null;
Map> map = ciMap();
for (int i = 0; i < l(table); i++) {
List row = table.get(i);
for (int j = 0; j < l(row); j++) map.put(row.get(j), pair(i, j));
}
return map;
}
public static Object first(Object list) {
return first((Iterable) list);
}
public static A first(List list) {
return empty(list) ? null : list.get(0);
}
public static A first(A[] bla) {
return bla == null || bla.length == 0 ? null : bla[0];
}
public static A first(IterableIterator i) {
return first((Iterator ) i);
}
public static A first(Iterator i) {
return i == null || !i.hasNext() ? null : i.next();
}
public static A first(Iterable i) {
if (i == null)
return null;
Iterator it = i.iterator();
return it.hasNext() ? it.next() : null;
}
public static Character first(String s) {
return empty(s) ? null : s.charAt(0);
}
public static A first(Pair p) {
return p == null ? null : p.a;
}
public static A first(T3 t) {
return t == null ? null : t.a;
}
public static volatile StringBuffer local_log = new StringBuffer();
public static volatile Appendable print_log = local_log;
public static volatile int print_log_max = 1024 * 1024;
public static volatile int local_log_max = 100 * 1024;
public static boolean print_silent;
public static Object print_byThread_lock = new Object();
public static volatile ThreadLocal print_byThread;
public static volatile Object print_allThreads;
public static void print() {
print("");
}
public static A print(String s, A o) {
print((endsWithLetterOrDigit(s) ? s + ": " : s) + o);
return o;
}
public static A print(A o) {
ping_okInCleanUp();
if (print_silent)
return o;
String s = String.valueOf(o) + "\n";
print_noNewLine(s);
return o;
}
public static void print_noNewLine(String s) {
Object f = print_byThread == null ? null : print_byThread.get();
if (f == null)
f = print_allThreads;
if (f != null)
if (isFalse(f instanceof F1 ? ((F1) f).get(s) : callF(f, s)))
return;
print_raw(s);
}
public static void print_raw(String s) {
s = fixNewLines(s);
Appendable loc = local_log;
Appendable buf = print_log;
int loc_max = print_log_max;
if (buf != loc && buf != null) {
print_append(buf, s, print_log_max);
loc_max = local_log_max;
}
if (loc != null)
print_append(loc, s, loc_max);
System.out.print(s);
}
public static String sfu(Object o) {
return structureForUser(o);
}
public static List codeTokens(List tok) {
return codeTokensOnly(tok);
}
public static Map cloneMap(Map map) {
if (map == null)
return new HashMap();
synchronized (map) {
return map instanceof TreeMap ? new TreeMap((TreeMap) map) : map instanceof LinkedHashMap ? new LinkedHashMap(map) : new HashMap(map);
}
}
public static Set keys(Map map) {
return map == null ? new HashSet() : map.keySet();
}
public static Set keys(Object map) {
return keys((Map) map);
}
public static Set keys(MultiMap mm) {
return mm.keySet();
}
public static int indexOfIC(List a, String b) {
return indexOfIgnoreCase(a, b);
}
public static int indexOfIC(List a, String b, int i) {
return indexOfIgnoreCase(a, b, i);
}
public static int indexOfIC(String a, String b) {
return indexOfIgnoreCase(a, b);
}
public static void mapPut(Map map, A key, B value) {
if (map != null && key != null && value != null)
map.put(key, value);
}
public static A _get(List l, int idx) {
return l != null && idx >= 0 && idx < l(l) ? l.get(idx) : null;
}
public static Object _get(Object o, String field) {
return get(o, field);
}
public static Object _get(String field, Object o) {
return get(o, field);
}
public static A _get(A[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : null;
}
public static void nlPrintNL(Object o) {
print_doubleNL(o);
}
public static List collect(Collection c, String field) {
return collectField(c, field);
}
public static List collect(String field, Collection c) {
return collectField(c, field);
}
public static A pnl(A l) {
printNumberedLines(l);
return l;
}
public static void pnl(Map map) {
printNumberedLines(map);
}
public static void pnl(Object[] a) {
printNumberedLines(a);
}
public static void pnl(String s) {
printNumberedLines(lines(s));
}
public static List gazelle_getChildren(GazelleTree tree, Object... __) {
if (tree == null)
return null;
if (tree.children != null)
return tree.children;
tree.children = new ArrayList();
double qualityCutOff = optPar("qualityCutOff", __, -0.75);
List dialogHistory = optPar("dialogHistory", __);
if (tree.ctx == null)
tree.setContext(assertNotNull("evalContext", (GazelleEvalContext) callF(assertNotNull("makeEvalContext", optPar("makeEvalContext", __)))));
GazelleEvalContext ctx = tree.ctx;
RuleEngine2 engine = ctx.engine;
Map inputMap = litmap("standard", tree.line);
List history = concatLists(dialogHistory, tree.history());
for (int i = 0; i < l(history); i++) inputMap.put("dialog-" + (l(history) - i), history.get(i));
for (RuleEngine2.SimplifyWithRule rule : engine.splitterRules()) {
try {
Object f = rule.function();
Collection out = (Collection) ((f instanceof String ? callF(engine.callFunctionOnString, (String) f, tree.line) : callF(f, tree.line)));
if (l(out) < 2)
continue;
GazelleTree child = new GazelleTree(joinWithVBar(out));
child.isSplitNode = true;
tree.add(child);
for (String line : out) child.add(new GazelleTree(line));
} catch (Throwable __e) {
_handleException(__e);
}
}
List l = sortByMethodDesc("qualitySum", ai_ruleEngine2_rulesForInput_5_allConditions(engine, inputMap, "debug", false, "tree", tree));
for (RuleEngine2_MatchedRule r : l) {
if (r.relativeQuality() < qualityCutOff)
continue;
String line = r.outText();
GazelleTree child = new GazelleTree(line);
child.mr = r;
ai_gazelle_analyzeStatementsForRule_Data data = ctx.dataByRule.get(r.rule.globalID);
child.prediction = data == null ? null : ai_gazelle_predictor1_onData(r, data);
tree.add(child);
}
sortByCalculatedFieldDesc(tree.children, new F1() {
public Integer get(GazelleTree c) {
try {
return ai_goodBadToInt(c.prediction);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ai_goodBadToInt(c.prediction)";
}
});
return tree.children;
}
public static > C assertContainsIC(C c, String y) {
return assertContainsIC(null, c, y);
}
public static > C assertContainsIC(String msg, C c, String y) {
if (!cic(c, y))
throw fail((msg != null ? msg + ": " : "") + y + " not contained in " + c);
return c;
}
public static int javaTok_n, javaTok_elements;
public static boolean javaTok_opt;
public static List javaTok(String s) {
++javaTok_n;
ArrayList tok = new ArrayList();
int l = s == null ? 0 : s.length();
int i = 0, n = 0;
while (i < l) {
int j = i;
char c, d;
while (j < l) {
c = s.charAt(j);
d = j + 1 >= l ? '\0' : s.charAt(j + 1);
if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
++j;
else if (c == '/' && d == '*') {
do ++j; while (j < l && !s.substring(j, Math.min(j + 2, l)).equals("*/"));
j = Math.min(j + 2, l);
} else if (c == '/' && d == '/') {
do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0);
} else
break;
}
tok.add(javaTok_substringN(s, i, j));
++n;
i = j;
if (i >= l)
break;
c = s.charAt(i);
d = i + 1 >= l ? '\0' : s.charAt(i + 1);
if (c == '\'' && Character.isJavaIdentifierStart(d) && i + 2 < l && "'\\".indexOf(s.charAt(i + 2)) < 0) {
j += 2;
while (j < l && Character.isJavaIdentifierPart(s.charAt(j))) ++j;
} else if (c == '\'' || c == '"') {
char opener = c;
++j;
while (j < l) {
int c2 = s.charAt(j);
if (c2 == opener || c2 == '\n' && opener == '\'') {
++j;
break;
} else if (c2 == '\\' && j + 1 < l)
j += 2;
else
++j;
}
} else if (Character.isJavaIdentifierStart(c))
do ++j; while (j < l && (Character.isJavaIdentifierPart(s.charAt(j)) || "'".indexOf(s.charAt(j)) >= 0));
else if (Character.isDigit(c)) {
do ++j; while (j < l && Character.isDigit(s.charAt(j)));
if (j < l && s.charAt(j) == 'L')
++j;
} else if (c == '[' && d == '[') {
do ++j; while (j + 1 < l && !s.substring(j, j + 2).equals("]]"));
j = Math.min(j + 2, l);
} else if (c == '[' && d == '=' && i + 2 < l && s.charAt(i + 2) == '[') {
do ++j; while (j + 2 < l && !s.substring(j, j + 3).equals("]=]"));
j = Math.min(j + 3, l);
} else
++j;
tok.add(javaTok_substringC(s, i, j));
++n;
i = j;
}
if ((tok.size() % 2) == 0)
tok.add("");
javaTok_elements += tok.size();
return tok;
}
public static List javaTok(List tok) {
return javaTokWithExisting(join(tok), tok);
}
public static int l(Object[] a) {
return a == null ? 0 : a.length;
}
public static int l(boolean[] a) {
return a == null ? 0 : a.length;
}
public static int l(byte[] a) {
return a == null ? 0 : a.length;
}
public static int l(short[] a) {
return a == null ? 0 : a.length;
}
public static int l(long[] a) {
return a == null ? 0 : a.length;
}
public static int l(int[] a) {
return a == null ? 0 : a.length;
}
public static int l(float[] a) {
return a == null ? 0 : a.length;
}
public static int l(double[] a) {
return a == null ? 0 : a.length;
}
public static int l(char[] a) {
return a == null ? 0 : a.length;
}
public static int l(Collection c) {
return c == null ? 0 : c.size();
}
public static int l(Map m) {
return m == null ? 0 : m.size();
}
public static int l(CharSequence s) {
return s == null ? 0 : s.length();
}
public static long l(File f) {
return f == null ? 0 : f.length();
}
public static int l(Object o) {
return o == null ? 0 : o instanceof String ? l((String) o) : o instanceof Map ? l((Map) o) : o instanceof Collection ? l((Collection) o) : o instanceof Object[] ? l((Object[]) o) : o instanceof boolean[] ? l((boolean[]) o) : o instanceof byte[] ? l((byte[]) o) : o instanceof char[] ? l((char[]) o) : o instanceof short[] ? l((short[]) o) : o instanceof int[] ? l((int[]) o) : o instanceof float[] ? l((float[]) o) : o instanceof double[] ? l((double[]) o) : o instanceof long[] ? l((long[]) o) : (Integer) call(o, "size");
}
public static int smartIndexOf(String s, String sub, int i) {
if (s == null)
return 0;
i = s.indexOf(sub, min(i, l(s)));
return i >= 0 ? i : l(s);
}
public static int smartIndexOf(String s, int i, char c) {
return smartIndexOf(s, c, i);
}
public static int smartIndexOf(String s, char c, int i) {
if (s == null)
return 0;
i = s.indexOf(c, min(i, l(s)));
return i >= 0 ? i : l(s);
}
public static int smartIndexOf(String s, String sub) {
return smartIndexOf(s, sub, 0);
}
public static int smartIndexOf(String s, char c) {
return smartIndexOf(s, c, 0);
}
public static int smartIndexOf(List l, A sub) {
return smartIndexOf(l, sub, 0);
}
public static int smartIndexOf(List l, int start, A sub) {
return smartIndexOf(l, sub, start);
}
public static int smartIndexOf(List l, A sub, int start) {
int i = indexOf(l, sub, start);
return i < 0 ? l(l) : i;
}
public static String joinSubList(List l, int i, int j) {
return join(subList(l, i, j));
}
public static String joinSubList(List l, int i) {
return join(subList(l, i));
}
public static boolean isMain() {
return isMainProgram();
}
public static double autoRestart_interval = 10;
public static boolean autoRestart_on, autoRestart_debug, autoRestart_simulate;
public static java.util.Timer autoRestart_timer;
public static void autoRestart(double interval) {
autoRestart_interval = interval;
autoRestart();
}
public static void autoRestart() {
if (!isMain() || autoRestart_on)
return;
autoRestart_on = true;
autoRestart_schedule();
preloadProgramTitle();
}
public static void autoRestart_off() {
if (!autoRestart_on)
return;
stopTimer(autoRestart_timer);
autoRestart_timer = null;
}
public static void autoRestart_schedule() {
autoRestart_timer = doLater_daemon(toMS(autoRestart_interval), "autoRestart_check");
}
public static void autoRestart_check() {
try {
String newMD5;
try {
newMD5 = serverAutoRestartMD5(programID());
} catch (Throwable e) {
return;
}
if (!isMD5(newMD5)) {
if (autoRestart_debug)
print("autoRestart: no server transpilation");
return;
}
if (autoRestart_localMD5 == null)
autoRestart_localMD5 = md5(loadCachedTranspilation(programID()));
String localMD5 = autoRestart_localMD5();
if (neq(localMD5, newMD5)) {
if (autoRestart_simulate)
print("Would upgrade now. " + localMD5 + " -> " + newMD5);
else {
infoBox("Upgrading " + programTitle());
restartWithDelay(500);
sleep();
}
}
} finally {
if (autoRestart_debug)
print("autoRestart: Done");
autoRestart_schedule();
}
}
public static void experimentIcon() {
consoleAndDefaultFrameIcon("#1101173");
}
public static void centerHigherConsole() {
if (headless())
return;
setConsoleHeight(600);
centerConsole();
}
public static void tt() {
typeWriterConsole();
}
public static String tt(Object contents, Object... params) {
return tag("tt", contents, params);
}
public static TreeMap asCIMap(Map map) {
return asCaseInsensitiveMap(map);
}
public static Map minusSignsSections(String text) {
List lines = lines(text);
List l = indicesOfStartingWithTrim(lines, "--");
LinkedHashMap out = new LinkedHashMap();
if (nempty(l))
mapPutIfNemptyValue(out, "", rtrim(lines(subList(lines, 0, first(l)))));
for (int i = 0; i < l(l); i++) {
int i1 = l.get(i);
int i2 = or(get(l, i + 1), l(lines));
String heading = trim(lines.get(i1));
int iHeading = 0;
while (iHeading < l(heading) && heading.charAt(iHeading) == '-') iHeading++;
heading = trim(substring(heading, iHeading));
out.put(heading, lines(subList(lines, i1 + 1, i2)));
}
return out;
}
public static RuntimeException fail() {
throw new RuntimeException("fail");
}
public static RuntimeException fail(Throwable e) {
throw asRuntimeException(e);
}
public static RuntimeException fail(Object msg) {
throw new RuntimeException(String.valueOf(msg));
}
public static RuntimeException fail(String msg) {
throw new RuntimeException(msg == null ? "" : msg);
}
public static RuntimeException fail(String msg, Throwable innerException) {
throw new RuntimeException(msg, innerException);
}
public static Class> _getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
return null;
}
}
public static Class _getClass(Object o) {
return o == null ? null : o instanceof Class ? (Class) o : o.getClass();
}
public static Class _getClass(Object realm, String name) {
try {
return getClass(realm).getClassLoader().loadClass(classNameToVM(name));
} catch (ClassNotFoundException e) {
return null;
}
}
public static String struct_noStringSharing(Object o) {
structure_Data d = new structure_Data();
d.noStringSharing = true;
return structure(o, d);
}
public static ArrayList asList(A[] a) {
return a == null ? new ArrayList () : new ArrayList (Arrays.asList(a));
}
public static ArrayList asList(int[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (int i : a) l.add(i);
return l;
}
public static ArrayList asList(float[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (float i : a) l.add(i);
return l;
}
public static ArrayList asList(Iterable s) {
if (s instanceof ArrayList)
return (ArrayList) s;
ArrayList l = new ArrayList();
if (s != null)
for (A a : s) l.add(a);
return l;
}
public static ArrayList asList(Producer p) {
ArrayList l = new ArrayList();
A a;
if (p != null)
while ((a = p.next()) != null) l.add(a);
return l;
}
public static ArrayList asList(Enumeration e) {
ArrayList l = new ArrayList();
if (e != null)
while (e.hasMoreElements()) l.add(e.nextElement());
return l;
}
public static List ai_splitEntriesWithMultipleDoubleArrows(List l) {
List out = new ArrayList();
for (String s : unnull(l)) if (l(splitAtDoubleArrow(javaTokWithBrackets(s))) > 2)
addAll(out, tlft(s));
else
out.add(s);
return out;
}
public static List splitAtEmptyLines(String text) {
List lines = toLines(text);
int n = l(lines), i = 0;
List parts = new ArrayList();
while (true) {
while (i < n && emptyAfterTrim(lines.get(i))) ++i;
if (i >= n)
break;
int j = i;
while (j < n && !emptyAfterTrim(lines.get(j))) ++j;
parts.add(fromLines(subList(lines, i, j)));
i = j;
}
return parts;
}
public static List mapNonNulls(Iterable l, Object f) {
return mapNonNulls(f, l);
}
public static List mapNonNulls(Object f, Iterable l) {
List x = new ArrayList();
if (l != null)
for (Object o : l) addIfNotNull(x, callF(f, o));
return x;
}
public static List mapNonNulls(Iterable l, F1 f) {
return mapNonNulls(f, l);
}
public static List mapNonNulls(F1 f, Iterable l) {
List x = new ArrayList();
if (l != null)
for (Object o : l) addIfNotNull(x, callF(f, o));
return x;
}
public static Pair splitAtDoubleArrow_pair(String s) {
return splitAtDoubleArrow_pair(javaTokWithBrackets(s));
}
public static Pair splitAtDoubleArrow_pair(List tok) {
return listToPair(splitAtDoubleArrow(tok));
}
public static MultiMap ai_gazelle_indexStatementsByRule(List statements) {
MultiMap mm = new MultiMap();
for (Matches m : getMatchesX_all("Rule *: ...", statements)) mm.put(m.unq(0), m.rest());
return mm;
}
public static class dm_gazelle_statementsFromAppliedRules_ByRule {
public String ruleID;
public TreeSet statements = new TreeSet();
}
public static List dm_gazelle_statementsFromAppliedRules() {
List concepts = cloneList((List) dm_requireAndCall("#1021413/AppliedRules", "concepts"));
Map ruleMap = new HashMap();
for (Object c : concepts) {
try {
String judgement = getString("judgement", c);
String struct = getString("matchedRuleStruct", c);
RuleEngine2_MatchedRule mr = unstruct(struct);
String ruleID = mr.rule.globalID;
dm_gazelle_statementsFromAppliedRules_ByRule r = getOrCreate_f1(ruleMap, ruleID, new F1() {
public dm_gazelle_statementsFromAppliedRules_ByRule get(String ruleID) {
try {
return nu(dm_gazelle_statementsFromAppliedRules_ByRule.class, "ruleID", ruleID);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "nu(dm_gazelle_statementsFromAppliedRules_ByRule, +ruleID)";
}
});
r.statements.addAll(ai_gazelle_statementsFromAppliedRule(mr, judgement));
} catch (Throwable __e) {
_handleException(__e);
}
}
List out = new ArrayList();
for (dm_gazelle_statementsFromAppliedRules_ByRule r : values(ruleMap)) for (String s : r.statements) out.add("Rule " + r.ruleID + ": " + s);
return out;
}
public static Map mapValues(Object func, Map map) {
Map m = similarEmptyMap(map);
for (Object key : keys(map)) m.put(key, callF(func, map.get(key)));
return m;
}
public static Map mapValues(Map map, Object func) {
return mapValues(func, map);
}
public static class ai_gazelle_analyzeStatementsForRule_Data {
public Set possibleVars, usedVars, unusedVars, varsUsedInGood, varsUsedInBad, varsUsedInGoodOnly, varsUsedInBadOnly;
public Set unclearVars;
public MultiMap goodMappings, badMappings, alwaysGoodMappings, alwaysBadMappings;
public List> completeGoodMappings, completeBadMappings;
}
public static ai_gazelle_analyzeStatementsForRule_Data ai_gazelle_analyzeStatementsForRule(Collection l) {
Set possibleVars = asCISet(matchAny_firstGroups("possible variable *", l));
Set usedVars = asCISet(matchX_any_firstGroups("... variable * was used", l));
Set unusedVars = asCISet(listMinusSet(possibleVars, usedVars));
Set varsUsedInGood = asCISet(matchX_any_firstGroups("in a good mapping, variable * was used", l));
Set varsUsedInBad = asCISet(matchX_any_firstGroups("in a bad mapping, variable * was used", l));
Set unclearVars = setIntersection(varsUsedInGood, varsUsedInBad);
MultiMap goodMappings = uniquifyMultiMapValues(pairsToMultiMap(matchX_any_firstAndSecondGroups("in a good mapping, variable * was mapped to *", l)));
MultiMap badMappings = uniquifyMultiMapValues(pairsToMultiMap(matchX_any_firstAndSecondGroups("in a bad mapping, variable * was mapped to *", l)));
MultiMap alwaysGoodMappings = multiMapDiff(goodMappings, badMappings);
MultiMap alwaysBadMappings = multiMapDiff(badMappings, goodMappings);
List> completeGoodMappings = map("safeUnstruct", matchX_any_firstGroups("a good mapping is *", l));
List> completeBadMappings = map("safeUnstruct", matchX_any_firstGroups("a bad mapping is *", l));
return nu(ai_gazelle_analyzeStatementsForRule_Data.class, "possibleVars", possibleVars, "usedVars", usedVars, "unusedVars", unusedVars, "varsUsedInGood", varsUsedInGood, "varsUsedInBad", varsUsedInBad, "unclearVars", unclearVars, "varsUsedInGoodOnly", setDiff(varsUsedInGood, varsUsedInBad), "varsUsedInBadOnly", setDiff(varsUsedInBad, varsUsedInGood), "goodMappings", goodMappings, "badMappings", badMappings, "alwaysGoodMappings", alwaysGoodMappings, "alwaysBadMappings", alwaysBadMappings, "completeGoodMappings", completeGoodMappings, "completeBadMappings", completeBadMappings);
}
public static Map > multiMapToMap(MultiMap m) {
return m == null ? null : m.data;
}
public static ArrayList emptyList() {
return new ArrayList();
}
public static ArrayList emptyList(int capacity) {
return new ArrayList(max(0, capacity));
}
public static ArrayList emptyList(Iterable l) {
return l instanceof Collection ? emptyList(((Collection) l).size()) : emptyList();
}
public static ArrayList emptyList(Class c) {
return new ArrayList();
}
public static Map> callF_cache = newDangerousWeakHashMap();
public static A callF(F0 f) {
return f == null ? null : f.get();
}
public static B callF(F1 f, A a) {
return f == null ? null : f.get(a);
}
public static C callF(F2 f, A a, B b) {
return f == null ? null : f.get(a, b);
}
public static void callF(VF1 f, A a) {
if (f != null)
f.get(a);
}
public static Object callF(Object f, Object... args) {
try {
if (f instanceof String)
return callMC((String) f, args);
if (f instanceof Runnable) {
((Runnable) f).run();
return null;
}
if (f == null)
return null;
Class c = f.getClass();
ArrayList methods;
synchronized (callF_cache) {
methods = callF_cache.get(c);
if (methods == null)
methods = callF_makeCache(c);
}
int n = l(methods);
if (n == 0) {
throw fail("No get method in " + getClassName(c));
}
if (n == 1)
return invokeMethod(methods.get(0), f, args);
for (int i = 0; i < n; i++) {
Method m = methods.get(i);
if (call_checkArgs(m, args, false))
return invokeMethod(m, f, args);
}
throw fail("No matching get method in " + getClassName(c));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static ArrayList callF_makeCache(Class c) {
ArrayList l = new ArrayList();
Class _c = c;
do {
for (Method m : _c.getDeclaredMethods()) if (m.getName().equals("get")) {
m.setAccessible(true);
l.add(m);
}
if (!l.isEmpty())
break;
_c = _c.getSuperclass();
} while (_c != null);
callF_cache.put(c, l);
return l;
}
public static Field getOpt_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
return null;
}
public static RuntimeException asRuntimeException(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
return t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
public static String str(Object o) {
return o == null ? "null" : o.toString();
}
public static String str(char[] c) {
return new String(c);
}
public static int randomID_defaultLength = 12;
public static String randomID(int length) {
return makeRandomID(length);
}
public static String randomID() {
return randomID(randomID_defaultLength);
}
public static int globalIDLength() {
return 16;
}
public static void _handleError(Error e) {
call(javax(), "_handleError", e);
}
public static List toLinesFullTrim(String s) {
List l = new ArrayList();
for (String line : toLines(s)) if (nempty(line = trim(line)))
l.add(line);
return l;
}
public static List toLinesFullTrim(File f) {
List l = new ArrayList();
for (String line : linesFromFile(f)) if (nempty(line = trim(line)))
l.add(line);
return l;
}
public static TreeMap ciMap() {
return caseInsensitiveMap();
}
public static Pair pair(A a, B b) {
return new Pair(a, b);
}
public static Pair pair(A a) {
return new Pair(a, a);
}
public static boolean empty(Collection c) {
return c == null || c.isEmpty();
}
public static boolean empty(CharSequence s) {
return s == null || s.length() == 0;
}
public static boolean empty(Map map) {
return map == null || map.isEmpty();
}
public static boolean empty(Object[] o) {
return o == null || o.length == 0;
}
public static boolean empty(Object o) {
if (o instanceof Collection)
return empty((Collection) o);
if (o instanceof String)
return empty((String) o);
if (o instanceof Map)
return empty((Map) o);
if (o instanceof Object[])
return empty((Object[]) o);
if (o instanceof byte[])
return empty((byte[]) o);
if (o == null)
return true;
throw fail("unknown type for 'empty': " + getType(o));
}
public static boolean empty(float[] a) {
return a == null || a.length == 0;
}
public static boolean empty(int[] a) {
return a == null || a.length == 0;
}
public static boolean empty(long[] a) {
return a == null || a.length == 0;
}
public static boolean empty(byte[] a) {
return a == null || a.length == 0;
}
public static boolean empty(File f) {
return getFileSize(f) == 0;
}
public static boolean endsWithLetterOrDigit(String s) {
return s != null && s.length() > 0 && Character.isLetterOrDigit(s.charAt(s.length() - 1));
}
public static void ping_okInCleanUp() {
if (ping_pauseAll || ping_anyActions)
ping_impl(true);
}
public static boolean isFalse(Object o) {
return eq(false, o);
}
public static String fixNewLines(String s) {
int i = indexOf(s, '\r');
if (i < 0)
return s;
int l = s.length();
StringBuilder out = new StringBuilder(l);
out.append(s, 0, i);
for (; i < l; i++) {
char c = s.charAt(i);
if (c != '\r')
out.append(c);
else {
out.append('\n');
if (i + 1 < l && s.charAt(i + 1) == '\n')
++i;
}
}
return out.toString();
}
public static void print_append(Appendable _buf, String s, int max) {
try {
synchronized (_buf) {
_buf.append(s);
if (!(_buf instanceof StringBuilder))
return;
StringBuilder buf = (StringBuilder) (_buf);
max /= 2;
if (buf.length() > max)
try {
int newLength = max / 2;
int ofs = buf.length() - newLength;
String newString = buf.substring(ofs);
buf.setLength(0);
buf.append("[...] ").append(newString);
} catch (Exception e) {
buf.setLength(0);
}
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static String structureForUser(Object o) {
return beautifyStructure(struct_noStringSharing(o));
}
public static List codeTokensOnly(List tok) {
List l = new ArrayList();
for (int i = 1; i < tok.size(); i += 2) l.add(tok.get(i));
return l;
}
public static int indexOfIgnoreCase(List a, String b) {
return indexOfIgnoreCase(a, b, 0);
}
public static int indexOfIgnoreCase(List a, String b, int i) {
int n = l(a);
for (; i < n; i++) if (eqic(a.get(i), b))
return i;
return -1;
}
public static int indexOfIgnoreCase(String a, String b) {
return indexOfIgnoreCase_manual(a, b);
}
public static void print_doubleNL(Object o) {
print("\n" + str(o) + "\n");
}
public static List collectField(Collection c, String field) {
List l = new ArrayList();
if (c != null)
for (Object a : c) l.add(getOpt(a, field));
return l;
}
public static List collectField(String field, Collection c) {
return collectField(c, field);
}
public static List printNumberedLines(List l) {
printNumberedLines((Collection ) l);
return l;
}
public static void printNumberedLines(Map map) {
printNumberedLines(mapToLines(map));
}
public static A printNumberedLines(A l) {
int i = 0;
if (l != null)
for (Object a : l) print((++i) + ". " + str(a));
return l;
}
public static void printNumberedLines(Object[] l) {
printNumberedLines(asList(l));
}
public static void printNumberedLines(Object o) {
printNumberedLines(lines(str(o)));
}
public static String lines(Collection lines) {
return fromLines(lines);
}
public static List lines(String s) {
return toLines(s);
}
public static A optPar(ThreadLocal tl, A defaultValue) {
A a = tl.get();
if (a != null) {
tl.set(null);
return a;
}
return defaultValue;
}
public static A optPar(ThreadLocal tl) {
return optPar(tl, null);
}
public static A optPar(Object[] params, String name) {
return optParam(params, name);
}
public static A optPar(String name, Object[] params) {
return optParam(params, name);
}
public static A optPar(Object[] params, String name, A defaultValue) {
return optParam(params, name, defaultValue);
}
public static A optPar(String name, Object[] params, A defaultValue) {
return optParam(params, name, defaultValue);
}
public static A assertNotNull(A a) {
assertTrue(a != null);
return a;
}
public static A assertNotNull(String msg, A a) {
assertTrue(msg, a != null);
return a;
}
public static HashMap litmap(Object... x) {
HashMap map = new HashMap();
litmap_impl(map, x);
return map;
}
public static void litmap_impl(Map map, Object... x) {
for (int i = 0; i < x.length - 1; i += 2) if (x[i + 1] != null)
map.put(x[i], x[i + 1]);
}
public static List concatLists(Collection ... lists) {
List l = new ArrayList();
if (lists != null)
for (Collection list : lists) if (list != null)
l.addAll(list);
return l;
}
public static List concatLists(Collection extends Collection > lists) {
List l = new ArrayList();
if (lists != null)
for (Collection list : lists) if (list != null)
l.addAll(list);
return l;
}
public static String joinWithVBar(Iterable l) {
return join(" | ", l);
}
public static volatile PersistableThrowable _handleException_lastException;
public static List _handleException_onException = synchroList(ll("printStackTrace2"));
public static void _handleException(Throwable e) {
_handleException_lastException = persistableThrowable(e);
Throwable e2 = innerException(e);
if (e2.getClass() == RuntimeException.class && eq(e2.getMessage(), "Thread cancelled.") || e2 instanceof InterruptedException)
return;
for (Object f : cloneList(_handleException_onException)) try {
callF(f, e);
} catch (Throwable e3) {
printStackTrace2(e3);
}
}
public static List sortByMethodDesc(Collection c, final String method) {
return sortByCalculatedFieldDesc(c, new F1 () {
public Object get(A a) {
try {
return callOpt(a, method);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callOpt(a, method)";
}
});
}
public static List sortByMethodDesc(String method, Collection c) {
return sortByMethodDesc(c, method);
}
public static List ai_ruleEngine2_rulesForInput_5_allConditions(RuleEngine2 engine, Map inputsByType, Object... __) {
List notDone = ai_ruleEngine2_rulesForInput_5(engine, inputsByType, __);
List done = new ArrayList();
boolean debug = boolPar("debug", __);
while (nempty(notDone)) {
List l = notDone;
notDone = new ArrayList();
for (RuleEngine2_MatchedRule mr : l) {
if (!mr.moreConditions()) {
if (debug)
print("Done: " + mr.ruleID());
done.add(mr);
} else {
if (debug)
print("Matching step " + mr.iCond + " in " + mr.ruleID());
if (ai_ruleEngine2_matchStep(mr, inputsByType, false)) {
if (debug)
print("Step succeeded");
notDone.add(mr);
} else
done.add(mr);
}
}
}
return done;
}
public static String ai_gazelle_predictor1_onData(RuleEngine2_MatchedRule r, ai_gazelle_analyzeStatementsForRule_Data data) {
return containsAny(keys(r.map), data.varsUsedInBadOnly) ? "bad" : "good";
}
public static List sortByCalculatedFieldDesc(Collection c, final Object f) {
return sortByCalculatedFieldDesc_inPlace(cloneList(c), f);
}
public static List sortByCalculatedFieldDesc(Object f, Collection c) {
return sortByCalculatedFieldDesc(c, f);
}
public static int ai_goodBadToInt(String s) {
if (eq(s, "good"))
return 1;
if (eq(s, "bad"))
return -1;
return 0;
}
public static boolean cic(Collection l, String s) {
return containsIgnoreCase(l, s);
}
public static boolean cic(String[] l, String s) {
return containsIgnoreCase(l, s);
}
public static boolean cic(String s, char c) {
return containsIgnoreCase(s, c);
}
public static boolean cic(String a, String b) {
return containsIgnoreCase(a, b);
}
public static Map> javaTokNPunctuationWithBrackets_cache = synchronizedMRUCache(1000);
public static List javaTokNPunctuationWithBrackets(String s) {
List tok = javaTokNPunctuationWithBrackets_cache.get(s);
if (tok == null)
javaTokNPunctuationWithBrackets_cache.put(s, tok = javaTokNPunctuationWithBrackets_uncached(s));
return tok;
}
public static List javaTokNPunctuationWithBrackets_uncached(String s) {
return tok_combineRoundOrCurlyBrackets_keep(javaTokNPunctuation_bracketsInC(s));
}
public static List javaTokNoQuotes(String s) {
return quotelessJavaTok(s);
}
public static List javaTokNoQuotesWithBrackets(String s) {
return tok_combineRoundOrCurlyBrackets_keep(javaTokNoQuotes(s));
}
public static Throwable printStackTrace2(Throwable e) {
print(getStackTrace2(e));
return e;
}
public static void printStackTrace2() {
printStackTrace2(new Throwable());
}
public static void printStackTrace2(String msg) {
printStackTrace2(new Throwable(msg));
}
public static String javaTok_substringN(String s, int i, int j) {
if (i == j)
return "";
if (j == i + 1 && s.charAt(i) == ' ')
return " ";
return s.substring(i, j);
}
public static String javaTok_substringC(String s, int i, int j) {
return s.substring(i, j);
}
public static List javaTokWithExisting(String s, List existing) {
++javaTok_n;
int nExisting = javaTok_opt && existing != null ? existing.size() : 0;
ArrayList tok = existing != null ? new ArrayList(nExisting) : new ArrayList();
int l = s.length();
int i = 0, n = 0;
while (i < l) {
int j = i;
char c, d;
while (j < l) {
c = s.charAt(j);
d = j + 1 >= l ? '\0' : s.charAt(j + 1);
if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
++j;
else if (c == '/' && d == '*') {
do ++j; while (j < l && !s.substring(j, Math.min(j + 2, l)).equals("*/"));
j = Math.min(j + 2, l);
} else if (c == '/' && d == '/') {
do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0);
} else
break;
}
if (n < nExisting && javaTokWithExisting_isCopyable(existing.get(n), s, i, j))
tok.add(existing.get(n));
else
tok.add(javaTok_substringN(s, i, j));
++n;
i = j;
if (i >= l)
break;
c = s.charAt(i);
d = i + 1 >= l ? '\0' : s.charAt(i + 1);
if (c == '\'' && Character.isJavaIdentifierStart(d) && i + 2 < l && "'\\".indexOf(s.charAt(i + 2)) < 0) {
j += 2;
while (j < l && Character.isJavaIdentifierPart(s.charAt(j))) ++j;
} else if (c == '\'' || c == '"') {
char opener = c;
++j;
while (j < l) {
if (s.charAt(j) == opener) {
++j;
break;
} else if (s.charAt(j) == '\\' && j + 1 < l)
j += 2;
else
++j;
}
} else if (Character.isJavaIdentifierStart(c))
do ++j; while (j < l && (Character.isJavaIdentifierPart(s.charAt(j)) || "'".indexOf(s.charAt(j)) >= 0));
else if (Character.isDigit(c)) {
do ++j; while (j < l && Character.isDigit(s.charAt(j)));
if (j < l && s.charAt(j) == 'L')
++j;
} else if (c == '[' && d == '[') {
do ++j; while (j + 1 < l && !s.substring(j, j + 2).equals("]]"));
j = Math.min(j + 2, l);
} else if (c == '[' && d == '=' && i + 2 < l && s.charAt(i + 2) == '[') {
do ++j; while (j + 2 < l && !s.substring(j, j + 3).equals("]=]"));
j = Math.min(j + 3, l);
} else
++j;
if (n < nExisting && javaTokWithExisting_isCopyable(existing.get(n), s, i, j))
tok.add(existing.get(n));
else
tok.add(javaTok_substringC(s, i, j));
++n;
i = j;
}
if ((tok.size() % 2) == 0)
tok.add("");
javaTok_elements += tok.size();
return tok;
}
public static boolean javaTokWithExisting_isCopyable(String t, String s, int i, int j) {
return t.length() == j - i && s.regionMatches(i, t, 0, j - i);
}
public static String join(String glue, Iterable strings) {
if (strings == null)
return "";
if (strings instanceof Collection) {
if (((Collection) strings).size() == 1)
return str(first(((Collection) strings)));
}
StringBuilder buf = new StringBuilder();
Iterator i = strings.iterator();
if (i.hasNext()) {
buf.append(i.next());
while (i.hasNext()) buf.append(glue).append(i.next());
}
return buf.toString();
}
public static String join(String glue, String... strings) {
return join(glue, Arrays.asList(strings));
}
public static String join(Iterable strings) {
return join("", strings);
}
public static String join(Iterable strings, String glue) {
return join(glue, strings);
}
public static String join(String[] strings) {
return join("", strings);
}
public static String join(String glue, Pair p) {
return p == null ? "" : str(p.a) + glue + str(p.b);
}
public static A call(Object o) {
return (A) callF(o);
}
public static A call(Object o, String method, String[] arg) {
return call(o, method, new Object[] { arg });
}
public static A call(Object o, String method, Object... args) {
return (A) call_cached(o, method, args);
}
public static int min(int a, int b) {
return Math.min(a, b);
}
public static long min(long a, long b) {
return Math.min(a, b);
}
public static float min(float a, float b) {
return Math.min(a, b);
}
public static float min(float a, float b, float c) {
return min(min(a, b), c);
}
public static double min(double a, double b) {
return Math.min(a, b);
}
public static double min(double[] c) {
double x = Double.MAX_VALUE;
for (double d : c) x = Math.min(x, d);
return x;
}
public static float min(float[] c) {
float x = Float.MAX_VALUE;
for (float d : c) x = Math.min(x, d);
return x;
}
public static byte min(byte[] c) {
byte x = 127;
for (byte d : c) if (d < x)
x = d;
return x;
}
public static short min(short[] c) {
short x = 0x7FFF;
for (short d : c) if (d < x)
x = d;
return x;
}
public static int min(int[] c) {
int x = Integer.MAX_VALUE;
for (int d : c) if (d < x)
x = d;
return x;
}
public static int indexOf(List l, A a, int startIndex) {
if (l == null)
return -1;
for (int i = startIndex; i < l(l); i++) if (eq(l.get(i), a))
return i;
return -1;
}
public static int indexOf(List l, int startIndex, A a) {
return indexOf(l, a, startIndex);
}
public static int indexOf(List l, A a) {
if (l == null)
return -1;
return l.indexOf(a);
}
public static int indexOf(String a, String b) {
return a == null || b == null ? -1 : a.indexOf(b);
}
public static int indexOf(String a, String b, int i) {
return a == null || b == null ? -1 : a.indexOf(b, i);
}
public static int indexOf(String a, char b) {
return a == null ? -1 : a.indexOf(b);
}
public static int indexOf(String a, int i, char b) {
return indexOf(a, b, i);
}
public static int indexOf(String a, char b, int i) {
return a == null ? -1 : a.indexOf(b, i);
}
public static int indexOf(String a, int i, String b) {
return a == null || b == null ? -1 : a.indexOf(b, i);
}
public static int indexOf(A[] x, A a) {
if (x == null)
return -1;
for (int i = 0; i < l(x); i++) if (eq(x[i], a))
return i;
return -1;
}
public static List subList(List l, int startIndex) {
return subList(l, startIndex, l(l));
}
public static List subList(List l, int startIndex, int endIndex) {
if (l == null)
return null;
startIndex = Math.max(0, startIndex);
endIndex = Math.min(l(l), endIndex);
if (startIndex >= endIndex)
return ll();
return l.subList(startIndex, endIndex);
}
public static boolean isMainProgram() {
return creator() == null;
}
public static void preloadProgramTitle() {
startThread(new Runnable() {
public void run() {
try {
programTitle();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "programTitle();";
}
});
}
public static void stopTimer(java.util.Timer timer) {
if (timer != null)
timer.cancel();
}
public static java.util.Timer doLater_daemon(long delay, final Object r) {
final java.util.Timer timer = new java.util.Timer(true);
timer.schedule(timerTask(r, timer), delay);
return timer;
}
public static java.util.Timer doLater_daemon(double delaySeconds, final Object r) {
return doLater_daemon(toMS(delaySeconds), r);
}
public static long toMS(double seconds) {
return (long) (seconds * 1000);
}
public static int serverAutoRestartMD5_timeout = 10000;
public static String serverAutoRestartMD5(String programID) {
return loadPageSilentlyWithTimeout("http://botcompany.de/1010693/raw?id=" + psI(programID), serverAutoRestartMD5_timeout);
}
public static String serverAutoRestartMD5() {
return serverAutoRestartMD5(programID());
}
public static String programID() {
return getProgramID();
}
public static String programID(Object o) {
return getProgramID(o);
}
public static boolean isMD5(String s) {
return l(s) == 32 && isLowerHexString(s);
}
public static String md5(String text) {
try {
if (text == null)
return "-";
return bytesToHex(md5_impl(toUtf8(text)));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static String md5(byte[] data) {
if (data == null)
return "-";
return bytesToHex(md5_impl(data));
}
public static MessageDigest md5_md;
public static byte[] md5_impl(byte[] data) {
try {
return MessageDigest.getInstance("MD5").digest(data);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static String md5(File file) {
return md5OfFile(file);
}
public static String loadCachedTranspilation(String id) {
try {
return loadTextFilePossiblyGZipped(getCachedTranspilationFile(id));
} catch (Throwable __e) {
return null;
}
}
public static String autoRestart_localMD5;
public static String autoRestart_localMD5() {
if (autoRestart_localMD5 == null)
autoRestart_localMD5 = md5(loadCachedTranspilation(programID()));
return autoRestart_localMD5;
}
public static boolean neq(Object a, Object b) {
return !eq(a, b);
}
public static JWindow infoBox(String text) {
return infoMessage(text);
}
public static JWindow infoBox(String text, double seconds) {
return infoMessage(text, seconds);
}
public static JWindow infoBox(Throwable e) {
return infoMessage(e);
}
public static String programTitle() {
return getProgramName();
}
public static void restartWithDelay(int delay) {
Object j = getJavaX();
call(j, "preKill");
call(j, "nohupJavax", smartJoin((String[]) get(j, "fullArgs")), call(j, "fullVMArguments"));
sleep(delay);
System.exit(0);
sleep();
}
public static volatile boolean sleep_noSleep;
public static void sleep(long ms) {
ping();
if (ms < 0)
return;
if (isAWTThread() && ms > 100)
throw fail("Should not sleep on AWT thread");
try {
Thread.sleep(ms);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void sleep() {
try {
if (sleep_noSleep)
throw fail("nosleep");
print("Sleeping.");
sleepQuietly();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static void consoleAndDefaultFrameIcon(String icon) {
consoleIcon(icon);
setDefaultFrameIcon(icon);
}
public static boolean headless() {
return isHeadless();
}
public static void setConsoleHeight(int h) {
setFrameHeight(consoleFrame(), h);
}
public static void centerConsole() {
centerConsoleFrame();
}
public static void centerConsole(int w, int h) {
setConsoleSize(w, h);
centerConsoleFrame();
}
public static void typeWriterConsole() {
if (isHeadless())
return;
Font f = typeWriterFont();
consoleFont(f);
consoleInputFont(f);
}
public static String tag(String tag) {
return htag(tag);
}
public static String tag(String tag, Object contents, Object... params) {
return htag(tag, str(contents), params);
}
public static String tag(String tag, StringBuilder contents, Object... params) {
return htag(tag, contents, params);
}
public static String tag(String tag, StringBuffer contents, Object... params) {
return htag(tag, contents, params);
}
public static TreeMap asCaseInsensitiveMap(Map map) {
if (isCIMap(map))
return (TreeMap) map;
TreeMap m = ciMap();
m.putAll(map);
return m;
}
public static List indicesOfStartingWithTrim(List l, String prefix) {
List x = new ArrayList();
for (int i = 0; i < l(l); i++) if (startsWith(trim(l.get(i)), prefix))
x.add(i);
return x;
}
public static boolean nempty(Collection c) {
return !empty(c);
}
public static boolean nempty(CharSequence s) {
return !empty(s);
}
public static boolean nempty(Object[] o) {
return !empty(o);
}
public static boolean nempty(byte[] o) {
return !empty(o);
}
public static boolean nempty(int[] o) {
return !empty(o);
}
public static boolean nempty(Map m) {
return !empty(m);
}
public static boolean nempty(Iterator i) {
return i != null && i.hasNext();
}
public static boolean nempty(Object o) {
return !empty(o);
}
public static void mapPutIfNemptyValue(Map map, A key, String value) {
if (map != null && key != null && nempty(value))
map.put(key, value);
}
public static String rtrim(String s) {
if (s == null)
return null;
int i = s.length();
while (i > 0 && " \t\r\n".indexOf(s.charAt(i - 1)) >= 0) --i;
return i < s.length() ? s.substring(0, i) : s;
}
public static A or(A a, A b) {
return a != null ? a : b;
}
public static String trim(String s) {
return s == null ? null : s.trim();
}
public static String trim(StringBuilder buf) {
return buf.toString().trim();
}
public static String trim(StringBuffer buf) {
return buf.toString().trim();
}
public static String substring(String s, int x) {
return substring(s, x, strL(s));
}
public static String substring(String s, int x, int y) {
if (s == null)
return null;
if (x < 0)
x = 0;
if (x >= s.length())
return "";
if (y < x)
y = x;
if (y > s.length())
y = s.length();
return s.substring(x, y);
}
public static Class> getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
return null;
}
}
public static Class getClass(Object o) {
return o instanceof Class ? (Class) o : o.getClass();
}
public static Class getClass(Object realm, String name) {
try {
try {
return getClass(realm).getClassLoader().loadClass(classNameToVM(name));
} catch (ClassNotFoundException e) {
return null;
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static String classNameToVM(String name) {
return name.replace(".", "$");
}
public static boolean structure_showTiming, structure_checkTokenCount;
public static String structure(Object o) {
return structure(o, new structure_Data());
}
public static String structure(Object o, structure_Data d) {
StringWriter sw = new StringWriter();
d.out = new PrintWriter(sw);
structure_go(o, d);
String s = str(sw);
if (structure_checkTokenCount) {
print("token count=" + d.n);
assertEquals("token count", l(javaTokC(s)), d.n);
}
return s;
}
public static void structure_go(Object o, structure_Data d) {
structure_1(o, d);
while (nempty(d.stack)) popLast(d.stack).run();
}
public static void structureToPrintWriter(Object o, PrintWriter out) {
structure_Data d = new structure_Data();
d.out = out;
structure_go(o, d);
}
public static boolean structure_allowShortening = false;
public static class structure_Data {
public PrintWriter out;
public int stringSizeLimit;
public int shareStringsLongerThan = 20;
public boolean noStringSharing;
public IdentityHashMap seen = new IdentityHashMap();
public HashMap strings = new HashMap();
public HashSet concepts = new HashSet();
public HashMap> fieldsByClass = new HashMap();
public HashMap persistenceInfo = new HashMap();
public int n;
public List stack = new ArrayList();
public structure_Data append(String token) {
out.print(token);
++n;
return this;
}
public structure_Data append(int i) {
out.print(i);
++n;
return this;
}
public structure_Data append(String token, int tokCount) {
out.print(token);
n += tokCount;
return this;
}
public structure_Data app(String token) {
out.print(token);
return this;
}
public structure_Data app(int i) {
out.print(i);
return this;
}
}
public static void structure_1(final Object o, final structure_Data d) {
try {
if (o == null) {
d.append("null");
return;
}
Class c = o.getClass();
boolean concept = false;
List lFields = d.fieldsByClass.get(c);
if (lFields == null) {
if (o instanceof Number) {
PrintWriter out = d.out;
if (o instanceof Integer) {
int i = ((Integer) o).intValue();
out.print(i);
d.n += i < 0 ? 2 : 1;
return;
}
if (o instanceof Long) {
long l = ((Long) o).longValue();
out.print(l);
out.print("L");
d.n += l < 0 ? 2 : 1;
return;
}
if (o instanceof Short) {
short s = ((Short) o).shortValue();
d.append("sh ", 2);
out.print(s);
d.n += s < 0 ? 2 : 1;
return;
}
if (o instanceof Float) {
d.append("fl ", 2);
quoteToPrintWriter(str(o), out);
return;
}
if (o instanceof Double) {
d.append("d(", 3);
quoteToPrintWriter(str(o), out);
d.append(")");
return;
}
if (o instanceof BigInteger) {
out.print("bigint(");
out.print(o);
out.print(")");
d.n += ((BigInteger) o).signum() < 0 ? 5 : 4;
return;
}
}
if (o instanceof Boolean) {
d.append(((Boolean) o).booleanValue() ? "t" : "f");
return;
}
if (o instanceof Character) {
d.append(quoteCharacter((Character) o));
return;
}
if (o instanceof File) {
d.append("File ").append(quote(((File) o).getPath()));
return;
}
Integer ref = d.seen.get(o);
if (o instanceof String && ref == null)
ref = d.strings.get((String) o);
if (ref != null) {
d.append("t").app(ref);
return;
}
if (!(o instanceof String))
d.seen.put(o, d.n);
else {
String s = d.stringSizeLimit != 0 ? shorten((String) o, d.stringSizeLimit) : (String) o;
if (!d.noStringSharing) {
if (d.shareStringsLongerThan == Integer.MAX_VALUE)
d.seen.put(o, d.n);
if (l(s) >= d.shareStringsLongerThan)
d.strings.put(s, d.n);
}
quoteToPrintWriter(s, d.out);
d.n++;
return;
}
if (o instanceof HashSet) {
d.append(o instanceof LinkedHashSet ? "lhs" : "hashset");
structure_1(new ArrayList((Set) o), d);
return;
}
if (o instanceof TreeSet) {
d.append(isCISet_gen(((TreeSet) o)) ? "ciset" : "treeset");
structure_1(new ArrayList(((TreeSet) o)), d);
return;
}
String name = c.getName();
if (o instanceof Collection && !startsWith(name, "main$")) {
if (name.equals("java.util.Collections$SynchronizedList") || name.equals("java.util.Collections$SynchronizedRandomAccessList"))
d.append("sync");
d.append("[");
final int l = d.n;
final Iterator it = ((Collection) o).iterator();
d.stack.add(new Runnable() {
public void run() {
try {
if (!it.hasNext())
d.append("]");
else {
d.stack.add(this);
if (d.n != l)
d.append(", ");
structure_1(it.next(), d);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (!it.hasNext())\r\n d.append(\"]\");\r\n else {\r\n d.sta...";
}
});
return;
}
if (o instanceof Map && !startsWith(name, "main$")) {
if (o instanceof LinkedHashMap)
d.append("lhm");
else if (o instanceof HashMap)
d.append("hm");
else if (name.equals("java.util.Collections$SynchronizedMap"))
d.append("sync");
else if (name.equals("java.util.Collections$SynchronizedSortedMap")) {
d.append("sync tm", 2);
}
d.append("{");
final int l = d.n;
final Iterator it = ((Map) o).entrySet().iterator();
d.stack.add(new Runnable() {
public boolean v;
public Map.Entry e;
public void run() {
if (v) {
d.append("=");
v = false;
d.stack.add(this);
structure_1(e.getValue(), d);
} else {
if (!it.hasNext())
d.append("}");
else {
e = (Map.Entry) it.next();
v = true;
d.stack.add(this);
if (d.n != l)
d.append(", ");
structure_1(e.getKey(), d);
}
}
}
});
return;
}
if (c.isArray()) {
if (o instanceof byte[]) {
d.append("ba ").append(quote(bytesToHex((byte[]) o)));
return;
}
final int n = Array.getLength(o);
if (o instanceof boolean[]) {
String hex = boolArrayToHex((boolean[]) o);
int i = l(hex);
while (i > 0 && hex.charAt(i - 1) == '0' && hex.charAt(i - 2) == '0') i -= 2;
d.append("boolarray ").append(n).app(" ").append(quote(substring(hex, 0, i)));
return;
}
String atype = "array", sep = ", ";
if (o instanceof int[]) {
atype = "intarray";
sep = " ";
}
d.append(atype).append("{");
d.stack.add(new Runnable() {
public int i;
public void run() {
if (i >= n)
d.append("}");
else {
d.stack.add(this);
if (i > 0)
d.append(", ");
structure_1(Array.get(o, i++), d);
}
}
});
return;
}
if (o instanceof Class) {
d.append("class(", 2).append(quote(((Class) o).getName())).append(")");
return;
}
if (o instanceof Throwable) {
d.append("exception(", 2).append(quote(((Throwable) o).getMessage())).append(")");
return;
}
if (o instanceof BitSet) {
BitSet bs = (BitSet) o;
d.append("bitset{", 2);
int l = d.n;
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
if (d.n != l)
d.append(", ");
d.append(i);
}
d.append("}");
return;
}
if (name.startsWith("java.") || name.startsWith("javax.")) {
d.append("j ").append(quote(str(o)));
return;
}
String dynName = shortDynamicClassName(o);
if (concept && !d.concepts.contains(dynName)) {
d.concepts.add(dynName);
d.append("c ");
}
TreeSet fields = new TreeSet(new Comparator() {
public int compare(Field a, Field b) {
return stdcompare(a.getName(), b.getName());
}
});
Class cc = c;
while (cc != Object.class) {
for (Field field : getDeclaredFields_cached(cc)) {
String fieldName = field.getName();
if (fieldName.equals("_persistenceInfo"))
d.persistenceInfo.put(c, field);
if ((field.getModifiers() & (java.lang.reflect.Modifier.STATIC | java.lang.reflect.Modifier.TRANSIENT)) != 0)
continue;
fields.add(field);
}
cc = cc.getSuperclass();
}
lFields = asList(fields);
for (int i = 0; i < l(lFields); i++) {
Field f = lFields.get(i);
if (f.getName().equals("this$1")) {
lFields.remove(i);
lFields.add(0, f);
break;
}
}
d.fieldsByClass.put(c, lFields);
} else {
Integer ref = d.seen.get(o);
if (ref != null) {
d.append("t").app(ref);
return;
}
d.seen.put(o, d.n);
}
Field persistenceInfoField = (Field) (d.persistenceInfo.get(c));
Map persistenceInfo = persistenceInfoField == null ? null : (Map) persistenceInfoField.get(o);
LinkedHashMap fv = new LinkedHashMap();
for (Field f : lFields) {
Object value;
try {
value = f.get(o);
} catch (Exception e) {
value = "?";
}
if (value != null && (persistenceInfo == null || !Boolean.FALSE.equals(persistenceInfo.get(f.getName()))))
fv.put(f.getName(), value);
}
String name = c.getName();
String shortName = dropPrefix("main$", name);
if (concept && eq(fv.get("className"), shortName))
fv.remove("className");
if (o instanceof DynamicObject) {
fv.putAll((Map) fv.get("fieldValues"));
fv.remove("fieldValues");
shortName = shortDynamicClassName(o);
fv.remove("className");
}
String singleField = fv.size() == 1 ? first(fv.keySet()) : null;
d.append(shortName);
final int l = d.n;
final Iterator it = fv.entrySet().iterator();
d.stack.add(new Runnable() {
public void run() {
try {
if (!it.hasNext()) {
if (d.n != l)
d.append(")");
} else {
Map.Entry e = (Map.Entry) it.next();
d.append(d.n == l ? "(" : ", ");
d.append((String) e.getKey()).append("=");
d.stack.add(this);
structure_1(e.getValue(), d);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (!it.hasNext()) {\r\n if (d.n != l)\r\n d.append(\")\");\r\n } else...";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static String unnull(String s) {
return s == null ? "" : s;
}
public static Collection unnull(Collection l) {
return l == null ? emptyList() : l;
}
public static List unnull(List l) {
return l == null ? emptyList() : l;
}
public static Map unnull(Map l) {
return l == null ? emptyMap() : l;
}
public static Iterable unnull(Iterable i) {
return i == null ? emptyList() : i;
}
public static A[] unnull(A[] a) {
return a == null ? (A[]) new Object[0] : a;
}
public static BitSet unnull(BitSet b) {
return b == null ? new BitSet() : b;
}
public static List splitAtDoubleArrow(String s) {
return splitAtDoubleArrow(javaTok(s));
}
public static List splitAtDoubleArrow(List tok) {
List l = new ArrayList();
int i = 0;
while (i < l(tok)) {
int j = indexOfSubList(tok, ll("=", "", ">"), i);
if (i >= l(tok))
break;
if (j < 0)
j = l(tok);
l.add(trimJoin(tok.subList(i, j)));
i = j + 3;
}
return l;
}
public static List javaTokWithBrackets(String s) {
return javaTokPlusBrackets(s);
}
public static void addAll(Collection c, Iterable b) {
if (c != null && b != null)
for (A a : b) c.add(a);
}
public static boolean addAll(Collection c, Collection b) {
return c != null && b != null && c.addAll(b);
}
public static boolean addAll(Collection c, B... b) {
return c != null && c.addAll(Arrays.asList(b));
}
public static IterableIterator toLines(File f) {
return linesFromFile(f);
}
public static List toLines(String s) {
List lines = new ArrayList();
if (s == null)
return lines;
int start = 0;
while (true) {
int i = toLines_nextLineBreak(s, start);
if (i < 0) {
if (s.length() > start)
lines.add(s.substring(start));
break;
}
lines.add(s.substring(start, i));
if (s.charAt(i) == '\r' && i + 1 < s.length() && s.charAt(i + 1) == '\n')
i += 2;
else
++i;
start = i;
}
return lines;
}
public static int toLines_nextLineBreak(String s, int start) {
for (int i = start; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '\r' || c == '\n')
return i;
}
return -1;
}
public static boolean emptyAfterTrim(String s) {
return empty(trim(s));
}
public static String fromLines(Collection lines) {
StringBuilder buf = new StringBuilder();
if (lines != null)
for (Object line : lines) buf.append(str(line)).append('\n');
return buf.toString();
}
public static String fromLines(String... lines) {
return fromLines(asList(lines));
}
public static void addIfNotNull(Collection l, A a) {
if (a != null && l != null)
l.add(a);
}
public static Pair listToPair(List l) {
return l(l) != 2 ? null : pair(first(l), second(l));
}
public static List getMatchesX_all(String pat, Iterable l) {
Matches m = new Matches();
List out = new ArrayList();
for (String s : unnull(l)) if (matchX(pat, s, m)) {
out.add(m);
m = new Matches();
}
return out;
}
public static ArrayList cloneList(Iterable l) {
return l instanceof Collection ? cloneList((Collection) l) : asList(l);
}
public static ArrayList cloneList(Collection l) {
if (l == null)
return new ArrayList();
synchronized (collectionMutex(l)) {
return new ArrayList (l);
}
}
public static A dm_requireAndCall(String moduleLibID, String method, Object... args) {
return dm_requireAndCallModule(moduleLibID, method, args);
}
public static String getString(Map map, Object key) {
return map == null ? null : (String) map.get(key);
}
public static String getString(List l, int idx) {
return (String) get(l, idx);
}
public static String getString(Object o, Object key) {
if (o instanceof Map)
return getString((Map) o, key);
if (key instanceof String)
return (String) getOpt(o, (String) key);
throw fail("Not a string key: " + getClassName(key));
}
public static String getString(String key, Object o) {
return getString(o, (Object) key);
}
public static A unstruct(String text) {
return (A) unstructure(text);
}
public static B getOrCreate_f1(Map map, A key, F1 create) {
try {
B b = map.get(key);
if (b == null)
mapPut(map, key, b = callF(create, key));
return b;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static A nu(Class c, Object... values) {
A a = nuObject(c);
setAll(a, values);
return a;
}
public static List ai_gazelle_statementsFromAppliedRule(RuleEngine2_MatchedRule r, String judgement) {
if (r == null || r.rule == null)
return new ArrayList();
if (nempty(judgement) && neq(judgement, "good"))
judgement = "bad";
String ruleID = r.rule.globalID;
String ruleIn = first(r.rule.in);
if (ruleIn == null)
return new ArrayList();
Map varMap = r.map;
String tokenize = r.tokenizationFunction;
List tok = (List) (callAndMake(tokenize, ruleIn));
List tokC = codeTokens(tok);
Set possibleVars = asCISet(tokC);
List statements = new ArrayList();
for (String a : keys(varMap)) {
String b = varMap.get(a);
statements.add(format("in a * mapping, variable " + quote(a) + " was used", judgement));
statements.add(format("in a * mapping, variable " + quote(a) + " was mapped to " + quote(b), judgement));
}
for (String var : possibleVars) statements.add("possible variable " + quote(var));
statements.add(format("a * mapping is *", judgement, sfu(varMap)));
return statements;
}
public static Collection values(Map map) {
return map == null ? emptyList() : map.values();
}
public static Collection values(MultiMap mm) {
return mm == null ? emptyList() : concatLists(values(mm.data));
}
public static Map similarEmptyMap(Map m) {
if (m instanceof TreeMap)
return new TreeMap(((TreeMap) m).comparator());
if (m instanceof LinkedHashMap)
return new LinkedHashMap();
return new HashMap();
}
public static TreeSet asCISet(Iterable c) {
return toCaseInsensitiveSet(c);
}
public static TreeSet asCISet(String... x) {
return toCaseInsensitiveSet(x);
}
public static List matchAny_firstGroups(String pat, Iterable l) {
Matches m = new Matches();
List out = new ArrayList();
for (String s : unnull(l)) if (match(pat, s, m))
out.add(m.unq(0));
return out;
}
public static List matchX_any_firstGroups(String pat, Iterable l) {
Matches m = new Matches();
List out = new ArrayList();
for (String s : unnull(l)) if (matchX(pat, s, m))
out.add(m.unq(0));
return out;
}
public static List listMinusSet(Iterable l, Collection stuff) {
if (empty(stuff))
return asList(l);
Set set = asSet(stuff);
List l2 = new ArrayList();
for (A a : l) if (!set.contains(a))
l2.add(a);
return l2;
}
public static List listMinusSet(Iterable l, Collection stuff, Collection stuff2) {
return listMinusSet(listMinusSet(l, stuff), stuff2);
}
public static Set setIntersection(Set a, Collection b) {
Set set = similarEmptySet(a);
Set bSet = asSet(b);
for (A x : a) if (bSet.contains(x))
set.add(x);
return set;
}
public static MultiMap uniquifyMultiMapValues(MultiMap mm) {
return mm == null ? null : new MultiMap(mapValues("uniquify", mm.data));
}
public static MultiMap pairsToMultiMap(List> l) {
MultiMap mm = new MultiMap();
for (Pair p : unnull(l)) mm.put(p.a, p.b);
return mm;
}
public static List> matchX_any_firstAndSecondGroups(String pat, Iterable l) {
Matches m = new Matches();
List> out = new ArrayList();
for (String s : unnull(l)) if (matchX(pat, s, m))
out.add(pair(m.unq(0), m.unq(1)));
return out;
}
public static MultiMap multiMapDiff(MultiMap mm1, MultiMap mm2) {
return pairsToMultiMap(listMinusSet(multiMapToPairs(mm1), multiMapToPairs(mm2)));
}
public static A safeUnstruct(String s) {
return (A) unstructure(s, true);
}
public static Set setDiff(Set l, Collection stuff) {
return setMinusSet(l, stuff);
}
public static int max(int a, int b) {
return Math.max(a, b);
}
public static int max(int a, int b, int c) {
return max(max(a, b), c);
}
public static long max(int a, long b) {
return Math.max((long) a, b);
}
public static long max(long a, long b) {
return Math.max(a, b);
}
public static double max(int a, double b) {
return Math.max((double) a, b);
}
public static float max(float a, float b) {
return Math.max(a, b);
}
public static double max(double a, double b) {
return Math.max(a, b);
}
public static int max(Collection c) {
int x = Integer.MIN_VALUE;
for (int i : c) x = max(x, i);
return x;
}
public static double max(double[] c) {
if (c.length == 0)
return Double.MIN_VALUE;
double x = c[0];
for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]);
return x;
}
public static float max(float[] c) {
if (c.length == 0)
return Float.MAX_VALUE;
float x = c[0];
for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]);
return x;
}
public static byte max(byte[] c) {
byte x = -128;
for (byte d : c) if (d > x)
x = d;
return x;
}
public static short max(short[] c) {
short x = -0x8000;
for (short d : c) if (d > x)
x = d;
return x;
}
public static int max(int[] c) {
int x = Integer.MIN_VALUE;
for (int d : c) if (d > x)
x = d;
return x;
}
public static Map newDangerousWeakHashMap() {
return _registerDangerousWeakMap(synchroMap(new WeakHashMap()));
}
public static Map newDangerousWeakHashMap(Object initFunction) {
return _registerDangerousWeakMap(synchroMap(new WeakHashMap()), initFunction);
}
public static HashMap> callMC_cache = new HashMap();
public static String callMC_key;
public static Method callMC_value;
public static Object callMC(String method, String[] arg) {
return callMC(method, new Object[] { arg });
}
public static Object callMC(String method, Object... args) {
try {
Method me;
if (callMC_cache == null)
callMC_cache = new HashMap();
synchronized (callMC_cache) {
me = method == callMC_key ? callMC_value : null;
}
if (me != null)
try {
return invokeMethod(me, null, args);
} catch (IllegalArgumentException e) {
throw new RuntimeException("Can't call " + me + " with arguments " + classNames(args), e);
}
List m;
synchronized (callMC_cache) {
m = callMC_cache.get(method);
}
if (m == null) {
if (callMC_cache.isEmpty()) {
callMC_makeCache();
m = callMC_cache.get(method);
}
if (m == null)
throw fail("Method named " + method + " not found in main");
}
int n = m.size();
if (n == 1) {
me = m.get(0);
synchronized (callMC_cache) {
callMC_key = method;
callMC_value = me;
}
try {
return invokeMethod(me, null, args);
} catch (IllegalArgumentException e) {
throw new RuntimeException("Can't call " + me + " with arguments " + classNames(args), e);
}
}
for (int i = 0; i < n; i++) {
me = m.get(i);
if (call_checkArgs(me, args, false))
return invokeMethod(me, null, args);
}
throw fail("No method called " + method + " with matching arguments found in main");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static void callMC_makeCache() {
synchronized (callMC_cache) {
callMC_cache.clear();
Class _c = (Class) mc(), c = _c;
while (c != null) {
for (Method m : c.getDeclaredMethods()) if ((m.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0) {
m.setAccessible(true);
multiMapPut(callMC_cache, m.getName(), m);
}
c = c.getSuperclass();
}
}
}
public static String getClassName(Object o) {
return o == null ? "null" : o instanceof Class ? ((Class) o).getName() : o.getClass().getName();
}
public static Object invokeMethod(Method m, Object o, Object... args) {
try {
try {
return m.invoke(o, args);
} catch (InvocationTargetException e) {
throw rethrow(getExceptionCause(e));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(e.getMessage() + " - was calling: " + m + ", args: " + joinWithSpace(classNames(args)));
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static boolean call_checkArgs(Method m, Object[] args, boolean debug) {
Class>[] types = m.getParameterTypes();
if (types.length != args.length) {
if (debug)
System.out.println("Bad parameter length: " + args.length + " vs " + types.length);
return false;
}
for (int i = 0; i < types.length; i++) if (!(args[i] == null || isInstanceX(types[i], args[i]))) {
if (debug)
System.out.println("Bad parameter " + i + ": " + args[i] + " vs " + types[i]);
return false;
}
return true;
}
public static String makeRandomID(int length) {
return makeRandomID(length, defaultRandomGenerator());
}
public static String makeRandomID(int length, Random random) {
char[] id = new char[length];
for (int i = 0; i < id.length; i++) id[i] = (char) ((int) 'a' + random.nextInt(26));
return new String(id);
}
public static Class javax() {
return getJavaX();
}
public static CloseableIterableIterator linesFromFile(File f) {
try {
if (!f.exists())
return emptyCloseableIterableIterator();
if (ewic(f.getName(), ".gz"))
return linesFromReader(utf8bufferedReader(newGZIPInputStream(f)));
return linesFromReader(utf8bufferedReader(f));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static TreeMap caseInsensitiveMap() {
return new TreeMap(caseInsensitiveComparator());
}
public static String getType(Object o) {
return getClassName(o);
}
public static long getFileSize(String path) {
return path == null ? 0 : new File(path).length();
}
public static long getFileSize(File f) {
return f == null ? 0 : f.length();
}
public static volatile boolean ping_pauseAll;
public static int ping_sleep = 100;
public static volatile boolean ping_anyActions;
public static Map ping_actions = newWeakHashMap();
public static ThreadLocal ping_isCleanUpThread = new ThreadLocal();
public static boolean ping() {
if (ping_pauseAll || ping_anyActions)
ping_impl(true);
return true;
}
public static boolean ping_impl(boolean okInCleanUp) {
try {
if (ping_pauseAll && !isAWTThread()) {
do Thread.sleep(ping_sleep); while (ping_pauseAll);
return true;
}
if (ping_anyActions) {
if (!okInCleanUp && !isTrue(ping_isCleanUpThread.get()))
failIfUnlicensed();
Object action = null;
synchronized (ping_actions) {
if (!ping_actions.isEmpty()) {
action = ping_actions.get(currentThread());
if (action instanceof Runnable)
ping_actions.remove(currentThread());
if (ping_actions.isEmpty())
ping_anyActions = false;
}
}
if (action instanceof Runnable)
((Runnable) action).run();
else if (eq(action, "cancelled"))
throw fail("Thread cancelled.");
}
return false;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static boolean eq(Object a, Object b) {
return a == null ? b == null : a == b || b != null && a.equals(b);
}
public static String beautifyStructure(String s) {
List tok = javaTok(s);
structure_addTokenMarkers(tok);
jreplace(tok, "lhm", "");
return join(tok);
}
public static boolean eqic(String a, String b) {
if ((a == null) != (b == null))
return false;
if (a == null)
return true;
return a.equalsIgnoreCase(b);
}
public static boolean eqic(char a, char b) {
if (a == b)
return true;
char u1 = Character.toUpperCase(a);
char u2 = Character.toUpperCase(b);
if (u1 == u2)
return true;
return Character.toLowerCase(u1) == Character.toLowerCase(u2);
}
public static int indexOfIgnoreCase_manual(String a, String b) {
int la = l(a), lb = l(b);
if (la < lb)
return -1;
int n = la - lb;
loop: for (int i = 0; i <= n; i++) {
for (int j = 0; j < lb; j++) {
char c1 = a.charAt(i + j), c2 = b.charAt(j);
if (!eqic(c1, c2))
continue loop;
}
return i;
}
return -1;
}
public static A getOpt(Object o, String field) {
return (A) getOpt_cached(o, field);
}
public static A getOpt(String field, Object o) {
return (A) getOpt_cached(o, field);
}
public static Object getOpt_raw(Object o, String field) {
try {
Field f = getOpt_findField(o.getClass(), field);
if (f == null)
return null;
f.setAccessible(true);
return f.get(o);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static A getOpt(Class c, String field) {
try {
if (c == null)
return null;
Field f = getOpt_findStaticField(c, field);
if (f == null)
return null;
f.setAccessible(true);
return (A) f.get(null);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static Field getOpt_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
return null;
}
public static List mapToLines(Map map) {
List l = new ArrayList();
for (Object key : keys(map)) l.add(str(key) + " = " + str(map.get(key)));
return l;
}
public static A optParam(ThreadLocal tl, A defaultValue) {
return optPar(tl, defaultValue);
}
public static A optParam(ThreadLocal tl) {
return optPar(tl);
}
public static A optParam(Object[] opt, String name, A defaultValue) {
if (!even(l(opt)))
throw fail("Odd parameter length");
for (int i = 0; i < l(opt); i += 2) if (eq(opt[i], name))
return (A) opt[i + 1];
return defaultValue;
}
public static A optParam(Object[] opt, String name) {
return optParam(opt, name, null);
}
public static void assertTrue(Object o) {
if (!(eq(o, true)))
throw fail(str(o));
}
public static boolean assertTrue(String msg, boolean b) {
if (!b)
throw fail(msg);
return b;
}
public static boolean assertTrue(boolean b) {
if (!b)
throw fail("oops");
return b;
}
public static List synchroList() {
return Collections.synchronizedList(new ArrayList ());
}
public static List synchroList(List l) {
return Collections.synchronizedList(l);
}
public static List ll(A... a) {
ArrayList l = new ArrayList(a.length);
for (A x : a) l.add(x);
return l;
}
public static PersistableThrowable persistableThrowable(Throwable e) {
return e == null ? null : new PersistableThrowable(e);
}
public static Throwable innerException(Throwable e) {
return getInnerException(e);
}
public static Object callOpt(Object o) {
return callF(o);
}
public static A callOpt(Object o, String method, Object... args) {
return (A) callOpt_cached(o, method, args);
}
public static List ai_ruleEngine2_rulesForInput_5(RuleEngine2 engine, Map inputsByType, Object... __) {
List l = new ArrayList();
for (RuleEngine2.Rule rule : engine.rules) {
if (rule instanceof RuleEngine2.SimplifyWithRule) {
if (((RuleEngine2.SimplifyWithRule) rule).isSplitRule)
continue;
String in = inputsByType.get("standard");
Object f = ((RuleEngine2.SimplifyWithRule) rule).function();
Object arg = ((RuleEngine2.SimplifyWithRule) rule).callOnTree ? optPar("tree", __) : in;
if (arg == null)
continue;
Object result = f instanceof String ? arg instanceof String ? callF(engine.callFunctionOnString, (String) f, arg) : callAndMake((String) f, arg) : callF(f, arg);
if (result == null)
continue;
List list = result instanceof Collection ? allToString((Collection) result) : ll(str(result));
for (String x : list) {
if (nempty(x) && neq(x, in)) {
final RuleEngine2_MatchedRule matched = new RuleEngine2_MatchedRule();
matched.rule = ((RuleEngine2.SimplifyWithRule) rule);
matched.out = x;
l.add(matched);
}
}
continue;
}
final RuleEngine2_MatchedRule matched = new RuleEngine2_MatchedRule();
matched.rule = rule;
matched.map = ciMap();
matched.tokenizationFunction = or(matchAny_firstGroup("tokenize with *", rule.comments), "javaTokNPunctuationWithBrackets");
if (!ai_ruleEngine2_matchStep(matched, inputsByType, true))
continue;
l.add(matched);
}
return l;
}
public static boolean boolPar(ThreadLocal tl) {
return boolOptParam(tl);
}
public static boolean boolPar(Object[] __, String name) {
return boolOptParam(__, name);
}
public static boolean boolPar(String name, Object[] __) {
return boolOptParam(__, name);
}
public static boolean boolPar(String name, Object[] params, boolean defaultValue) {
return optParam(params, name, defaultValue);
}
public static boolean ai_ruleEngine2_matchStep(final RuleEngine2_MatchedRule matched, Map inputsByType, boolean fillRemainingConditions) {
RuleEngine2.Rule rule = matched.rule;
TextAndType in = rule.insWithType.get(matched.iCond);
matched.iCond++;
String cond = in.text;
String tokenize = matched.tokenizationFunction;
List tokC = (List) callAndMake(tokenize, cond);
String input = inputsByType.get(in.type);
if (input == null)
return false;
List tokI = (List