Warning : session_start(): open(/var/lib/php/sessions/sess_utoajuc7b9cgu8pho31lrucu7n, 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 x30_pkg.x30_util;
import static x30_pkg.x30_util.VF1;
import static x30_pkg.x30_util.l;
import static x30_pkg.x30_util.fail;
import static x30_pkg.x30_util.indexOf;
import static x30_pkg.x30_util.getOpt;
import static x30_pkg.x30_util.setOpt;
import static x30_pkg.x30_util.callOpt;
import static x30_pkg.x30_util.newWeakHashMap;
import static x30_pkg.x30_util.newDangerousWeakHashMap;
import static x30_pkg.x30_util.get;
import static x30_pkg.x30_util.get_raw;
import static x30_pkg.x30_util.assertTrue;
import static x30_pkg.x30_util.isHeadless;
import static x30_pkg.x30_util.isAndroid;
import static x30_pkg.x30_util.isTrue;
import static x30_pkg.x30_util.asList;
import x30_pkg.x30_util.DynamicObject;
import loadableUtils.utils;
import static loadableUtils.utils._threadInfo;
import static loadableUtils.utils._threadInheritInfo;
import static loadableUtils.utils._threadInfo_addMakerAndRetriever;
import static loadableUtils.utils.dm_currentModule;
import static loadableUtils.utils.dm_current_mandatory;
import static loadableUtils.utils.match;
import static loadableUtils.utils.getOpt_raw;
import static loadableUtils.utils.setOpt_raw;
import static loadableUtils.utils.getField;
import static loadableUtils.utils.fieldType;
import static loadableUtils.utils.format3;
import static loadableUtils.utils.vm_generalIdentityHashSet;
import static loadableUtils.utils.vm_generalHashMap;
import static loadableUtils.utils.vm_generalWeakSubMap;
import static loadableUtils.utils.bindToComponent;
import static loadableUtils.utils.struct;
import static loadableUtils.utils.structure;
import static loadableUtils.utils.loadPage;
import static loadableUtils.utils.loadPage_utf8;
import static loadableUtils.utils.loadPageSilentlyWithTimeout;
import static loadableUtils.utils.loadPageSilently;
import static loadableUtils.utils.loadSnippet;
import static loadableUtils.utils.loadSnippetQuietly;
import static loadableUtils.utils.sendToLocalBot;
import static loadableUtils.utils.componentPopupMenu;
import static loadableUtils.utils.componentPopupMenu_top;
import static loadableUtils.utils.componentPopupMenu_initForComponent;
import static loadableUtils.utils.componentPopupMenu_getEvent;
import static loadableUtils.utils.listPopupMenu;
import static loadableUtils.utils.tablePopupMenu;
import static loadableUtils.utils.rowSorter_setComparators;
import static loadableUtils.utils.sexyTableWithoutDrag;
import static loadableUtils.utils.dm_current_generic;
import static loadableUtils.utils.dm_current_mandatory_generic;
import static loadableUtils.utils.cset;
import static loadableUtils.utils.DynamicObject_loading;
import static loadableUtils.utils.concepts_unlisted;
import static loadableUtils.utils.makePopupMenuConditional;
import static loadableUtils.utils.makeConceptsTable_idWidth;
import static loadableUtils.utils.showConceptsTable_afterUpdate;
import static loadableUtils.utils.dynamicObjectIsLoading;
import loadableUtils.utils.F0;
import loadableUtils.utils.F1;
import loadableUtils.utils.IF1;
import loadableUtils.utils.Matches;
import loadableUtils.utils.BetterLabel;
import loadableUtils.utils.SingleComponentPanel;
import loadableUtils.utils.Snippet;
import loadableUtils.utils.Q;
import loadableUtils.utils.ImageSurface;
import loadableUtils.utils.structure_Data;
import loadableUtils.utils.structure_ClassInfo;
import loadableUtils.utils.RGBImage;
import loadableUtils.utils.RGB;
import loadableUtils.utils.BWImage;
import loadableUtils.utils.MakesBufferedImage;
import loadableUtils.utils.MultiSet;
import loadableUtils.utils.Concept;
import loadableUtils.utils.Concepts;
import loadableUtils.utils.IConceptIndex;
import loadableUtils.utils.IFieldIndex;
import loadableUtils.utils.Derefable;
import loadableUtils.utils.ImageSurfaceSelector;
import loadableUtils.utils.SimpleCRUD;
import loadableUtils.utils.PersistableThrowable;
import loadableUtils.utils.DynModule;
import loadableUtils.utils.DynPrintLog;
import loadableUtils.utils.DynObjectTable;
import loadableUtils.utils.DynImageSurface;
import loadableUtils.utils.DynCalculatedList;
import loadableUtils.utils.Rect;
import loadableUtils.utils.Pt;
import java.text.NumberFormat;
class main {
public static class PhilosophyBot2 extends DynPrintLog {
public transient List unmappedLines = ll("good", "early morning");
public transient List unmappedQuestions = ll("what is the time", "how do you feel");
public transient Map mappings = ciMap();
public transient String program = "\r\n start\n \n start => proc {\n run (proc {\r\n while (there are unmapped questions):\r\n find (an unmapped question) x\r\n find (an unmapped line) y\r\n map x to y\r\n }\r) with backtracking\r\n }\n ";
public transient PhilosophyBot1 bot = new PhilosophyBot1();
public void start() {
super.start();
startThread("Start", new Runnable() {
public void run() {
try {
AutoCloseable __7 = enter();
try {
bot.program = program;
bot.addNativePredicate("there are unmapped questions", () -> nempty(unmappedQuestions));
bot.addNativePredicate("find (an unmapped question) x", (map, env) -> {
print("find unmapped question x");
return randomChoiceFromChangingList("x", unmappedQuestions, env);
});
bot.addNativePredicate("find (an unmapped line) z", (map, env) -> {
print("find unmapped line z");
return randomChoiceFromChangingList("z", unmappedLines, env);
});
bot.addNativePredicate("map x to y", (map, env) -> {
String x = map.get("x"), y = map.get("y");
unmappedQuestions.remove(x);
unmappedLines.remove(y);
print("Remaining unmapped questions: " + l(unmappedQuestions));
mappings.put(x, y);
print("Mapped question " + quote(x) + " to answer " + quote(y));
return !env.wantAlternatives() ? true : new PhilosophyBot1.WithAlternative(() -> {
print("Undoing mapping of " + quote(x) + " to answer " + quote(y));
unmappedQuestions.add(x);
unmappedLines.add(y);
return false;
}, true);
});
bot.addNativePredicate("run x with backtracking", (Map map) -> {
String x = map.get("x");
print("Run x with backtracking: " + x);
bot.runParsedProcedure(bot.parseProcedure(x));
print("Ran x with backtracking: " + x);
return true;
});
bot.run();
} finally {
_close(__7);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "AutoCloseable __7 = enter(); try { \r\n bot.program = program;\r\n bot.addN...";
}
});
}
public Object randomChoiceFromChangingList(String var, Collection list, PhilosophyBot1.Env env) {
if (empty(unmappedLines))
return false;
if (!env.wantAlternatives())
return litcimap(var, random(list));
return lazyMap(cloneList(list), z -> litcimap(var, z));
}
}
public static boolean _moduleClass_PhilosophyBot2 = true;
public static Object callF(Object f, Object... args) {
try {
if (f instanceof String)
return callMC((String) f, args);
return x30_util.callF(f, args);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static A callF(F0 f) {
return f == null ? null : f.get();
}
public static A callF(IF0 f) {
return f == null ? null : f.get();
}
public static B callF(F1 f, A a) {
return f == null ? null : f.get(a);
}
public static B callF(IF1 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 callMC(String method, Object... args) {
return call(mc(), method, args);
}
public static Object call(Object o) {
return callF(o);
}
public static Object call(Object o, String method, Object... args) {
return call_withVarargs(o, method, args);
}
public static void _onLoad_initUtils() {
utils.__javax = javax();
}
public static void _onLoad_defaultClassFinder() {
setDefaultClassFinder(new F1() {
public Class get(String name) {
try {
Class c = findClass_fullName(name);
if (c != null)
return c;
if (startsWith(name, "main$"))
return loadableUtils.utils.findClass_fullName("loadableUtils.utils" + substring(name, 4));
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Class c = findClass_fullName(name);\r\n if (c != null) ret c;\r\n if (start...";
}
});
}
public static String programID() {
return getProgramID();
}
public static String programID(Object o) {
return getProgramID(o);
}
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 = false;
public static Object print_byThread_lock = new Object();
public static volatile ThreadLocal print_byThread;
public static volatile Object print_allThreads;
public static volatile Object print_preprocess;
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 = getThreadLocal(print_byThread_dontCreate());
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) {
if (print_preprocess != null)
s = (String) callF(print_preprocess, 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 void print_autoRotate() {
}
public static AutoCloseable tempInterceptPrintIfNotIntercepted(F1 f) {
return print_byThread().get() == null ? tempInterceptPrint(f) : null;
}
public static List ll(A... a) {
ArrayList l = new ArrayList(a.length);
if (a != null)
for (A x : a) l.add(x);
return l;
}
public static TreeMap ciMap() {
return caseInsensitiveMap();
}
public static Thread startThread(Object runnable) {
return startThread(defaultThreadName(), runnable);
}
public static Thread startThread(String name, Object runnable) {
runnable = wrapAsActivity(runnable);
return startThread(newThread(toRunnable(runnable), name));
}
public static Thread startThread(Thread t) {
_registerThread(t);
t.start();
return t;
}
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 String quote(Object o) {
if (o == null)
return "null";
return quote(str(o));
}
public static String quote(String s) {
if (s == null)
return "null";
StringBuilder out = new StringBuilder((int) (l(s) * 1.5 + 2));
quote_impl(s, out);
return out.toString();
}
public static void quote_impl(String s, StringBuilder out) {
out.append('"');
int l = s.length();
for (int i = 0; i < l; i++) {
char c = s.charAt(i);
if (c == '\\' || c == '"')
out.append('\\').append(c);
else if (c == '\r')
out.append("\\r");
else if (c == '\n')
out.append("\\n");
else if (c == '\0')
out.append("\\0");
else
out.append(c);
}
out.append('"');
}
public static void _close(AutoCloseable c) {
if (c != null)
try {
c.close();
} catch (Throwable e) {
if (c instanceof javax.imageio.stream.ImageOutputStream)
return;
else
throw rethrow(e);
}
}
public static RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
public static RuntimeException rethrow(String msg, Throwable t) {
throw new RuntimeException(msg, t);
}
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(Iterator i) {
return i == null || !i.hasNext();
}
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(short[] a) {
return a == null || a.length == 0;
}
public static boolean empty(MultiSet ms) {
return ms == null || ms.isEmpty();
}
public static boolean empty(File f) {
return getFileSize(f) == 0;
}
public static TreeMap litcimap(Object... x) {
return litCIMap(x);
}
public static Random random_random = new Random();
public static int random(int n) {
return random(random_random, n);
}
public static int random(Random r, int n) {
return n <= 0 ? 0 : r.nextInt(n);
}
public static double random(double max) {
return random() * max;
}
public static double random() {
return random_random.nextInt(100001) / 100000.0;
}
public static double random(double min, double max) {
return min + random() * (max - min);
}
public static int random(int min, int max) {
return min + random(max - min);
}
public static int random(Random r, int min, int max) {
return min + random(r, max - min);
}
public static A random(List l) {
return oneOf(l);
}
public static A random(Collection c) {
if (c instanceof List)
return random((List ) c);
int i = random(l(c));
return collectionGet(c, i);
}
public static List lazyMap(final Object f, final List l) {
return lazilyMap(f, l);
}
public static List lazyMap(List l, IF1 f) {
return lazilyMap(f, l);
}
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 Class mc() {
return main.class;
}
public static Object call_withVarargs(Object o, String method, Object... args) {
try {
if (o == null)
return null;
if (o instanceof Class) {
Class c = (Class) o;
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findStaticMethod(method, args);
if (me != null)
return invokeMethod(me, null, args);
List methods = cache.cache.get(method);
if (methods != null)
methodSearch: for (Method m : methods) {
{
if (!(m.isVarArgs()))
continue;
}
{
if (!(isStaticMethod(m)))
continue;
}
Object[] newArgs = massageArgsForVarArgsCall(m, args);
if (newArgs != null)
return invokeMethod(m, null, newArgs);
}
throw fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not found");
} else {
Class c = o.getClass();
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(method, args);
if (me != null)
return invokeMethod(me, o, args);
List methods = cache.cache.get(method);
if (methods != null)
methodSearch: for (Method m : methods) {
{
if (!(m.isVarArgs()))
continue;
}
Object[] newArgs = massageArgsForVarArgsCall(m, args);
if (newArgs != null)
return invokeMethod(m, o, newArgs);
}
throw fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not found in " + c);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static Class javax() {
return getJavaX();
}
public static void setDefaultClassFinder(Object cf) {
_defaultClassFinder_value = cf;
}
public static HashMap findClass_fullName_cache = new HashMap();
public static Class findClass_fullName(String name) {
synchronized (findClass_fullName_cache) {
if (findClass_fullName_cache.containsKey(name))
return findClass_fullName_cache.get(name);
Class c;
try {
c = Class.forName(name);
} catch (ClassNotFoundException e) {
c = null;
}
findClass_fullName_cache.put(name, c);
return c;
}
}
public static boolean startsWith(String a, String b) {
return a != null && a.startsWith(b);
}
public static boolean startsWith(String a, char c) {
return nemptyString(a) && a.charAt(0) == c;
}
public static boolean startsWith(String a, String b, Matches m) {
if (!startsWith(a, b))
return false;
m.m = new String[] { substring(a, strL(b)) };
return true;
}
public static boolean startsWith(List a, List b) {
if (a == null || listL(b) > listL(a))
return false;
for (int i = 0; i < listL(b); i++) if (neq(a.get(i), b.get(i)))
return false;
return true;
}
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 String substring(String s, IntRange r) {
return r == null ? null : substring(s, r.start, r.end);
}
public static Object _defaultClassFinder_value = defaultDefaultClassFinder();
public static Object _defaultClassFinder() {
return _defaultClassFinder_value;
}
public static String programID;
public static String getProgramID() {
return nempty(programID) ? formatSnippetIDOpt(programID) : "?";
}
public static String getProgramID(Class c) {
String id = (String) getOpt(c, "programID");
if (nempty(id))
return formatSnippetID(id);
return "?";
}
public static String getProgramID(Object o) {
return getProgramID(getMainClass(o));
}
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 Object getThreadLocal(Object o, String name) {
ThreadLocal t = (ThreadLocal) (getOpt(o, name));
return t != null ? t.get() : null;
}
public static A getThreadLocal(ThreadLocal tl) {
return tl == null ? null : tl.get();
}
public static A getThreadLocal(ThreadLocal tl, A defaultValue) {
return or(getThreadLocal(tl), defaultValue);
}
public static ThreadLocal print_byThread_dontCreate() {
return print_byThread;
}
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 StringBuffer)
rotateStringBuffer(((StringBuffer) buf), max);
else if (buf instanceof StringBuilder)
rotateStringBuilder(((StringBuilder) buf), max);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static ThreadLocal print_byThread() {
synchronized (print_byThread_lock) {
if (print_byThread == null)
print_byThread = new ThreadLocal();
}
return print_byThread;
}
public static AutoCloseable tempInterceptPrint(F1 f) {
return tempSetThreadLocal(print_byThread(), f);
}
public static TreeMap caseInsensitiveMap() {
return new TreeMap(caseInsensitiveComparator());
}
public static String defaultThreadName_name;
public static String defaultThreadName() {
if (defaultThreadName_name == null)
defaultThreadName_name = "A thread by " + programID();
return defaultThreadName_name;
}
public static Runnable wrapAsActivity(Object r) {
return toRunnable(r);
}
public static Thread newThread(Object runnable) {
return new Thread(_topLevelErrorHandling(toRunnable(runnable)));
}
public static Thread newThread(Object runnable, String name) {
if (name == null)
name = defaultThreadName();
return new Thread(_topLevelErrorHandling(toRunnable(runnable)), name);
}
public static Thread newThread(String name, Object runnable) {
return newThread(runnable, name);
}
public static Runnable toRunnable(final Object o) {
if (o instanceof Runnable)
return (Runnable) o;
return new Runnable() {
public void run() {
try {
callF(o);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(o)";
}
};
}
public static Map _registerThread_threads;
public static Object _onRegisterThread;
public static Thread _registerThread(Thread t) {
if (_registerThread_threads == null)
_registerThread_threads = newWeakHashMap();
_registerThread_threads.put(t, true);
vm_generalWeakSubMap("thread2mc").put(t, weakRef(mc()));
callF(_onRegisterThread, t);
return t;
}
public static void _registerThread() {
_registerThread(Thread.currentThread());
}
public static String str(Object o) {
return o == null ? "null" : o.toString();
}
public static String str(char[] c) {
return new String(c);
}
public static void _handleError(Error e) {
call(javax(), "_handleError", e);
}
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 TreeMap litCIMap(Object... x) {
TreeMap map = caseInsensitiveMap();
litmap_impl(map, x);
return map;
}
public static A oneOf(List l) {
return empty(l) ? null : l.get(new Random().nextInt(l.size()));
}
public static char oneOf(String s) {
return empty(s) ? '?' : s.charAt(random(l(s)));
}
public static String oneOf(String... l) {
return oneOf(asList(l));
}
public static A collectionGet(Collection c, int idx) {
if (c == null || idx < 0 || idx >= l(c))
return null;
if (c instanceof List)
return listGet((List ) c, idx);
Iterator it = c.iterator();
for (int i = 0; i < idx; i++) if (it.hasNext())
it.next();
else
return null;
return it.hasNext() ? it.next() : null;
}
public static List lazilyMap(final Object f, final List l) {
return new RandomAccessAbstractList() {
public final int size = l(l);
public HashMap data = new HashMap();
public int size() {
return size;
}
public Object get(int i) {
if (data.containsKey(i))
return data.get(i);
Object o = callF(f, l.get(i));
data.put(i, o);
return o;
}
};
}
public static Object collectionMutex(List l) {
return l;
}
public static Object collectionMutex(Object o) {
if (o instanceof List)
return o;
String c = className(o);
if (eq(c, "java.util.TreeMap$KeySet"))
c = className(o = getOpt(o, "m"));
else if (eq(c, "java.util.HashMap$KeySet"))
c = className(o = get_raw(o, "this$0"));
if (eqOneOf(c, "java.util.TreeMap$AscendingSubMap", "java.util.TreeMap$DescendingSubMap"))
c = className(o = get_raw(o, "m"));
return o;
}
public static final Map callOpt_cache = newDangerousWeakHashMap();
public static Object callOpt_cached(Object o, String methodName, Object... args) {
try {
if (o == null)
return null;
if (o instanceof Class) {
Class c = (Class) o;
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(methodName, args);
if (me == null || (me.getModifiers() & Modifier.STATIC) == 0)
return null;
return invokeMethod(me, null, args);
} else {
Class c = o.getClass();
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(methodName, args);
if (me == null)
return null;
return invokeMethod(me, o, args);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static _MethodCache callOpt_getCache(Class c) {
synchronized (callOpt_cache) {
_MethodCache cache = callOpt_cache.get(c);
if (cache == null)
callOpt_cache.put(c, cache = new _MethodCache(c));
return cache;
}
}
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 isStaticMethod(Method m) {
return methodIsStatic(m);
}
public static Object[] massageArgsForVarArgsCall(Method m, Object[] args) {
Class>[] types = m.getParameterTypes();
int n = types.length - 1, nArgs = args.length;
if (nArgs < n)
return null;
for (int i = 0; i < n; i++) if (!argumentCompatibleWithType(args[i], types[i]))
return null;
Class varArgType = types[n].getComponentType();
for (int i = n; i < nArgs; i++) if (!argumentCompatibleWithType(args[i], varArgType))
return null;
Object[] newArgs = new Object[n + 1];
arraycopy(args, 0, newArgs, 0, n);
Object[] varArgs = arrayOfType(varArgType, nArgs - n);
arraycopy(args, n, varArgs, 0, nArgs - n);
newArgs[n] = varArgs;
return newArgs;
}
public static String joinWithComma(Collection c) {
return join(", ", c);
}
public static String joinWithComma(String... c) {
return join(", ", c);
}
public static String joinWithComma(Pair p) {
return p == null ? "" : joinWithComma(str(p.a), str(p.b));
}
public static List classNames(Collection l) {
return getClassNames(l);
}
public static List classNames(Object[] l) {
return getClassNames(Arrays.asList(l));
}
public static Class __javax;
public static Class getJavaX() {
try {
return __javax;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static boolean nemptyString(String s) {
return s != null && s.length() > 0;
}
public static int strL(String s) {
return s == null ? 0 : s.length();
}
public static int listL(Collection l) {
return l == null ? 0 : l.size();
}
public static boolean neq(Object a, Object b) {
return !eq(a, b);
}
public static Object defaultDefaultClassFinder() {
return new F1() {
public Class get(String name) {
try {
Class c = findClass_fullName(name);
if (c != null)
return c;
if (startsWith(name, "loadableUtils.utils$"))
return findClass_fullName("main" + substring(name, 19));
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Class c = findClass_fullName(name);\r\n if (c != null) ret c;\r\n if (start...";
}
};
}
public static String formatSnippetIDOpt(String s) {
return isSnippetID(s) ? formatSnippetID(s) : s;
}
public static String formatSnippetID(String id) {
return "#" + parseSnippetID(id);
}
public static String formatSnippetID(long id) {
return "#" + id;
}
public static Class getMainClass() {
return mc();
}
public static Class getMainClass(Object o) {
try {
if (o == null)
return null;
if (o instanceof Class && eq(((Class) o).getName(), "x30"))
return (Class) o;
return (o instanceof Class ? (Class) o : o.getClass()).getClassLoader().loadClass("main");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static volatile boolean ping_pauseAll = false;
public static int ping_sleep = 100;
public static volatile boolean ping_anyActions = false;
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 A or(A a, A b) {
return a != null ? a : b;
}
public static boolean eq(Object a, Object b) {
return a == b || (a == null ? b == null : b != null && a.equals(b));
}
public static void rotateStringBuffer(StringBuffer buf, int max) {
try {
if (buf == null)
return;
synchronized (buf) {
if (buf.length() <= max)
return;
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);
}
buf.trimToSize();
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static void rotateStringBuilder(StringBuilder buf, int max) {
try {
if (buf == null)
return;
synchronized (buf) {
if (buf.length() <= max)
return;
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);
}
buf.trimToSize();
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static AutoCloseable tempSetThreadLocal(final ThreadLocal tl, A a) {
if (tl == null)
return null;
final A prev = setThreadLocal(tl, a);
return new AutoCloseable() {
public String toString() {
return "tl.set(prev);";
}
public void close() throws Exception {
tl.set(prev);
}
};
}
public static Comparator caseInsensitiveComparator() {
return betterCIComparator();
}
public static Runnable _topLevelErrorHandling(final Runnable runnable) {
final Object info = _threadInfo();
return new Runnable() {
public void run() {
try {
try {
_threadInheritInfo(info);
runnable.run();
} catch (Throwable __e) {
_handleException(__e);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "pcall {\r\n _threadInheritInfo(info);\r\n runnable.run();\r\n }";
}
};
}
public static WeakReference weakRef(A a) {
return newWeakReference(a);
}
public static String getClassName(Object o) {
return o == null ? "null" : o instanceof Class ? ((Class) o).getName() : o.getClass().getName();
}
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) {
if (x != null)
for (int i = 0; i < x.length - 1; i += 2) if (x[i + 1] != null)
map.put(x[i], x[i + 1]);
}
public static A listGet(List l, int idx) {
return l != null && idx >= 0 && idx < l(l) ? l.get(idx) : null;
}
public static String className(Object o) {
return getClassName(o);
}
public static boolean eqOneOf(Object o, Object... l) {
for (Object x : l) if (eq(o, x))
return true;
return false;
}
public static Throwable getExceptionCause(Throwable e) {
Throwable c = e.getCause();
return c != null ? c : e;
}
public static String joinWithSpace(Collection c) {
return join(" ", c);
}
public static String joinWithSpace(String... c) {
return join(" ", c);
}
public static boolean methodIsStatic(Method m) {
return (m.getModifiers() & Modifier.STATIC) != 0;
}
public static boolean argumentCompatibleWithType(Object arg, Class type) {
return arg == null ? !type.isPrimitive() : isInstanceX(type, arg);
}
public static void arraycopy(Object[] a, Object[] b) {
if (a != null && b != null)
arraycopy(a, 0, b, 0, min(a.length, b.length));
}
public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int n) {
if (n != 0)
System.arraycopy(src, srcPos, dest, destPos, n);
}
public static A[] arrayOfType(Class type, int n) {
return makeArray(type, n);
}
public static A[] arrayOfType(int n, Class type) {
return arrayOfType(type, n);
}
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 List getClassNames(Collection l) {
List out = new ArrayList();
if (l != null)
for (Object o : l) out.add(o == null ? null : getClassName(o));
return out;
}
public static boolean isSnippetID(String s) {
try {
parseSnippetID(s);
return true;
} catch (RuntimeException e) {
return false;
}
}
public static long parseSnippetID(String snippetID) {
long id = Long.parseLong(shortenSnippetID(snippetID));
if (id == 0)
throw fail("0 is not a snippet ID");
return id;
}
public static boolean isAWTThread() {
if (isAndroid())
return false;
if (isHeadless())
return false;
return isAWTThread_awt();
}
public static boolean isAWTThread_awt() {
return SwingUtilities.isEventDispatchThread();
}
public static void failIfUnlicensed() {
assertTrue("license off", licensed());
}
public static Thread currentThread() {
return Thread.currentThread();
}
public static A setThreadLocal(ThreadLocal tl, A value) {
if (tl == null)
return null;
A old = tl.get();
tl.set(value);
return old;
}
public static betterCIComparator_C betterCIComparator_instance;
public static betterCIComparator_C betterCIComparator() {
if (betterCIComparator_instance == null)
betterCIComparator_instance = new betterCIComparator_C();
return betterCIComparator_instance;
}
public static class betterCIComparator_C implements Comparator {
public int compare(String s1, String s2) {
if (s1 == null)
return s2 == null ? 0 : -1;
if (s2 == null)
return 1;
int n1 = s1.length();
int n2 = s2.length();
int min = Math.min(n1, n2);
for (int i = 0; i < min; i++) {
char c1 = s1.charAt(i);
char c2 = s2.charAt(i);
if (c1 != c2) {
c1 = Character.toUpperCase(c1);
c2 = Character.toUpperCase(c2);
if (c1 != c2) {
c1 = Character.toLowerCase(c1);
c2 = Character.toLowerCase(c2);
if (c1 != c2) {
return c1 - c2;
}
}
}
}
return n1 - n2;
}
}
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 WeakReference newWeakReference(A a) {
return a == null ? null : new WeakReference(a);
}
public static boolean isInstanceX(Class type, Object arg) {
if (type == boolean.class)
return arg instanceof Boolean;
if (type == int.class)
return arg instanceof Integer;
if (type == long.class)
return arg instanceof Long;
if (type == float.class)
return arg instanceof Float;
if (type == short.class)
return arg instanceof Short;
if (type == char.class)
return arg instanceof Character;
if (type == byte.class)
return arg instanceof Byte;
if (type == double.class)
return arg instanceof Double;
return type.isInstance(arg);
}
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 A[] makeArray(Class type, int n) {
return (A[]) Array.newInstance(type, n);
}
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 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 shortenSnippetID(String snippetID) {
if (snippetID.startsWith("#"))
snippetID = snippetID.substring(1);
String httpBlaBla = "http://tinybrain.de/";
if (snippetID.startsWith(httpBlaBla))
snippetID = snippetID.substring(httpBlaBla.length());
return "" + parseLong(snippetID);
}
public static volatile boolean licensed_yes = true;
public static boolean licensed() {
if (!licensed_yes)
return false;
ping_okInCleanUp();
return true;
}
public static void licensed_off() {
licensed_yes = false;
}
public static List synchroList() {
return Collections.synchronizedList(new ArrayList ());
}
public static List synchroList(List l) {
return Collections.synchronizedList(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 String getStackTrace2(Throwable e) {
return hideCredentials(getStackTrace(unwrapTrivialExceptionWraps(e)) + replacePrefix("java.lang.RuntimeException: ", "FAIL: ", hideCredentials(str(innerException2(e)))) + "\n");
}
public static long parseLong(String s) {
if (empty(s))
return 0;
return Long.parseLong(dropSuffix("L", s));
}
public static long parseLong(Object s) {
return Long.parseLong((String) s);
}
public static Throwable getInnerException(Throwable e) {
if (e == null)
return null;
while (e.getCause() != null) e = e.getCause();
return e;
}
public static Throwable getInnerException(Runnable r) {
return getInnerException(getException(r));
}
public static String hideCredentials(URL url) {
return url == null ? null : hideCredentials(str(url));
}
public static String hideCredentials(String url) {
try {
if (startsWithOneOf(url, "http://", "https://") && isAGIBlueDomain(hostNameFromURL(url)))
return url;
} catch (Throwable e) {
print("HideCredentials", e);
}
return url.replaceAll("([&?])(_pass|key)=[^&\\s\"]*", "$1$2=");
}
public static String hideCredentials(Object o) {
return hideCredentials(str(o));
}
public static String getStackTrace(Throwable throwable) {
lastException(throwable);
return getStackTrace_noRecord(throwable);
}
public static String getStackTrace_noRecord(Throwable throwable) {
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
return hideCredentials(writer.toString());
}
public static String getStackTrace() {
return getStackTrace_noRecord(new Throwable());
}
public static Throwable unwrapTrivialExceptionWraps(Throwable e) {
if (e == null)
return e;
while (e.getClass() == RuntimeException.class && e.getCause() != null && eq(e.getMessage(), str(e.getCause()))) e = e.getCause();
return e;
}
public static String replacePrefix(String prefix, String replacement, String s) {
if (!startsWith(s, prefix))
return s;
return replacement + substring(s, l(prefix));
}
public static Throwable innerException2(Throwable e) {
if (e == null)
return null;
while (empty(e.getMessage()) && e.getCause() != null) e = e.getCause();
return e;
}
public static String dropSuffix(String suffix, String s) {
return s.endsWith(suffix) ? s.substring(0, l(s) - l(suffix)) : s;
}
public static Throwable getException(Runnable r) {
try {
callF(r);
return null;
} catch (Throwable e) {
return e;
}
}
public static boolean startsWithOneOf(String s, String... l) {
for (String x : l) if (startsWith(s, x))
return true;
return false;
}
public static boolean isAGIBlueDomain(String domain) {
return domainIsUnder(domain, theAGIBlueDomain());
}
public static String hostNameFromURL(String url) {
try {
return new URL(url).getHost();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static volatile PersistableThrowable lastException_lastException;
public static PersistableThrowable lastException() {
return lastException_lastException;
}
public static void lastException(Throwable e) {
lastException_lastException = persistableThrowable(e);
}
public static boolean domainIsUnder(String domain, String mainDomain) {
return eqic(domain, mainDomain) || ewic(domain, "." + mainDomain);
}
public static String theAGIBlueDomain() {
return "agi.blue";
}
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 boolean ewic(String a, String b) {
return endsWithIgnoreCase(a, b);
}
public static boolean ewic(String a, String b, Matches m) {
return endsWithIgnoreCase(a, b, m);
}
public static String asString(Object o) {
return o == null ? null : o.toString();
}
public static boolean endsWithIgnoreCase(String a, String b) {
int la = l(a), lb = l(b);
return la >= lb && regionMatchesIC(a, la - lb, b, 0, lb);
}
public static boolean endsWithIgnoreCase(String a, String b, Matches m) {
if (!endsWithIgnoreCase(a, b))
return false;
m.m = new String[] { substring(a, 0, l(a) - l(b)) };
return true;
}
public static boolean regionMatchesIC(String a, int offsetA, String b, int offsetB, int len) {
return a != null && a.regionMatches(true, offsetA, b, offsetB, len);
}
public static final class _MethodCache {
public final Class c;
public final HashMap> cache = new HashMap();
public _MethodCache(Class c) {
this.c = c;
_init();
}
public void _init() {
Class _c = c;
while (_c != null) {
for (Method m : _c.getDeclaredMethods()) if (!reflection_isForbiddenMethod(m))
multiMapPut(cache, m.getName(), makeAccessible(m));
_c = _c.getSuperclass();
}
for (Class intf : allInterfacesImplementedBy(c)) for (Method m : intf.getDeclaredMethods()) if (m.isDefault() && !reflection_isForbiddenMethod(m))
multiMapPut(cache, m.getName(), makeAccessible(m));
}
public Method findMethod(String method, Object[] args) {
try {
List m = cache.get(method);
if (m == null)
return null;
int n = m.size();
for (int i = 0; i < n; i++) {
Method me = m.get(i);
if (call_checkArgs(me, args, false))
return me;
}
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public Method findStaticMethod(String method, Object[] args) {
try {
List m = cache.get(method);
if (m == null)
return null;
int n = m.size();
for (int i = 0; i < n; i++) {
Method me = m.get(i);
if (isStaticMethod(me) && call_checkArgs(me, args, false))
return me;
}
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
public abstract static class RandomAccessAbstractList extends AbstractList implements RandomAccess {
}
public static class PhilosophyBot1 {
public static class LogicRule implements IFieldsToList {
public Object lhs;
public Object rhs;
public LogicRule() {
}
public LogicRule(Object lhs, Object rhs) {
this.rhs = rhs;
this.lhs = lhs;
}
public String toString() {
return "LogicRule(" + lhs + ", " + rhs + ")";
}
public boolean equals(Object o) {
if (!(o instanceof LogicRule))
return false;
LogicRule x = (LogicRule) o;
return eq(lhs, x.lhs) && eq(rhs, x.rhs);
}
public int hashCode() {
int h = 274479962;
h = boostHashCombine(h, _hashCode(lhs));
h = boostHashCombine(h, _hashCode(rhs));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { lhs, rhs };
}
}
public static class And implements IFieldsToList {
public Object a;
public Object b;
public And() {
}
public And(Object a, Object b) {
this.b = b;
this.a = a;
}
public String toString() {
return "And(" + a + ", " + b + ")";
}
public boolean equals(Object o) {
if (!(o instanceof And))
return false;
And x = (And) o;
return eq(a, x.a) && eq(b, x.b);
}
public int hashCode() {
int h = 65975;
h = boostHashCombine(h, _hashCode(a));
h = boostHashCombine(h, _hashCode(b));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { a, b };
}
}
public static class If implements IFieldsToList {
public static String _fieldOrder = "condition thenBlock elseBlock";
public Object condition;
public Object thenBlock;
public Object elseBlock;
public If() {
}
public If(Object condition, Object thenBlock, Object elseBlock) {
this.elseBlock = elseBlock;
this.thenBlock = thenBlock;
this.condition = condition;
}
public String toString() {
return "If(" + condition + ", " + thenBlock + ", " + elseBlock + ")";
}
public boolean equals(Object o) {
if (!(o instanceof If))
return false;
If x = (If) o;
return eq(condition, x.condition) && eq(thenBlock, x.thenBlock) && eq(elseBlock, x.elseBlock);
}
public int hashCode() {
int h = 2365;
h = boostHashCombine(h, _hashCode(condition));
h = boostHashCombine(h, _hashCode(thenBlock));
h = boostHashCombine(h, _hashCode(elseBlock));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { condition, thenBlock, elseBlock };
}
}
public static class For implements IFieldsToList {
public static String _fieldOrder = "var condition body";
public Object var;
public Object condition;
public Object body;
public For() {
}
public For(Object var, Object condition, Object body) {
this.body = body;
this.condition = condition;
this.var = var;
}
public String toString() {
return "For(" + var + ", " + condition + ", " + body + ")";
}
public boolean equals(Object o) {
if (!(o instanceof For))
return false;
For x = (For) o;
return eq(var, x.var) && eq(condition, x.condition) && eq(body, x.body);
}
public int hashCode() {
int h = 70825;
h = boostHashCombine(h, _hashCode(var));
h = boostHashCombine(h, _hashCode(condition));
h = boostHashCombine(h, _hashCode(body));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { var, condition, body };
}
}
public static class While implements IFieldsToList {
public static String _fieldOrder = "condition body";
public Object condition;
public Object body;
public While() {
}
public While(Object condition, Object body) {
this.body = body;
this.condition = condition;
}
public String toString() {
return "While(" + condition + ", " + body + ")";
}
public boolean equals(Object o) {
if (!(o instanceof While))
return false;
While x = (While) o;
return eq(condition, x.condition) && eq(body, x.body);
}
public int hashCode() {
int h = 83548945;
h = boostHashCombine(h, _hashCode(condition));
h = boostHashCombine(h, _hashCode(body));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { condition, body };
}
}
public static class Env {
public boolean wantAlternatives = false;
public boolean wantAlternatives() {
return wantAlternatives;
}
}
public static class WithAlternative implements IFieldsToList {
public IF0 alternative;
public Object result;
public WithAlternative() {
}
public WithAlternative(IF0 alternative, Object result) {
this.result = result;
this.alternative = alternative;
}
public String toString() {
return "WithAlternative(" + alternative + ", " + result + ")";
}
public boolean equals(Object o) {
if (!(o instanceof WithAlternative))
return false;
WithAlternative x = (WithAlternative) o;
return eq(alternative, x.alternative) && eq(result, x.result);
}
public int hashCode() {
int h = -1195262233;
h = boostHashCombine(h, _hashCode(alternative));
h = boostHashCombine(h, _hashCode(result));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { alternative, result };
}
}
public static class NativePredicate implements IFieldsToList {
public static String _fieldOrder = "head body";
public String head;
public IF2, Env, Object> body;
public NativePredicate() {
}
public NativePredicate(String head, IF2, Env, Object> body) {
this.body = body;
this.head = head;
}
public String toString() {
return "NativePredicate(" + head + ", " + body + ")";
}
public boolean equals(Object o) {
if (!(o instanceof NativePredicate))
return false;
NativePredicate x = (NativePredicate) o;
return eq(head, x.head) && eq(body, x.body);
}
public int hashCode() {
int h = 1520196416;
h = boostHashCombine(h, _hashCode(head));
h = boostHashCombine(h, _hashCode(body));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { head, body };
}
}
public transient String program;
public transient int maxRounds = 1000;
public transient Set facts = linkedCISet();
public transient Set originalFacts;
public transient LinkedHashSet logicRules = new LinkedHashSet();
public transient AllOnAll rulesOnFacts = new AllOnAll();
public transient List proceduresToRun = new ArrayList();
public transient long proceduresExecuted;
public transient List nativePredicates = new ArrayList();
public transient boolean debugNativeCalls = true, debugAllCmds = true;
public transient List onProcedureEnded = new ArrayList();
public transient Set vars = litciset("x", "y", "z");
public void addLogicRule(LogicRule rule) {
if (logicRules.add(rule)) {
print("Got logic rule", rule);
rulesOnFacts.newA(rule);
}
}
public void addFact(String fact) {
fact = trim(fact);
if (empty(fact))
return;
fact = tok_deRoundBracket(fact);
List tok = javaTokWithBrackets(fact);
if (countCodeTokens(tok) == 2 && eqic(getCodeToken(tok, 0), "proc") && isCurlyBracketed(getCodeToken(tok, 1))) {
try {
String proc = uncurly_keepSpaces(getCodeToken(tok, 1));
if (proceduresToRun.add(parseProcedure(proc))) {
print("Got procedure:");
print(indentx("> ", proc));
}
} catch (Throwable __e) {
_handleException(__e);
}
} else if (facts.add(fact)) {
print("Got fact: " + fact);
rulesOnFacts.newB(fact);
}
}
public void runProcedure(String proc) {
try {
print("Running procedure.");
runParsedProcedure(parseProcedure(proc));
} catch (Throwable __e) {
_handleException(__e);
}
}
public void runParsedProcedure(List commands) {
runParsedProcedure(commands, proceduresToRun);
}
public void runParsedProcedure(List commands, List whereToPostCode) {
++proceduresExecuted;
Env env = new Env();
List remainingCommands = cloneLinkedList(commands);
Object cmd;
while ((cmd = popFirst(remainingCommands)) != null) {
if (cmd instanceof List) {
runParsedProcedure(((List) cmd));
continue;
}
if (debugAllCmds)
print("Running cmd: " + sfu(cmd));
if (cmd instanceof If) {
Object condition = ((If) cmd).condition;
Object thenBlock = ((If) cmd).thenBlock;
Object elseBlock = ((If) cmd).elseBlock;
Object blockToRun = checkCondition(condition) ? thenBlock : elseBlock;
runParsedProcedure(ll(blockToRun));
} else if (cmd instanceof For) {
Object var = ((For) cmd).var;
Object condition = ((For) cmd).condition;
Object body = ((For) cmd).body;
addLogicRule(new LogicRule(condition, "proc {\n" + body + "\n}"));
} else if (cmd instanceof While) {
Object condition = ((While) cmd).condition;
Object body = ((While) cmd).body;
boolean b = checkCondition(condition);
if (!b)
return;
whereToPostCode.add(ll(body, cmd));
} else if (cmd instanceof String) {
Object result = runNativePredicate(((String) cmd), env);
if (result != null) {
result = unpackWithAlternativeOrIterator(result);
if (isFalse(result))
return;
if (isTrueOpt(result))
continue;
Map mapping = (Map) result;
List remainingCommands2 = mapToLinkedList(remainingCommands, c -> replaceVars(c, mapValues("optRound", mapping)));
print("Applying var mapping " + mapping + " to " + remainingCommands + " => " + remainingCommands2);
remainingCommands = remainingCommands2;
} else
addFact(((String) cmd));
} else if (cmd != null)
throw fail("Unimplemented command: " + cmd);
}
pcallFAll(onProcedureEnded, commands);
}
public Object runNativePredicate(String s, Env env) {
for (NativePredicate np : nativePredicates) {
Map map = zipIt(np.head, s);
if (map != null) {
Object result = np.body.get(mapValues("tok_deRoundBracket", map), env);
if (debugNativeCalls)
print("Native predicate result: " + np.head + " => " + result);
if (result instanceof Map && nempty(map)) {
result = mapKeys((Map) result, var -> lookupOrKeep(map, var));
if (debugNativeCalls)
print("Rewrote native predicate result: " + result);
}
{
Object __25 = result;
if (__25 != null)
return __25;
}
}
}
return null;
}
public boolean checkCondition(Object o) {
if (o instanceof String) {
if (contains(facts, ((String) o)))
return true;
Object result = runNativePredicate(((String) o), nu(Env.class, "wantAlternatives", false));
result = unpackWithAlternativeOrIterator(result);
if (result instanceof Boolean)
return ((Boolean) result);
if (result instanceof Map)
return true;
}
print("Ignoring condition: " + o);
return false;
}
public List parsePythonesqueProcedure(String proc) {
proc = withoutLinesEmptyAfterTrim(proc);
proc = autoUnindent(proc);
List l = groupPythonStyleIndents_honoringBrackets(proc);
List out = new ArrayList();
for (int i = 0; i < l(l); i++) {
String s = l.get(i);
List tok = javaTokWithBrackets(s);
if (eqic(firstCodeToken(tok), "if")) {
assertEquals(s, ":", getCodeToken(tok, 2));
out.add(new If(deRoundBracket(getCodeToken(tok, 1)), parsePythonesqueProcedure(joinSubList(tok, 3 * 2)), null));
} else if (eqic(firstCodeToken(tok), "while")) {
assertEquals(s, ":", getCodeToken(tok, 2));
out.add(new While(deRoundBracket(getCodeToken(tok, 1)), parsePythonesqueProcedure(joinSubList(tok, 3 * 2))));
} else if (eqic(firstCodeToken(tok), "else")) {
Object last = last(out);
if (!(last instanceof If))
throw fail("Else without if");
assertEquals(s, ":", getCodeToken(tok, 1));
((If) last).elseBlock = joinSubList(tok, 2 * 2);
} else if (eqic(firstCodeToken(tok), "for")) {
assertEquals(s, ":", getCodeToken(tok, 2));
String cond = getCodeToken(tok, 1);
cond = deRoundBracket(cond);
List tok2 = javaTok(cond);
assertEquals(cond, "|", getCodeToken(tok2, 1));
String var = assertIdentifier(cond, getCodeToken(tok2, 0));
String actualCondition = trimJoinSubList(tok2, 2 * 2 + 1);
out.add(new For(var, actualCondition, parsePythonesqueProcedure(joinSubList(tok, 3 * 2))));
} else
out.add(s);
}
return out;
}
public List parseProcedure(String s) {
return parsePythonesqueProcedure(s);
}
public Object splitAtAmpersand2(String s) {
List l = tok_splitAtAmpersand(s);
if (l(l) == 1)
return s;
return new And(first(l), splitAtAmpersand2(join(" & ", dropFirst(l))));
}
public Map zipIt(String cond, String fact) {
Map map = gazelle_zip(cond, fact);
if (map == null)
return null;
print("gazelle zip => " + map);
if (!allKeysAreInSet(map, vars))
return null;
;
return map;
}
public Object replaceVars(Object o, Map map) {
if (empty(map))
return o;
return join(replaceCodeTokensUsingMap(javaTok((String) o), map));
}
public void applyLogicRuleToFact(LogicRule rule, String fact) {
Object lhs = rule.lhs, rhs = rule.rhs;
Object cond, remaining = null;
if (lhs instanceof And) {
Object a = ((And) lhs).a;
Object b = ((And) lhs).b;
cond = a;
remaining = b;
} else
cond = lhs;
Map map = zipIt((String) cond, fact);
if (map == null)
return;
print("Match.");
String rhs_replaced = (String) (replaceVars(rhs, map));
print("rhs_replaced", rhs_replaced);
if (remaining == null) {
addFact(rhs_replaced);
} else {
String remaining_replaced = (String) (replaceVars(remaining, map));
addLogicRule(new LogicRule(remaining_replaced, rhs_replaced));
}
}
public void run() {
parseProgram();
think();
}
public void smartParser1(String program) {
List paragraphs = map("autoUnindent", map("rtrim", splitAtEmptyLines(program)));
print("Got " + n2(paragraphs, "parapraph"));
print(joinWithEmptyLines(map(s -> indentx("> ", s), paragraphs)));
List paragraphs2 = antiFilter(paragraphs, s -> isSingleLine(trim(s)) && isQuoted(trim(s)) || countJavaTokens(s) == 0 || endsWith(rtrim(s), "----"));
print("Got " + n2(paragraphs2, "filtered paragraph"));
print(joinWithEmptyLines(map(s -> indentx("> ", s), paragraphs2)));
print(map("allLinesAreUnindented", paragraphs2));
Pair, List> p1 = filterAntiFilter(s -> !isSingleLine(trim(s)) && allLinesAreUnindented(s), paragraphs2);
List multiFactParagraphs = p1.a, paragraphs3 = p1.b;
for (String para : multiFactParagraphs) for (String s : tlft(para)) addFact(s);
List paragraphs4 = new ArrayList();
for (String para : paragraphs3) {
Pair p = splitAtDoubleArrow_pair(para);
if (p == null) {
paragraphs4.add(para);
continue;
}
addLogicRule(new LogicRule(splitAtAmpersand2(p.a), splitAtAmpersand2(p.b)));
}
pnlStruct("Unparsed - assuming facts", paragraphs4);
for (String para : paragraphs4) addFact(para);
originalFacts = cloneCISet(facts);
}
public void parseProgram() {
smartParser1(program);
}
public boolean doSomeLogic() {
boolean anyAction = false;
Pair p;
while ((p = rulesOnFacts.next()) != null) {
anyAction = true;
applyLogicRuleToFact(p.a, p.b);
}
return anyAction;
}
public long size() {
return l(logicRules) + l(facts) + proceduresExecuted;
}
public void think() {
int round = 0;
while (round++ < maxRounds) {
long lastSize = size();
print("Logic round " + round + ", size: " + lastSize);
while (doSomeLogic() && round++ < maxRounds) {
}
for (List proc : getAndClearList(proceduresToRun)) runParsedProcedure(proc);
if (size() == lastSize) {
print("No changes, exiting");
break;
}
}
List factsToPrint = listMinusList(facts, originalFacts);
pnlWithHeading("Facts I deduced", factsToPrint);
List output = new ArrayList();
for (String fact : factsToPrint) {
List tok = javaTokWithBrackets(fact);
if (countCodeTokens(tok) == 2 && eqic(getCodeToken(tok, 0), "print"))
output.add(tok_dropRoundBrackets(getCodeToken(tok, 1)));
}
pnlWithHeading("Bot Output", output);
}
public void addNativePredicate(String head, IF0 body) {
nativePredicates.add(new NativePredicate(head, (map, env) -> body.get()));
}
public void addNativePredicate(String head, IF1, Object> body) {
nativePredicates.add(new NativePredicate(head, (map, env) -> body.get(map)));
}
public void addNativePredicate(String head, IF2, Env, Object> body) {
nativePredicates.add(new NativePredicate(head, body));
}
public Object unpackWithAlternativeOrIterator(Object result) {
if (result instanceof Iterator)
return first((Iterator) result);
if (result instanceof WithAlternative)
return ((WithAlternative) result).result;
return result;
}
}
public static interface IF0 {
public A get();
}
public static interface IFieldsToList {
public Object[] _fieldsToList();
}
public static interface IF2 {
public C get(A a, B b);
}
public static class AllOnAll {
public List aList = new ArrayList();
public List bList = new ArrayList();
public List> todo = new LinkedList();
public List> todo2 = new LinkedList();
public synchronized void newA(A a) {
add(aList, a);
addPair(todo, intRange_last(aList), intRange(0, l(bList)));
}
public synchronized void newAs(Iterable l) {
for (A a : unnull(l)) newA(a);
}
public synchronized void newB(B b) {
add(bList, b);
addPair(todo, intRange(0, l(aList)), intRange_last(bList));
}
public synchronized void newBs(Iterable l) {
for (B b : unnull(l)) newB(b);
}
public synchronized Pair next() {
while (empty(todo2)) {
if (empty(todo))
return null;
Pair p = popFirst(todo);
addAll(todo2, outerProduct_pairs(subList(aList, p.a), subList(bList, p.b)));
}
return popFirst(todo2);
}
}
public static class Pair implements Comparable> {
public A a;
public B b;
public Pair() {
}
public Pair(A a, B b) {
this.b = b;
this.a = a;
}
public int hashCode() {
return hashCodeFor(a) + 2 * hashCodeFor(b);
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Pair))
return false;
Pair t = (Pair) o;
return eq(a, t.a) && eq(b, t.b);
}
public String toString() {
return "<" + a + ", " + b + ">";
}
public int compareTo(Pair p) {
if (p == null)
return 1;
int i = ((Comparable ) a).compareTo(p.a);
if (i != 0)
return i;
return ((Comparable) b).compareTo(p.b);
}
}
public static final class IntRange {
public int start, end;
public IntRange() {
}
public IntRange(int start, int end) {
this.end = end;
this.start = start;
}
public boolean equals(Object o) {
return stdEq2(this, o);
}
public int hashCode() {
return stdHash2(this);
}
public int length() {
return end - start;
}
public static String _fieldOrder = "start end";
public String toString() {
return "[" + start + ";" + end + "]";
}
}
public static boolean reflection_isForbiddenMethod(Method m) {
return m.getDeclaringClass() == Object.class && eqOneOf(m.getName(), "finalize", "clone", "registerNatives");
}
public static void multiMapPut(Map > map, A a, B b) {
List l = map.get(a);
if (l == null)
map.put(a, l = new ArrayList());
l.add(b);
}
public static Field makeAccessible(Field f) {
try {
f.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, f);
}
return f;
}
public static Method makeAccessible(Method m) {
try {
m.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, m);
}
return m;
}
public static Constructor makeAccessible(Constructor c) {
try {
c.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, c);
}
return c;
}
public static Set allInterfacesImplementedBy(Class c) {
if (c == null)
return null;
HashSet set = new HashSet();
allInterfacesImplementedBy_find(c, set);
return set;
}
public static void allInterfacesImplementedBy_find(Class c, Set set) {
if (c.isInterface() && !set.add(c))
return;
do {
for (Class intf : c.getInterfaces()) allInterfacesImplementedBy_find(intf, set);
} while ((c = c.getSuperclass()) != null);
}
public static Method findMethod(Object o, String method, Object... args) {
return findMethod_cached(o, method, args);
}
public static boolean findMethod_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 boolean call_checkArgs(Method m, Object[] args, boolean debug) {
Class>[] types = m.getParameterTypes();
if (types.length != args.length) {
if (debug)
print("Bad parameter length: " + args.length + " vs " + types.length);
return false;
}
for (int i = 0; i < types.length; i++) {
Object arg = args[i];
if (!(arg == null ? !types[i].isPrimitive() : isInstanceX(types[i], arg))) {
if (debug)
print("Bad parameter " + i + ": " + arg + " vs " + types[i]);
return false;
}
}
return true;
}
public static Method findStaticMethod(Class c, String method, Object... args) {
Class _c = c;
while (c != null) {
for (Method m : c.getDeclaredMethods()) {
if (!m.getName().equals(method))
continue;
if ((m.getModifiers() & Modifier.STATIC) == 0 || !findStaticMethod_checkArgs(m, args))
continue;
return m;
}
c = c.getSuperclass();
}
return null;
}
public static boolean findStaticMethod_checkArgs(Method m, Object[] args) {
Class>[] types = m.getParameterTypes();
if (types.length != args.length)
return false;
for (int i = 0; i < types.length; i++) if (!(args[i] == null || isInstanceX(types[i], args[i])))
return false;
return true;
}
public static int boostHashCombine(int a, int b) {
return a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2));
}
public static int _hashCode(Object a) {
return a == null ? 0 : a.hashCode();
}
public static Set linkedCISet() {
return new LinkedTreeSet(ciSet());
}
public static TreeSet litciset(String... items) {
TreeSet set = caseInsensitiveSet();
for (String a : items) set.add(a);
return set;
}
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 tok_deRoundBracket(String s) {
return tok_isRoundBracketed(s) ? join(dropFirstThreeAndLastThree(javaTok(s))) : s;
}
public static List javaTokWithBrackets(String s) {
return javaTokPlusBrackets(s);
}
public static int countCodeTokens(String s) {
return countTokens(s);
}
public static int countCodeTokens(List tok) {
return countTokens(tok);
}
public static String getCodeToken(List tok, int i) {
return get(tok, i * 2 + 1);
}
public static boolean isCurlyBracketed(String s) {
return isCurlyBraced(s);
}
public static String uncurly_keepSpaces(String s) {
return tok_unCurlyBracket_keepSpaces(s);
}
public static String indentx(String s) {
return indentx(indent_default, s);
}
public static String indentx(int n, String s) {
return dropSuffix(repeat(' ', n), indent(n, s));
}
public static String indentx(String indent, String s) {
return dropSuffix(indent, indent(indent, s));
}
public static LinkedList cloneLinkedList(Iterable l) {
return l instanceof Collection ? cloneLinkedList((Collection) l) : asLinkedList(l);
}
public static LinkedList cloneLinkedList(Collection l) {
if (l == null)
return new LinkedList();
synchronized (collectionMutex(l)) {
return new LinkedList (l);
}
}
public static A popFirst(List l) {
if (empty(l))
return null;
A a = first(l);
l.remove(0);
return a;
}
public static A popFirst(Collection l) {
if (empty(l))
return null;
A a = first(l);
l.remove(a);
return a;
}
public static List popFirst(int n, List l) {
List part = cloneSubList(l, 0, n);
removeSubList(l, 0, n);
return part;
}
public static String sfu(Object o) {
return structureForUser(o);
}
public static boolean checkCondition(Object condition, Object... args) {
return isTrue(callF(condition, args));
}
public static boolean checkCondition(IF1 condition, A arg) {
return isTrue(callF(condition, arg));
}
public static boolean isTrueOpt(Object o) {
if (o instanceof Boolean)
return ((Boolean) o).booleanValue();
return false;
}
public static LinkedList mapToLinkedList(Iterable l, Object f) {
LinkedList x = new LinkedList();
if (l != null)
for (Object o : l) x.add(callF(f, o));
return x;
}
public static LinkedList mapToLinkedList(Iterable l, IF1 f) {
return mapToLinkedList(l, (Object) f);
}
public static String replaceVars(String s, Map map) {
return empty(map) ? s : join(replaceVars(javaTok(s), map));
}
public static List replaceVars(List tok, Map map) {
if (empty(map))
return tok;
tok = cloneList(tok);
for (String var : keys(map)) jreplace(tok, var, map.get(var));
return tok;
}
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, IF1 f) {
return mapValues(f, map);
}
public static Map mapValues(Map map, Object func) {
return mapValues(func, map);
}
public static String optRound(String s) {
return roundBracketIfMoreThanOneToken(s);
}
public static void pcallFAll(Collection l, Object... args) {
if (l != null)
for (Object f : cloneList(l)) pcallF(f, args);
}
public static void pcallFAll(Iterator it, Object... args) {
while (it.hasNext()) pcallF(it.next(), args);
}
public static Map mapKeys(Object func, Map map) {
Map m = similarEmptyMap(map);
for (Object key : keys(map)) m.put(callF(func, key), map.get(key));
return m;
}
public static Map mapKeys(Map map, Object func) {
return mapKeys(func, map);
}
public static Map mapKeys(Map map, IF1 func) {
return mapKeys(map, (Object) func);
}
public static A lookupOrKeep(Map map, A key) {
return map != null && map.containsKey(key) ? map.get(key) : key;
}
public static boolean contains(Collection c, Object o) {
return c != null && c.contains(o);
}
public static boolean contains(Object[] x, Object o) {
if (x != null)
for (Object a : x) if (eq(a, o))
return true;
return false;
}
public static boolean contains(String s, char c) {
return s != null && s.indexOf(c) >= 0;
}
public static boolean contains(String s, String b) {
return s != null && s.indexOf(b) >= 0;
}
public static boolean contains(BitSet bs, int i) {
return bs != null && bs.get(i);
}
public static A nu(Class c, Object... values) {
A a = nuObject(c);
setAll(a, values);
return a;
}
public static List tok_splitAtAmpersand(String s) {
return splitAtTokens(javaTokWithAllBrackets(s), "&");
}
public static String[] dropFirst(int n, String[] a) {
return drop(n, a);
}
public static String[] dropFirst(String[] a) {
return drop(1, a);
}
public static Object[] dropFirst(Object[] a) {
return drop(1, a);
}
public static List dropFirst(List l) {
return dropFirst(1, l);
}
public static List dropFirst(int n, Iterable i) {
return dropFirst(n, toList(i));
}
public static List dropFirst(Iterable i) {
return dropFirst(toList(i));
}
public static List dropFirst(int n, List l) {
return n <= 0 ? l : new ArrayList(l.subList(Math.min(n, l.size()), l.size()));
}
public static List dropFirst(List l, int n) {
return dropFirst(n, l);
}
public static String dropFirst(int n, String s) {
return substring(s, n);
}
public static String dropFirst(String s, int n) {
return substring(s, n);
}
public static String dropFirst(String s) {
return substring(s, 1);
}
public static Map gazelle_zip(String inputA, String inputB, Object... __) {
Object tokenizer = optPar("tokenizer", __, "javaTokWithBrackets");
return gazelle_zipTwoTokenizationsToMap(callTokenizer(tokenizer, inputA), callTokenizer(tokenizer, inputB));
}
public static Map gazelle_zip(Pair inputs, Object... __) {
return inputs == null ? null : gazelle_zip(inputs.a, inputs.b, __);
}
public static boolean allKeysAreInSet(Map map, Set set) {
for (Object key : keys(map)) if (!contains(set, key))
return false;
return true;
}
public static String replaceCodeTokensUsingMap(String s, Map map) {
return join(replaceCodeTokensUsingMap(javaTok(s), map));
}
public static List replaceCodeTokensUsingMap(List tok, Map map) {
List out = emptyList(tok);
for (int i = 0; i < l(tok); i++) {
out.add(odd(i) ? lookupOrKeep(map, tok.get(i)) : tok.get(i));
}
return out;
}
public static String replaceCodeTokensUsingMap(Map map, String s) {
return replaceCodeTokensUsingMap(s, map);
}
public static int javaTok_n, javaTok_elements;
public static boolean javaTok_opt = false;
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)) || s.charAt(j) == '\''));
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 void think(String thought) {
miniChat(thought);
}
public static List getAndClearList(Collection l) {
if (l == null)
return emptyList();
synchronized (collectionMutex(l)) {
List out = cloneList(l);
l.clear();
return out;
}
}
public static List listMinusList(Collection l, Collection stuff) {
if (empty(stuff) && l instanceof List)
return (List) l;
List l2 = cloneList(l);
for (Object o : stuff) l2.remove(o);
return l2;
}
public static A pnlWithHeading(String heading, A l) {
printAsciiHeading(heading);
return pnl(l);
}
public static String tok_dropRoundBrackets(String s) {
return join(tok_dropRoundBrackets(javaTok(s)));
}
public static List tok_dropRoundBrackets(List tok) {
for (int i = 1; i < l(tok); i += 2) {
while (eqGetOneOf(tok, i, "(", ")")) {
tokAppend(tok, i - 1, tok.get(i + 1));
removeSubList(tok, i, i + 2);
}
}
return tok;
}
public static void add(BitSet bs, int i) {
bs.set(i);
}
public static boolean add(Collection c, A a) {
return c != null && c.add(a);
}
public static void add(Container c, Component x) {
addToContainer(c, x);
}
public static void addPair(Collection> c, A a, B b) {
if (c != null)
c.add(pair(a, b));
}
public static IntRange intRange_last(List l) {
int n = l(l);
return intRange(n - 1, n);
}
public static IntRange intRange(int start, int end) {
return new IntRange(start, end);
}
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 Pt unnull(Pt p) {
return p == null ? new Pt() : p;
}
public static Pair unnull(Pair p) {
return p != null ? p : new Pair(null, null);
}
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 Map addAll(Map a, Map extends A, ? extends B> b) {
if (a != null)
a.putAll(b);
return a;
}
public static IterableIterator> outerProduct_pairs(Collection lA, Collection lB) {
return outerProductPairs(lA, lB);
}
public static IterableIterator> outerProduct_pairs(Pair extends Collection, ? extends Collection> p) {
return outerProduct_pairs(p.a, p.b);
}
public static List subList(List l, int startIndex) {
return subList(l, startIndex, l(l));
}
public static List subList(int startIndex, int endIndex, List l) {
return subList(l, startIndex, endIndex);
}
public static List subList(List l, int startIndex, int endIndex) {
if (l == null)
return null;
int n = l(l);
startIndex = Math.max(0, startIndex);
endIndex = Math.min(n, endIndex);
if (startIndex >= endIndex)
return ll();
if (startIndex == 0 && endIndex == n)
return l;
return l.subList(startIndex, endIndex);
}
public static List subList(List l, IntRange r) {
return subList(l, r.start, r.end);
}
public static int hashCodeFor(Object a) {
return a == null ? 0 : a.hashCode();
}
public static boolean stdEq2(Object a, Object b) {
if (a == null)
return b == null;
if (b == null)
return false;
if (a.getClass() != b.getClass())
return false;
for (String field : allFields(a)) if (neq(getOpt(a, field), getOpt(b, field)))
return false;
return true;
}
public static int stdHash2(Object a) {
if (a == null)
return 0;
return stdHash(a, toStringArray(allFields(a)));
}
public static void vmBus_send(String msg, Object... args) {
Object arg = vmBus_wrapArgs(args);
pcallFAll(vm_busListeners_live(), msg, arg);
pcallFAll(vm_busListenersByMessage_live().get(msg), msg, arg);
}
public static void vmBus_send(String msg) {
vmBus_send(msg, (Object) null);
}
public static Method findMethod_cached(Object o, String method, Object... args) {
try {
if (o == null)
return null;
if (o instanceof Class) {
_MethodCache cache = callOpt_getCache(((Class) o));
List methods = cache.cache.get(method);
if (methods != null)
for (Method m : methods) if (isStaticMethod(m) && findMethod_checkArgs(m, args, false))
return m;
return null;
} else {
_MethodCache cache = callOpt_getCache(o.getClass());
List methods = cache.cache.get(method);
if (methods != null)
for (Method m : methods) if (findMethod_checkArgs(m, args, false))
return m;
return null;
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static TreeSet ciSet() {
return caseInsensitiveSet();
}
public static TreeSet caseInsensitiveSet() {
return caseInsensitiveSet_treeSet();
}
public static TreeSet caseInsensitiveSet(Collection c) {
return caseInsensitiveSet_treeSet(c);
}
public static TreeSet treeSet() {
return new TreeSet();
}
public static boolean tok_isRoundBracketed(String s) {
List tok = tok_combineRoundBrackets_keep(javaTok(s));
return l(tok) == 3 && startsWithAndEndsWith(tok.get(1), "(", ")");
}
public static List dropFirstThreeAndLastThree(List l) {
return dropFirstAndLast(3, l);
}
public static List javaTokPlusBrackets(String s) {
return tok_combineRoundOrCurlyBrackets_keep(javaTok(s));
}
public static int countTokens(String s) {
return l(javaTokC(s));
}
public static int countTokens(List tok) {
return l(tok) / 2;
}
public static boolean isCurlyBraced(String s) {
List tok = tok_combineCurlyBrackets_keep(javaTok(s));
return l(tok) == 3 && startsWithAndEndsWith(tok.get(1), "{", "}");
}
public static String tok_unCurlyBracket_keepSpaces(String s) {
return isCurlyBraced(s) ? join(dropFirstTwoAndLastTwo(javaTok(s))) : s;
}
public static String repeat(char c, int n) {
n = Math.max(n, 0);
char[] chars = new char[n];
for (int i = 0; i < n; i++) chars[i] = c;
return new String(chars);
}
public static List repeat(A a, int n) {
n = Math.max(n, 0);
List l = new ArrayList(n);
for (int i = 0; i < n; i++) l.add(a);
return l;
}
public static List repeat(int n, A a) {
return repeat(a, n);
}
public static int indent_default = 2;
public static String indent(int indent) {
return repeat(' ', indent);
}
public static String indent(int indent, String s) {
return indent(repeat(' ', indent), s);
}
public static String indent(String indent, String s) {
return indent + s.replace("\n", "\n" + indent);
}
public static String indent(String s) {
return indent(indent_default, s);
}
public static List indent(String indent, List lines) {
List l = new ArrayList();
if (lines != null)
for (String s : lines) l.add(indent + s);
return l;
}
public static LinkedList asLinkedList(Iterable s) {
if (s instanceof LinkedList)
return ((LinkedList) s);
LinkedList l = new LinkedList();
if (s != null)
for (A a : s) l.add(a);
return l;
}
public static List cloneSubList(List l, int startIndex, int endIndex) {
return newSubList(l, startIndex, endIndex);
}
public static List cloneSubList(List l, int startIndex) {
return newSubList(l, startIndex);
}
public static void removeSubList(List l, int from, int to) {
if (l != null)
subList(l, from, to).clear();
}
public static void removeSubList(List l, int from) {
if (l != null)
subList(l, from).clear();
}
public static String structureForUser(Object o) {
return beautifyStructure(struct_noStringSharing(o));
}
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(MultiSet ms) {
return ms.keySet();
}
public static String jreplace(String s, String in, String out) {
return jreplace(s, in, out, null);
}
public static String jreplace(String s, String in, String out, Object condition) {
List tok = javaTok(s);
return jreplace(tok, in, out, condition) ? join(tok) : s;
}
public static boolean jreplace(List tok, String in, String out) {
return jreplace(tok, in, out, false, true, null);
}
public static boolean jreplace(List tok, String in, String out, Object condition) {
return jreplace(tok, in, out, false, true, condition);
}
public static boolean jreplace(List tok, String in, String out, IF2, Integer, Boolean> condition) {
return jreplace(tok, in, out, (Object) condition);
}
public static boolean jreplace(List tok, String in, String out, boolean ignoreCase, boolean reTok, Object condition) {
String[] toks = javaTokForJFind_array(in);
int lTokin = toks.length * 2 + 1;
boolean anyChange = false;
int i = -1;
for (int n = 0; n < 10000; n++) {
i = findCodeTokens(tok, i + 1, ignoreCase, toks, condition);
if (i < 0)
return anyChange;
List subList = tok.subList(i - 1, i + lTokin - 1);
String expansion = jreplaceExpandRefs(out, subList);
int end = i + lTokin - 2;
clearAllTokens(tok, i, end);
tok.set(i, expansion);
if (reTok)
reTok(tok, i, end);
i = end;
anyChange = true;
}
throw fail("woot? 10000! " + quote(in) + " => " + quote(out));
}
public static boolean jreplace_debug = false;
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 String roundBracketIfMoreThanOneToken(String s) {
return !tok_isRoundBracketed(s) && numberOfJavaTokens(s) > 1 ? roundBracket(s) : s;
}
public static Object pcallF(Object f, Object... args) {
return pcallFunction(f, args);
}
public static A pcallF(F0 f) {
try {
return f == null ? null : f.get();
} catch (Throwable __e) {
return null;
}
}
public static B pcallF(F1 f, A a) {
try {
return f == null ? null : f.get(a);
} catch (Throwable __e) {
return null;
}
}
public static void pcallF(VF1 f, A a) {
try {
if (f != null)
f.get(a);
} catch (Throwable __e) {
_handleException(__e);
}
}
public static Object nuObject(String className, Object... args) {
try {
return nuObject(classForName(className), args);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static A nuObject(Class c, Object... args) {
try {
if (args.length == 0)
return nuObjectWithoutArguments(c);
Constructor m = nuObject_findConstructor(c, args);
makeAccessible(m);
return (A) m.newInstance(args);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static Constructor nuObject_findConstructor(Class c, Object... args) {
for (Constructor m : c.getDeclaredConstructors()) {
if (!nuObject_checkArgs(m.getParameterTypes(), args, false))
continue;
return m;
}
throw fail("Constructor " + c.getName() + getClasses(args) + " not found" + (args.length == 0 && (c.getModifiers() & java.lang.reflect.Modifier.STATIC) == 0 ? " - hint: it's a non-static class!" : ""));
}
public static boolean nuObject_checkArgs(Class[] types, Object[] args, boolean debug) {
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 A setAll(A o, Map fields) {
if (fields == null)
return o;
for (String field : keys(fields)) set(o, field, fields.get(field));
return o;
}
public static A setAll(A o, Object... values) {
failIfOddCount(values);
for (int i = 0; i + 1 < l(values); i += 2) {
String field = (String) values[i];
Object value = values[i + 1];
set(o, field, value);
}
return o;
}
public static List splitAtTokens(String s, List tokens) {
return splitAtTokens(javaTok(s), tokens);
}
public static List splitAtTokens(List tok, List tokens) {
List l = new ArrayList();
int i = 0;
while (i < l(tok)) {
int j = indexOfSubList(tok, tokens, i);
if (i >= l(tok))
break;
if (j < 0)
j = l(tok);
l.add(trimJoin(tok.subList(i, j)));
i = j + l(tokens);
}
return l;
}
public static List splitAtTokens(List tok, String... tokens) {
List l = new ArrayList();
int i = 0;
while (i < l(tok)) {
int j = indexOfSubList(tok, tokens, i);
if (i >= l(tok))
break;
if (j < 0)
j = l(tok);
l.add(trimJoin(tok.subList(i, j)));
i = j + l(tokens);
}
return l;
}
public static List javaTokWithAllBrackets(String s) {
return javaTokPlusBrackets2(s);
}
public static String[] drop(int n, String[] a) {
n = Math.min(n, a.length);
String[] b = new String[a.length - n];
System.arraycopy(a, n, b, 0, b.length);
return b;
}
public static Object[] drop(int n, Object[] a) {
n = Math.min(n, a.length);
Object[] b = new Object[a.length - n];
System.arraycopy(a, n, b, 0, b.length);
return b;
}
public static ArrayList toList(A[] a) {
return asList(a);
}
public static ArrayList toList(int[] a) {
return asList(a);
}
public static ArrayList toList(Set s) {
return asList(s);
}
public static ArrayList toList(Iterable s) {
return asList(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 Object optPar(Object[] params, String name) {
return optParam(params, name);
}
public static Object optPar(String name, Object[] params) {
return optParam(params, name);
}
public static Object optPar(String name, Map params) {
return optParam(name, params);
}
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 Map gazelle_zipTwoTokenizationsToMap(List tokA, List tokB) {
return ciMapWithoutKeysEqualToValues(zipTwoListsToCIMap_strict(codeTokens_lazy_uncurly(tokA), codeTokens_lazy_uncurly(tokB)));
}
public static List callTokenizer(Object tokenizer, String s) {
return (List) callF(tokenizer, s);
}
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(Object[] l) {
return emptyList(l(l));
}
public static ArrayList emptyList(Class c) {
return new ArrayList();
}
public static boolean odd(int i) {
return (i & 1) != 0;
}
public static boolean odd(long i) {
return (i & 1) != 0;
}
public static boolean odd(BigInteger i) {
return odd(toInt(i));
}
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 void miniChat(String text) {
String slackTS = getSlackTS();
if (slackTS == null) {
print("Skipping mini-chat post (not on slack): " + quote(text));
return;
}
Object mcBot = getBot("#1002433");
call(mcBot, "addToMiniChat", "dc" + slackTS, getProgramID(), text);
}
public static void printAsciiHeading(String text) {
print(asciiHeading2(text));
}
public static A pnl(String prefix, A l) {
printNumberedLines(prefix, l);
return l;
}
public static A pnl(A l) {
printNumberedLines(l);
return l;
}
public static A pnl(A map) {
printNumberedLines(map);
return map;
}
public static A[] pnl(A[] a) {
printNumberedLines(a);
return a;
}
public static String pnl(String s) {
printNumberedLines(lines(s));
return s;
}
public static boolean eqGetOneOf(List l, int i, A... options) {
return eqOneOf(get(l, i), options);
}
public static void tokAppend(List tok, int i, String s) {
tok.set(i, tok.get(i) + s);
}
public static void addToContainer(final Container a, final Component b) {
if (a != null && b != null) {
swing(new Runnable() {
public void run() {
try {
a.add(b);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "a.add(b);";
}
});
}
}
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 Map emptyMap() {
return new HashMap();
}
public static IterableIterator> outerProductPairs(Collection lA, Collection lB) {
return nestedIterator(lA, new F1>>() {
public Iterator> get(A a) {
try {
return mapI(lB, b -> pair(a, b));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "mapI(lB, b -> pair(a, b))";
}
});
}
public static Set allFields(Object o) {
TreeSet fields = new TreeSet();
Class _c = _getClass(o);
do {
for (Field f : _c.getDeclaredFields()) fields.add(f.getName());
_c = _c.getSuperclass();
} while (_c != null);
return fields;
}
public static int stdHash(Object a, String... fields) {
if (a == null)
return 0;
int hash = getClassName(a).hashCode();
for (String field : fields) hash = boostHashCombine(hash, hashCode(getOpt(a, field)));
return hash;
}
public static String[] toStringArray(Collection c) {
String[] a = new String[l(c)];
Iterator it = c.iterator();
for (int i = 0; i < l(a); i++) a[i] = it.next();
return a;
}
public static String[] toStringArray(Object o) {
if (o instanceof String[])
return (String[]) o;
else if (o instanceof Collection)
return toStringArray((Collection) o);
else
throw fail("Not a collection or array: " + getClassName(o));
}
public static Object vmBus_wrapArgs(Object... args) {
return empty(args) ? null : l(args) == 1 ? args[0] : args;
}
public static Set vm_busListeners_live_cache;
public static Set vm_busListeners_live() {
if (vm_busListeners_live_cache == null)
vm_busListeners_live_cache = vm_busListeners_live_load();
return vm_busListeners_live_cache;
}
public static Set vm_busListeners_live_load() {
return vm_generalIdentityHashSet("busListeners");
}
public static Map vm_busListenersByMessage_live_cache;
public static Map vm_busListenersByMessage_live() {
if (vm_busListenersByMessage_live_cache == null)
vm_busListenersByMessage_live_cache = vm_busListenersByMessage_live_load();
return vm_busListenersByMessage_live_cache;
}
public static Map vm_busListenersByMessage_live_load() {
return vm_generalHashMap("busListenersByMessage");
}
public static TreeSet caseInsensitiveSet_treeSet() {
return new TreeSet(caseInsensitiveComparator());
}
public static TreeSet caseInsensitiveSet_treeSet(Collection c) {
return toCaseInsensitiveSet_treeSet(c);
}
public static List tok_combineRoundBrackets_keep(List tok) {
List l = new ArrayList();
for (int i = 0; i < l(tok); i++) {
String t = tok.get(i);
if (odd(i) && eq(t, "(")) {
int j = findEndOfBracketPart(tok, i);
l.add(joinSubList(tok, i, j));
i = j - 1;
} else
l.add(t);
}
return l;
}
public static boolean startsWithAndEndsWith(String s, String prefix, String suffix) {
return startsWith(s, prefix) && endsWith(s, suffix);
}
public static List dropFirstAndLast(int n, List l) {
return new ArrayList(subList(l, n, l(l) - n));
}
public static List dropFirstAndLast(List l) {
return dropFirstAndLast(1, l);
}
public static String dropFirstAndLast(String s) {
return substring(s, 1, l(s) - 1);
}
public static List tok_combineRoundOrCurlyBrackets_keep(List tok) {
List l = new ArrayList();
for (int i = 0; i < l(tok); i++) {
String t = tok.get(i);
if (odd(i) && eqOneOf(t, "{", "(")) {
int j = findEndOfBracketPart(tok, i);
l.add(joinSubList(tok, i, j));
i = j - 1;
} else
l.add(t);
}
return l;
}
public static List javaTokC(String s) {
if (s == null)
return null;
int l = s.length();
ArrayList tok = new ArrayList();
int i = 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;
}
i = j;
if (i >= l)
break;
c = s.charAt(i);
d = i + 1 >= l ? '\0' : s.charAt(i + 1);
if (c == '\'' || c == '"') {
char opener = c;
++j;
while (j < l) {
if (s.charAt(j) == opener || s.charAt(j) == '\n') {
++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;
tok.add(javaTok_substringC(s, i, j));
i = j;
}
return tok;
}
public static List tok_combineCurlyBrackets_keep(List tok) {
List l = new ArrayList();
for (int i = 0; i < l(tok); i++) {
String t = tok.get(i);
if (odd(i) && eq(t, "{")) {
int j = findEndOfCurlyBracketPart(tok, i);
l.add(joinSubList(tok, i, j));
i = j - 1;
} else
l.add(t);
}
return l;
}
public static List dropFirstTwoAndLastTwo(List l) {
return dropFirstAndLast(2, l);
}
public static List newSubList(List l, int startIndex, int endIndex) {
return cloneList(subList(l, startIndex, endIndex));
}
public static List newSubList(List l, int startIndex) {
return cloneList(subList(l, startIndex));
}
public static String beautifyStructure(String s) {
List tok = javaTok(s);
structure_addTokenMarkers(tok);
jreplace(tok, "lhm", "");
return join(tok);
}
public static String struct_noStringSharing(Object o) {
structure_Data d = new structure_Data();
d.noStringSharing = true;
return structure(o, d);
}
public static Map javaTokForJFind_array_cache = synchronizedMRUCache(1000);
public static String[] javaTokForJFind_array(String s) {
String[] tok = javaTokForJFind_array_cache.get(s);
if (tok == null)
javaTokForJFind_array_cache.put(s, tok = codeTokensAsStringArray(jfind_preprocess(javaTok(s))));
return tok;
}
public static int findCodeTokens(List tok, String... tokens) {
return findCodeTokens(tok, 1, false, tokens);
}
public static int findCodeTokens(List tok, boolean ignoreCase, String... tokens) {
return findCodeTokens(tok, 1, ignoreCase, tokens);
}
public static int findCodeTokens(List tok, int startIdx, boolean ignoreCase, String... tokens) {
return findCodeTokens(tok, startIdx, ignoreCase, tokens, null);
}
public static HashSet findCodeTokens_specials = lithashset("*", "", "", "", "\\*");
public static int findCodeTokens_bails, findCodeTokens_nonbails;
public static interface findCodeTokens_Matcher {
public boolean get(String token);
}
public static int findCodeTokens(List tok, int startIdx, boolean ignoreCase, String[] tokens, Object condition) {
int end = tok.size() - tokens.length * 2 + 2, nTokens = tokens.length;
int i = startIdx | 1;
String firstToken = tokens[0];
if (!ignoreCase && !findCodeTokens_specials.contains(firstToken)) {
while (i < end && !firstToken.equals(tok.get(i))) i += 2;
}
findCodeTokens_Matcher[] matchers = new findCodeTokens_Matcher[nTokens];
for (int j = 0; j < nTokens; j++) {
String p = tokens[j];
findCodeTokens_Matcher matcher;
if (p.equals("*"))
matcher = t -> true;
else if (p.equals(""))
matcher = t -> isQuoted(t);
else if (p.equals(""))
matcher = t -> isIdentifier(t);
else if (p.equals(""))
matcher = t -> isInteger(t);
else if (p.equals("\\*"))
matcher = t -> t.equals("*");
else if (ignoreCase)
matcher = t -> eqic(p, t);
else
matcher = t -> t.equals(p);
matchers[j] = matcher;
}
outer: for (; i < end; i += 2) {
for (int j = 0; j < nTokens; j++) if (!matchers[j].get(tok.get(i + j * 2)))
continue outer;
if (condition == null || checkTokCondition(condition, tok, i - 1))
return i;
}
return -1;
}
public static String jreplaceExpandRefs(String s, List tokref) {
List tok = javaTok(s);
for (int i = 1; i < l(tok); i += 2) {
String t = tok.get(i);
if (t.startsWith("$") && isInteger(t.substring(1))) {
String x = tokref.get(-1 + parseInt(t.substring(1)) * 2);
tok.set(i, x);
} else if (t.equals("\\")) {
tok.set(i, "");
i += 2;
}
}
return join(tok);
}
public static void clearAllTokens(List tok) {
for (int i = 0; i < tok.size(); i++) tok.set(i, "");
}
public static void clearAllTokens(List tok, int i, int j) {
for (; i < j; i++) tok.set(i, "");
}
public static List reTok(List tok) {
replaceCollection(tok, javaTok(tok));
return tok;
}
public static List reTok(List