Warning : session_start(): open(/var/lib/php/sessions/sess_v92jfi6b4vc80adu3vgi89nsch, 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 java.util.function.*;
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 java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
import java.time.Duration;
import java.awt.geom.*;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.Const;
import org.apache.bcel.generic.*;
import java.lang.reflect.Type;
import static x30_pkg.x30_util.DynamicObject;
import java.text.*;
import java.text.NumberFormat;
import java.nio.charset.Charset;
import java.util.TimeZone;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
public class main {
static public class LASToByteCode implements IFieldsToList {
public MethodMaker m;
public LASToByteCode() {
}
public LASToByteCode(MethodMaker m) {
this.m = m;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + m + ")";
}
public Object[] _fieldsToList() {
return new Object[] { m };
}
public boolean callPing = true;
final public LASToByteCode setIVarContext(int iVarContext) {
return iVarContext(iVarContext);
}
public LASToByteCode iVarContext(int iVarContext) {
this.iVarContext = iVarContext;
return this;
}
final public int getIVarContext() {
return iVarContext();
}
public int iVarContext() {
return iVarContext;
}
public int iVarContext = -1;
public GazelleV_LeftArrowScript.Script returnableScript;
final public LASToByteCode setPostConversion(IF1 postConversion) {
return postConversion(postConversion);
}
public LASToByteCode postConversion(IF1 postConversion) {
this.postConversion = postConversion;
return this;
}
final public IF1 getPostConversion() {
return postConversion();
}
public IF1 postConversion() {
return postConversion;
}
public IF1 postConversion;
public JVMStackCellType compileScript(GazelleV_LeftArrowScript.Script script) {
returnableScript = script;
var stackTop = compile(script);
if (postConversion != null)
stackTop = postConversion.get(stackTop);
return stackTop;
}
public void compileToObject(GazelleV_LeftArrowScript.Evaluable code) {
m.convertToObject(compile(code));
}
public JVMStackCellType compile(GazelleV_LeftArrowScript.Evaluable code) {
if (code instanceof GazelleV_LeftArrowScript.Const) {
Object o = ((GazelleV_LeftArrowScript.Const) code).value;
if (o == null) {
m.add(new ACONST_NULL());
return JVMStackCellType.objValue;
} else if (o instanceof String) {
m.stringConstant((String) o);
return JVMStackCellType.objValue;
} else if (o instanceof Integer) {
m.intConstant((Integer) o);
return JVMStackCellType.intValue;
} else if (o instanceof Double) {
m.doubleConstant((Double) o);
return JVMStackCellType.doubleValue;
} else if (o instanceof Class) {
m.classConstant((Class) o);
return JVMStackCellType.objValue;
} else if (o instanceof Boolean) {
m.boolConstant((Boolean) o);
return JVMStackCellType.intValue;
} else
throw fail("Can't compile const value: " + toStringWithClass(o));
} else if (code instanceof GazelleV_LeftArrowScript.Script) {
var stackTop = JVMStackCellType.none;
for (var step : ((GazelleV_LeftArrowScript.Script) code).steps) {
if (stackTop != JVMStackCellType.none)
m.add(new POP());
stackTop = compile(step);
}
return stackTop;
} else if (code instanceof GazelleV_LeftArrowScript.CallMethod) {
compileToObject(((GazelleV_LeftArrowScript.CallMethod) code).target);
m.stringConstant(((GazelleV_LeftArrowScript.CallMethod) code).methodName);
argumentsAsArray(((GazelleV_LeftArrowScript.CallMethod) code).args);
m.invokeStatic(main.class, Object.class, "call", Object.class, String.class, Object[].class);
return JVMStackCellType.objValue;
} else if (code instanceof GazelleV_LeftArrowScript.CallMethodOrGetField) {
compileToObject(((GazelleV_LeftArrowScript.CallMethodOrGetField) code).target);
m.stringConstant(((GazelleV_LeftArrowScript.CallMethodOrGetField) code).name);
m.invokeStatic(main.class, Object.class, "preciseGetOrCallMethod", Object.class, String.class);
return JVMStackCellType.objValue;
} else if (code instanceof GazelleV_LeftArrowScript.SetField) {
compileToObject(((GazelleV_LeftArrowScript.SetField) code).target);
m.stringConstant(((GazelleV_LeftArrowScript.SetField) code).name);
compileToObject(((GazelleV_LeftArrowScript.SetField) code).expr);
m.invokeStatic(main.class, Object.class, "set", Object.class, String.class, Object.class);
return JVMStackCellType.none;
} else if (code instanceof GazelleV_LeftArrowScript.NewObject) {
m.classConstant(((GazelleV_LeftArrowScript.NewObject) code).c);
argumentsAsArray(((GazelleV_LeftArrowScript.NewObject) code).args);
m.invokeStatic(main.class, Object.class, "nuObject", Class.class, Object[].class);
return JVMStackCellType.objValue;
} else if (code instanceof GazelleV_LeftArrowScript.Assignment) {
compileToObject(((GazelleV_LeftArrowScript.Assignment) code).expression);
m.astore(iTemp());
loadVarContext();
m.stringConstant(((GazelleV_LeftArrowScript.Assignment) code).var);
m.aload(iTemp());
m.invokeVirtual(VarContext.class, void.class, "set", String.class, Object.class);
m.aload(iTemp());
return JVMStackCellType.objValue;
} else if (code instanceof GazelleV_LeftArrowScript.While) {
var loopStart = m.il.append(new NOP());
BranchInstruction branch1 = null;
if (callPing) {
m.invokeStatic(main.class, boolean.class, "ping");
branch1 = new IFEQ(null);
m.add(branch1);
}
compileToBool(((GazelleV_LeftArrowScript.While) code).condition);
var branch2 = new IFEQ(null);
m.add(branch2);
m.discardStackTop(compile(((GazelleV_LeftArrowScript.While) code).body));
m.add(new GOTO(loopStart));
var loopEnd = m.il.append(new NOP());
{
if (branch1 != null)
branch1.setTarget(loopEnd);
}
branch2.setTarget(loopEnd);
return JVMStackCellType.none;
} else if (code instanceof GazelleV_LeftArrowScript.IfThen) {
compileToBool(((GazelleV_LeftArrowScript.IfThen) code).condition);
var branch1 = new IFEQ(null);
m.add(branch1);
var stackTop = compile(((GazelleV_LeftArrowScript.IfThen) code).body);
if (stackTop == JVMStackCellType.none) {
branch1.setTarget(m.here());
return stackTop;
} else {
m.convertToObject(stackTop);
var jumpToEnd = m.forwardGoto();
branch1.setTarget(m.here());
m.loadNull();
jumpToEnd.setTarget(m.here());
return JVMStackCellType.objValue;
}
} else if (code instanceof GazelleV_LeftArrowScript.GetVar) {
return compileGetVar((GazelleV_LeftArrowScript.GetVar) code);
} else if (code instanceof GazelleV_LeftArrowScript.ReturnFromScript) {
if (((GazelleV_LeftArrowScript.ReturnFromScript) code).script != returnableScript)
throw fail("Can only return from current script");
var stackTop = compile(((GazelleV_LeftArrowScript.ReturnFromScript) code).value);
if (postConversion != null)
stackTop = postConversion.get(stackTop);
m.returnWithType(stackTop);
return JVMStackCellType.none;
}
throw fail("Can't compile yet: " + className(code));
}
public void argumentsAsArray(GazelleV_LeftArrowScript.Evaluable[] args) {
int n = l(args);
m.intConst(n);
m.add(new ANEWARRAY(m.classRef(Object.class)));
for (int iArg = 0; iArg < n; iArg++) {
m.dup();
m.intConst(iArg);
compileToObject(args[iArg]);
m.add(new AASTORE());
}
}
public void loadVarContext() {
assertTrue("Need VarContext", iVarContext >= 0);
m.aload(iVarContext);
}
public Integer iTemp_cache;
public int iTemp() {
if (iTemp_cache == null)
iTemp_cache = iTemp_load();
return iTemp_cache;
}
public Integer iTemp_load() {
return m.newLocalVar();
}
public void compileToBool(GazelleV_LeftArrowScript.Evaluable condition) {
var stackTop = compile(condition);
if (stackTop == JVMStackCellType.objValue) {
m.checkCast(Boolean.class);
m.invokeVirtual(Boolean.class, boolean.class, "booleanValue");
} else if (stackTop == JVMStackCellType.intValue) {
} else
throw fail("Can't convert to bool: " + stackTop);
}
public JVMStackCellType compileGetVar(GazelleV_LeftArrowScript.GetVar code) {
loadVarContext();
m.stringConstant(code.var);
m.invokeVirtual(VarContext.class, Object.class, "get", String.class);
return JVMStackCellType.objValue;
}
}
static public Object call(Object o) {
return callF(o);
}
static public Object call(Object o, String method, String[] arg) {
return call(o, method, new Object[] { arg });
}
static public Object call(Object o, String method, Object... args) {
return call_withVarargs(o, method, args);
}
static public Object preciseGetOrCallMethod(Object object, String name) {
if (object == null)
return null;
if (canCallWithVarargs(object, name))
return call(object, name);
return _get(object, name);
}
static public A set(A o, String field, Object value) {
if (o == null)
return null;
if (o instanceof Class)
set((Class) o, field, value);
else
try {
Field f = set_findField(o.getClass(), field);
makeAccessible(f);
smartSet(f, o, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
return o;
}
static public void set(Class c, String field, Object value) {
if (c == null)
return;
try {
Field f = set_findStaticField(c, field);
makeAccessible(f);
smartSet(f, null, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static public Field set_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Static field '" + field + "' not found in " + c.getName());
}
static public Field set_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Field '" + field + "' not found in " + c.getName());
}
static public void set(BitSet bs, int idx) {
{
if (bs != null)
bs.set(idx);
}
}
static public String shortClassName_dropNumberPrefix(Object o) {
return dropNumberPrefix(shortClassName(o));
}
static public RuntimeException fail() {
throw new RuntimeException("fail");
}
static public RuntimeException fail(Throwable e) {
throw asRuntimeException(e);
}
static public RuntimeException fail(Object msg) {
throw new RuntimeException(String.valueOf(msg));
}
static public RuntimeException fail(Object... objects) {
throw new Fail(objects);
}
static public RuntimeException fail(String msg) {
throw new RuntimeException(msg == null ? "" : msg);
}
static public RuntimeException fail(String msg, Throwable innerException) {
throw new RuntimeException(msg, innerException);
}
static public String toStringWithClass(Object o) {
return o == null ? null : className(o) + " - " + o;
}
static public String className(Object o) {
return getClassName(o);
}
static public int l(Object[] a) {
return a == null ? 0 : a.length;
}
static public int l(boolean[] a) {
return a == null ? 0 : a.length;
}
static public int l(byte[] a) {
return a == null ? 0 : a.length;
}
static public int l(short[] a) {
return a == null ? 0 : a.length;
}
static public int l(long[] a) {
return a == null ? 0 : a.length;
}
static public int l(int[] a) {
return a == null ? 0 : a.length;
}
static public int l(float[] a) {
return a == null ? 0 : a.length;
}
static public int l(double[] a) {
return a == null ? 0 : a.length;
}
static public int l(char[] a) {
return a == null ? 0 : a.length;
}
static public int l(Collection c) {
return c == null ? 0 : c.size();
}
static public int l(Iterator i) {
return iteratorCount_int_close(i);
}
static public int l(Map m) {
return m == null ? 0 : m.size();
}
static public int l(CharSequence s) {
return s == null ? 0 : s.length();
}
static public long l(File f) {
return f == null ? 0 : f.length();
}
static public int l(MultiSet ms) {
return ms == null ? 0 : ms.size();
}
static public int l(IMultiMap mm) {
return mm == null ? 0 : mm.size();
}
static public int l(IntRange r) {
return r == null ? 0 : r.length();
}
static public int l(AppendableChain a) {
return a == null ? 0 : a.size;
}
static public void assertTrue(Object o) {
if (!(eq(o, true)))
throw fail(str(o));
}
static public boolean assertTrue(String msg, boolean b) {
if (!b)
throw fail(msg);
return b;
}
static public boolean assertTrue(boolean b) {
if (!b)
throw fail("oops");
return b;
}
static public Map> callF_cache = newDangerousWeakHashMap();
static public A callF(F0 f) {
return f == null ? null : f.get();
}
static public B callF(F1 f, A a) {
return f == null ? null : f.get(a);
}
static public A callF(IF0 f) {
return f == null ? null : f.get();
}
static public B callF(IF1 f, A a) {
return f == null ? null : f.get(a);
}
static public B callF(A a, IF1 f) {
return f == null ? null : f.get(a);
}
static public C callF(IF2 f, A a, B b) {
return f == null ? null : f.get(a, b);
}
static public void callF(VF1 f, A a) {
if (f != null)
f.get(a);
}
static public void callF(A a, IVF1 f) {
if (f != null)
f.get(a);
}
static public void callF(IVF1 f, A a) {
if (f != null)
f.get(a);
}
static public Object callF(Runnable r) {
{
if (r != null)
r.run();
}
return null;
}
static public Object callF(Object f, Object... args) {
return safeCallF(f, args);
}
static public Object safeCallF(Object f, Object... args) {
if (f instanceof Runnable) {
((Runnable) f).run();
return null;
}
if (f == null)
return null;
Class c = f.getClass();
ArrayList methods;
synchronized (callF_cache) {
methods = callF_cache.get(c);
if (methods == null)
methods = callF_makeCache(c);
}
int n = l(methods);
if (n == 0) {
if (f instanceof String)
throw fail("Legacy call: " + f);
throw fail("No get method in " + getClassName(c));
}
if (n == 1)
return invokeMethod(methods.get(0), f, args);
for (int i = 0; i < n; i++) {
Method m = methods.get(i);
if (call_checkArgs(m, args, false))
return invokeMethod(m, f, args);
}
throw fail("No matching get method in " + getClassName(c));
}
static public ArrayList callF_makeCache(Class c) {
ArrayList l = new ArrayList();
Class _c = c;
do {
for (Method m : _c.getDeclaredMethods()) if (m.getName().equals("get")) {
makeAccessible(m);
l.add(m);
}
if (!l.isEmpty())
break;
_c = _c.getSuperclass();
} while (_c != null);
callF_cache.put(c, l);
return l;
}
static public Object call_withVarargs(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.findStaticMethod(methodName, args);
if (me != null)
return invokeMethod(me, null, args);
List methods = cache.cache.get(methodName);
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() + "." + methodName + "(" + joinWithComma(classNames(args)) + ") not found");
} else {
Class c = o.getClass();
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(methodName, args);
if (me != null)
return invokeMethod(me, o, args);
List methods = cache.cache.get(methodName);
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() + "." + methodName + "(" + joinWithComma(classNames(args)) + ") not found");
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public boolean canCallWithVarargs(Object o, String method, Object... args) {
if (o == null)
return false;
if (o instanceof Class) {
Class c = (Class) o;
_MethodCache cache = callOpt_getCache(c);
if (cache.findStaticMethod(method, args) != null)
return true;
List methods = cache.cache.get(method);
if (methods != null)
methodSearch: for (Method m : methods) {
{
if (!(m.isVarArgs() && isStaticMethod(m)))
continue;
}
if (massageArgsForVarArgsCall(m, args) != null)
return true;
}
} else {
Class c = o.getClass();
_MethodCache cache = callOpt_getCache(c);
if (cache.findMethod(method, args) != null)
return true;
List methods = cache.cache.get(method);
if (methods != null)
methodSearch: for (Method m : methods) {
{
if (!(m.isVarArgs()))
continue;
}
if (massageArgsForVarArgsCall(m, args) != null)
return true;
}
}
return false;
}
static public A _get(List l, int idx) {
return l != null && idx >= 0 && idx < l(l) ? l.get(idx) : null;
}
static public Object _get(Object o, String field) {
return get(o, field);
}
static public Object _get(String field, Object o) {
return get(o, field);
}
static public A _get(A[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : null;
}
static public Field makeAccessible(Field f) {
try {
f.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, f);
}
return f;
}
static public Method makeAccessible(Method m) {
try {
m.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, m);
}
return m;
}
static public Constructor makeAccessible(Constructor c) {
try {
c.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, c);
}
return c;
}
static public void smartSet(Field f, Object o, Object value) throws Exception {
try {
f.set(o, value);
} catch (Exception e) {
Class type = f.getType();
if (type == int.class && value instanceof Long) {
f.set(o, ((Long) value).intValue());
return;
}
if (type == boolean.class && value instanceof String) {
f.set(o, isTrueOrYes(((String) value)));
return;
}
if (type == LinkedHashMap.class && value instanceof Map) {
f.set(o, asLinkedHashMap((Map) value));
return;
}
try {
if (f.getType() == Concept.Ref.class) {
f.set(o, ((Concept) o).new Ref((Concept) value));
return;
}
if (o instanceof Concept.Ref) {
f.set(o, ((Concept.Ref) o).get());
return;
}
} catch (Throwable _e) {
}
throw e;
}
}
static public String dropNumberPrefix(String s) {
return dropFirst(s, indexOfNonDigit(s));
}
static public String shortClassName(Object o) {
if (o == null)
return null;
Class c = o instanceof Class ? (Class) o : o.getClass();
String name = c.getName();
return shortenClassName(name);
}
static public RuntimeException asRuntimeException(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
return t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static public String getClassName(Object o) {
return o == null ? "null" : o instanceof Class ? ((Class) o).getName() : o.getClass().getName();
}
static public int iteratorCount_int_close(Iterator i) {
try {
int n = 0;
if (i != null)
while (i.hasNext()) {
i.next();
++n;
}
if (i instanceof AutoCloseable)
((AutoCloseable) i).close();
return n;
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public boolean eq(Object a, Object b) {
return a == b || a != null && b != null && a.equals(b);
}
static public boolean eq(Symbol a, String b) {
return eq(str(a), b);
}
static public String str(Object o) {
return o == null ? "null" : o.toString();
}
static public String str(char[] c) {
return new String(c);
}
static public String str(char[] c, int offset, int count) {
return new String(c, offset, count);
}
static public Map newDangerousWeakHashMap() {
return _registerDangerousWeakMap(synchroMap(new WeakHashMap()));
}
static public Map newDangerousWeakHashMap(Object initFunction) {
return _registerDangerousWeakMap(synchroMap(new WeakHashMap()), initFunction);
}
static public 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);
}
}
static public boolean call_checkArgs(Method m, Object[] args, boolean debug) {
Class>[] types = m.getParameterTypes();
if (types.length != l(args)) {
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;
}
static final public Map callOpt_cache = newDangerousWeakHashMap();
static public 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);
}
}
static public _MethodCache callOpt_getCache(Class c) {
_MethodCache cache = callOpt_cache.get(c);
if (cache == null)
callOpt_cache.put(c, cache = new _MethodCache(c));
return cache;
}
static public boolean isStaticMethod(Method m) {
return methodIsStatic(m);
}
static public Object[] massageArgsForVarArgsCall(Executable m, Object[] args) {
Class>[] types = m.getParameterTypes();
int n = types.length - 1, nArgs = l(args);
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);
int nVarArgs = nArgs - n;
Object varArgs = Array.newInstance(varArgType, nVarArgs);
for (int i = 0; i < nVarArgs; i++) Array.set(varArgs, i, args[n + i]);
newArgs[n] = varArgs;
return newArgs;
}
static public String joinWithComma(Collection c) {
return join(", ", c);
}
static public String joinWithComma(Object... c) {
return join(", ", c);
}
static public String joinWithComma(String... c) {
return join(", ", c);
}
static public String joinWithComma(Pair p) {
return p == null ? "" : joinWithComma(str(p.a), str(p.b));
}
static public List classNames(Collection l) {
return getClassNames(l);
}
static public List classNames(Object[] l) {
return getClassNames(asList(l));
}
static public RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static public RuntimeException rethrow(String msg, Throwable t) {
throw new RuntimeException(msg, t);
}
static public A get(List l, int idx) {
return l != null && idx >= 0 && idx < l(l) ? l.get(idx) : null;
}
static public A get(A[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : null;
}
static public boolean get(boolean[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : false;
}
static public Object get(Object o, String field) {
try {
if (o == null)
return null;
if (o instanceof Class)
return get((Class) o, field);
if (o instanceof Map)
return ((Map) o).get(field);
Field f = getOpt_findField(o.getClass(), field);
if (f != null) {
makeAccessible(f);
return f.get(o);
}
if (o instanceof DynamicObject)
return getOptDynOnly(((DynamicObject) o), field);
} catch (Exception e) {
throw asRuntimeException(e);
}
throw new RuntimeException("Field '" + field + "' not found in " + o.getClass().getName());
}
static public Object get_raw(String field, Object o) {
return get_raw(o, field);
}
static public Object get_raw(Object o, String field) {
try {
if (o == null)
return null;
Field f = get_findField(o.getClass(), field);
makeAccessible(f);
return f.get(o);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Object get(Class c, String field) {
try {
Field f = get_findStaticField(c, field);
makeAccessible(f);
return f.get(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static public Field get_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Static field '" + field + "' not found in " + c.getName());
}
static public Field get_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Field '" + field + "' not found in " + c.getName());
}
static public Object get(String field, Object o) {
return get(o, field);
}
static public boolean get(BitSet bs, int idx) {
return bs != null && bs.get(idx);
}
static public void vmBus_send(String msg, Object... args) {
Object arg = vmBus_wrapArgs(args);
pcallFAll_minimalExceptionHandling(vm_busListeners_live(), msg, arg);
pcallFAll_minimalExceptionHandling(vm_busListenersByMessage_live().get(msg), msg, arg);
}
static public void vmBus_send(String msg) {
vmBus_send(msg, (Object) null);
}
static public boolean isTrueOrYes(Object o) {
return isTrueOpt(o) || o instanceof String && (eqicOneOf(((String) o), "1", "t", "true") || isYes(((String) o)));
}
static public LinkedHashMap asLinkedHashMap(Map map) {
if (map instanceof LinkedHashMap)
return (LinkedHashMap) map;
LinkedHashMap m = new LinkedHashMap();
if (map != null)
synchronized (collectionMutex(map)) {
m.putAll(map);
}
return m;
}
static public String[] dropFirst(int n, String[] a) {
return drop(n, a);
}
static public String[] dropFirst(String[] a) {
return drop(1, a);
}
static public Object[] dropFirst(Object[] a) {
return drop(1, a);
}
static public List dropFirst(List l) {
return dropFirst(1, l);
}
static public List dropFirst(int n, Iterable i) {
return dropFirst(n, toList(i));
}
static public List dropFirst(Iterable i) {
return dropFirst(toList(i));
}
static public List dropFirst(int n, List l) {
return n <= 0 ? l : new ArrayList(l.subList(Math.min(n, l.size()), l.size()));
}
static public List dropFirst(List l, int n) {
return dropFirst(n, l);
}
static public String dropFirst(int n, String s) {
return substring(s, n);
}
static public String dropFirst(String s, int n) {
return substring(s, n);
}
static public String dropFirst(String s) {
return substring(s, 1);
}
static public Chain dropFirst(Chain c) {
return c == null ? null : c.next;
}
static public int indexOfNonDigit(String s) {
int n = l(s);
for (int i = 0; i < n; i++) if (!isDigit(s.charAt(i)))
return i;
return -1;
}
static public String shortenClassName(String name) {
if (name == null)
return null;
int i = lastIndexOf(name, "$");
if (i < 0)
i = lastIndexOf(name, ".");
return i < 0 ? name : substring(name, i + 1);
}
static public void _handleError(Error e) {
}
static public List _registerDangerousWeakMap_preList;
static public A _registerDangerousWeakMap(A map) {
return _registerDangerousWeakMap(map, null);
}
static public A _registerDangerousWeakMap(A map, Object init) {
callF(init, map);
if (init instanceof String) {
final String f = (String) init;
init = new VF1() {
public void get(Map map) {
try {
callMC(f, map);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callMC(f, map)";
}
};
}
if (javax() == null) {
if (_registerDangerousWeakMap_preList == null)
_registerDangerousWeakMap_preList = synchroList();
_registerDangerousWeakMap_preList.add(pair(map, init));
return map;
}
call(javax(), "_registerDangerousWeakMap", map, init);
return map;
}
static public void _onLoad_registerDangerousWeakMap() {
assertNotNull(javax());
if (_registerDangerousWeakMap_preList == null)
return;
for (Pair p : _registerDangerousWeakMap_preList) _registerDangerousWeakMap(p.a, p.b);
_registerDangerousWeakMap_preList = null;
}
static public Map synchroMap() {
return synchroHashMap();
}
static public Map synchroMap(Map map) {
return Collections.synchronizedMap(map);
}
static public Throwable getExceptionCause(Throwable e) {
Throwable c = e.getCause();
return c != null ? c : e;
}
static public String joinWithSpace(Iterable c) {
return join(" ", c);
}
static public String joinWithSpace(String... c) {
return join(" ", c);
}
static volatile public StringBuffer local_log = new StringBuffer();
static public boolean printAlsoToSystemOut = true;
static volatile public Appendable print_log = local_log;
static volatile public int print_log_max = 1024 * 1024;
static volatile public int local_log_max = 100 * 1024;
static public boolean print_silent = false;
static public Object print_byThread_lock = new Object();
static volatile public ThreadLocal print_byThread;
static volatile public Object print_allThreads;
static volatile public Object print_preprocess;
static public void print() {
print("");
}
static public A print(String s, A o) {
print(combinePrintParameters(s, o));
return o;
}
static public A print(A o) {
ping_okInCleanUp();
if (print_silent)
return o;
String s = o + "\n";
print_noNewLine(s);
return o;
}
static public void print_noNewLine(String s) {
try {
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;
} catch (Throwable e) {
System.out.println(getStackTrace(e));
}
print_raw(s);
}
static public 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);
if (printAlsoToSystemOut)
System.out.print(s);
vmBus_send("printed", mc(), s);
}
static public void print_autoRotate() {
}
static public 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);
}
static public boolean methodIsStatic(Method m) {
return (m.getModifiers() & Modifier.STATIC) != 0;
}
static public boolean argumentCompatibleWithType(Object arg, Class type) {
return arg == null ? !type.isPrimitive() : isInstanceX(type, arg);
}
static public void arraycopy(Object[] a, Object[] b) {
if (a != null && b != null)
arraycopy(a, 0, b, 0, Math.min(a.length, b.length));
}
static public void arraycopy(Object src, int srcPos, int destPos, int n) {
arraycopy(src, srcPos, src, destPos, n);
}
static public void arraycopy(Object src, int srcPos, Object dest, int destPos, int n) {
if (n != 0)
System.arraycopy(src, srcPos, dest, destPos, 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(String glue, Object... strings) {
return join(glue, Arrays.asList(strings));
}
static public String join(Iterable strings) {
return join("", strings);
}
static public String join(Iterable strings, String glue) {
return join(glue, strings);
}
public static String join(String[] strings) {
return join("", strings);
}
static public String join(String glue, Pair p) {
return p == null ? "" : str(p.a) + glue + str(p.b);
}
static public List getClassNames(Collection l) {
List out = new ArrayList();
if (l != null)
for (Object o : l) out.add(o == null ? null : getClassName(o));
return out;
}
static public ArrayList asList(A[] a) {
return a == null ? new ArrayList () : new ArrayList (Arrays.asList(a));
}
static public ArrayList asList(int[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (int i : a) l.add(i);
return l;
}
static public ArrayList asList(long[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (long i : a) l.add(i);
return l;
}
static public ArrayList asList(float[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (float i : a) l.add(i);
return l;
}
static public ArrayList asList(double[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (double i : a) l.add(i);
return l;
}
static public ArrayList asList(short[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (short i : a) l.add(i);
return l;
}
static public ArrayList asList(Iterator it) {
ArrayList l = new ArrayList();
if (it != null)
while (it.hasNext()) l.add(it.next());
return l;
}
static public ArrayList asList(IterableIterator s) {
return asList((Iterator) s);
}
static public ArrayList asList(Iterable s) {
if (s instanceof ArrayList)
return (ArrayList) s;
ArrayList l = new ArrayList();
if (s != null)
for (A a : s) l.add(a);
return l;
}
static public ArrayList asList(Producer p) {
ArrayList l = new ArrayList();
A a;
if (p != null)
while ((a = p.next()) != null) l.add(a);
return l;
}
static public ArrayList asList(Enumeration e) {
ArrayList l = new ArrayList();
if (e != null)
while (e.hasMoreElements()) l.add(e.nextElement());
return l;
}
static public ArrayList asList(ReverseChain c) {
return c == null ? emptyList() : c.toList();
}
static public List asList(Pair p) {
return p == null ? null : ll(p.a, p.b);
}
static public Field getOpt_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
return null;
}
static public Object getOptDynOnly(DynamicObject o, String field) {
if (o == null || o.fieldValues == null)
return null;
return o.fieldValues.get(field);
}
static public Object vmBus_wrapArgs(Object... args) {
return empty(args) ? null : l(args) == 1 ? args[0] : args;
}
static public void pcallFAll_minimalExceptionHandling(Collection l, Object... args) {
if (l != null)
for (Object f : cloneList(l)) {
ping();
pcallF_minimalExceptionHandling(f, args);
}
}
static public void pcallFAll_minimalExceptionHandling(Iterator it, Object... args) {
while (it.hasNext()) {
ping();
pcallF_minimalExceptionHandling(it.next(), args);
}
}
static public Set vm_busListeners_live_cache;
static public Set vm_busListeners_live() {
if (vm_busListeners_live_cache == null)
vm_busListeners_live_cache = vm_busListeners_live_load();
return vm_busListeners_live_cache;
}
static public Set vm_busListeners_live_load() {
return vm_generalIdentityHashSet("busListeners");
}
static public Map vm_busListenersByMessage_live_cache;
static public Map vm_busListenersByMessage_live() {
if (vm_busListenersByMessage_live_cache == null)
vm_busListenersByMessage_live_cache = vm_busListenersByMessage_live_load();
return vm_busListenersByMessage_live_cache;
}
static public Map vm_busListenersByMessage_live_load() {
return vm_generalHashMap("busListenersByMessage");
}
static public boolean isTrueOpt(Object o) {
if (o instanceof Boolean)
return ((Boolean) o).booleanValue();
return false;
}
static public boolean isTrueOpt(String field, Object o) {
return isTrueOpt(getOpt(field, o));
}
static public boolean eqicOneOf(String s, String... l) {
for (String x : l) if (eqic(s, x))
return true;
return false;
}
static public List isYes_yesses = litlist("y", "yes", "yeah", "y", "yup", "yo", "corect", "sure", "ok", "afirmative");
static public boolean isYes(String s) {
return isYes_yesses.contains(collapseWord(toLowerCase(firstWord2(s))));
}
static public Object collectionMutex(List l) {
return l;
}
static public Object collectionMutex(Object o) {
if (o instanceof List)
return o;
String c = className(o);
return o;
}
static public 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;
}
static public 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;
}
static public ArrayList toList(A[] a) {
return asList(a);
}
static public ArrayList toList(int[] a) {
return asList(a);
}
static public ArrayList toList(Set s) {
return asList(s);
}
static public ArrayList toList(Iterable s) {
return asList(s);
}
static public String substring(String s, int x) {
return substring(s, x, strL(s));
}
static public String substring(String s, int x, int y) {
if (s == null)
return null;
if (x < 0)
x = 0;
int n = s.length();
if (y < x)
y = x;
if (y > n)
y = n;
if (x >= y)
return "";
return s.substring(x, y);
}
static public String substring(String s, IntRange r) {
return r == null ? null : substring(s, r.start, r.end);
}
static public String substring(String s, CharSequence l) {
return substring(s, lCharSequence(l));
}
static public boolean isDigit(char c) {
return Character.isDigit(c);
}
static public int lastIndexOf(String a, String b) {
return a == null || b == null ? -1 : a.lastIndexOf(b);
}
static public int lastIndexOf(String a, char b) {
return a == null ? -1 : a.lastIndexOf(b);
}
static public int lastIndexOf(List l, int i, A a) {
if (l == null)
return -1;
for (i = min(l(l), i) - 1; i >= 0; i--) if (eq(l.get(i), a))
return i;
return -1;
}
static public int lastIndexOf(List l, A a) {
if (l == null)
return -1;
for (int i = l(l) - 1; i >= 0; i--) if (eq(l.get(i), a))
return i;
return -1;
}
static public AutoCloseable tempInterceptPrintIfNotIntercepted(F1 f) {
return print_byThread().get() == null ? tempInterceptPrint(f) : null;
}
static public HashMap> callMC_cache = new HashMap();
static public String callMC_key;
static public Method callMC_value;
static public Object callMC(String method, String[] arg) {
return callMC(method, new Object[] { arg });
}
static public Object callMC(String method, Object... args) {
try {
Method me;
if (callMC_cache == null)
callMC_cache = new HashMap();
synchronized (callMC_cache) {
me = method == callMC_key ? callMC_value : null;
}
if (me != null)
try {
return invokeMethod(me, null, args);
} catch (IllegalArgumentException e) {
throw new RuntimeException("Can't call " + me + " with arguments " + classNames(args), e);
}
List m;
synchronized (callMC_cache) {
m = callMC_cache.get(method);
}
if (m == null) {
if (callMC_cache.isEmpty()) {
callMC_makeCache();
m = callMC_cache.get(method);
}
if (m == null)
throw fail("Method named " + method + " not found in main");
}
int n = m.size();
if (n == 1) {
me = m.get(0);
synchronized (callMC_cache) {
callMC_key = method;
callMC_value = me;
}
try {
return invokeMethod(me, null, args);
} catch (IllegalArgumentException e) {
throw new RuntimeException("Can't call " + me + " with arguments " + classNames(args), e);
}
}
for (int i = 0; i < n; i++) {
me = m.get(i);
if (call_checkArgs(me, args, false))
return invokeMethod(me, null, args);
}
throw fail("No method called " + method + " with arguments (" + joinWithComma(getClasses(args)) + ") found in main");
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public void callMC_makeCache() {
synchronized (callMC_cache) {
callMC_cache.clear();
Class _c = (Class) mc(), c = _c;
while (c != null) {
for (Method m : c.getDeclaredMethods()) if ((m.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0) {
makeAccessible(m);
multiMapPut(callMC_cache, m.getName(), m);
}
c = c.getSuperclass();
}
}
}
static public Class javax() {
return getJavaX();
}
static public List synchroList() {
return synchroList(new ArrayList ());
}
static public List synchroList(List l) {
return Collections.synchronizedList(l);
}
static public Pair pair(A a, B b) {
return new Pair(a, b);
}
static public Pair pair(A a) {
return new Pair(a, a);
}
static public A assertNotNull(A a) {
assertTrue(a != null);
return a;
}
static public A assertNotNull(String msg, A a) {
assertTrue(msg, a != null);
return a;
}
static public Map synchroHashMap() {
return synchronizedMap(new HashMap());
}
static public String combinePrintParameters(String s, Object o) {
return (endsWithLetterOrDigit(s) ? s + ": " : s) + o;
}
static public void ping_okInCleanUp() {
if (ping_pauseAll || ping_anyActions)
ping_impl(true);
}
static public Object getThreadLocal(Object o, String name) {
ThreadLocal t = (ThreadLocal) (getOpt(o, name));
return t != null ? t.get() : null;
}
static public A getThreadLocal(ThreadLocal tl) {
return tl == null ? null : tl.get();
}
static public A getThreadLocal(ThreadLocal tl, A defaultValue) {
return or(getThreadLocal(tl), defaultValue);
}
static public ThreadLocal print_byThread_dontCreate() {
return print_byThread;
}
static public boolean isFalse(Object o) {
return eq(false, o);
}
static public String getStackTrace(Throwable throwable) {
lastException(throwable);
return getStackTrace_noRecord(throwable);
}
static public String getStackTrace_noRecord(Throwable throwable) {
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
return hideCredentials(writer.toString());
}
static public String getStackTrace() {
return getStackTrace_noRecord(new Throwable());
}
static public String getStackTrace(String msg) {
return getStackTrace_noRecord(new Throwable(msg));
}
static public 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();
}
static public 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);
}
}
static public Class mc() {
return main.class;
}
static public Object first(Object list) {
return first((Iterable) list);
}
static public A first(List list) {
return empty(list) ? null : list.get(0);
}
static public A first(A[] bla) {
return bla == null || bla.length == 0 ? null : bla[0];
}
static public Pair first(Map map) {
return mapEntryToPair(first(entrySet(map)));
}
static public Pair first(MultiMap mm) {
if (mm == null)
return null;
var e = first(mm.data.entrySet());
if (e == null)
return null;
return pair(e.getKey(), first(e.getValue()));
}
static public A first(IterableIterator i) {
return first((Iterator ) i);
}
static public A first(Iterator i) {
return i == null || !i.hasNext() ? null : i.next();
}
static public A first(Iterable i) {
if (i == null)
return null;
Iterator it = i.iterator();
return it.hasNext() ? it.next() : null;
}
static public Character first(String s) {
return empty(s) ? null : s.charAt(0);
}
static public Character first(CharSequence s) {
return empty(s) ? null : s.charAt(0);
}
static public A first(Pair p) {
return p == null ? null : p.a;
}
static public A first(T3 t) {
return t == null ? null : t.a;
}
static public Byte first(byte[] l) {
return empty(l) ? null : l[0];
}
static public A first(A[] l, IF1 pred) {
return firstThat(l, pred);
}
static public A first(Iterable l, IF1 pred) {
return firstThat(l, pred);
}
static public A first(IF1 pred, Iterable l) {
return firstThat(pred, l);
}
static public A first(AppendableChain a) {
return a == null ? null : a.element;
}
static public ArrayList emptyList() {
return new ArrayList();
}
static public ArrayList emptyList(int capacity) {
return new ArrayList(max(0, capacity));
}
static public ArrayList emptyList(Iterable l) {
return l instanceof Collection ? emptyList(((Collection) l).size()) : emptyList();
}
static public ArrayList emptyList(Object[] l) {
return emptyList(l(l));
}
static public ArrayList emptyList(Class c) {
return new ArrayList();
}
static public List ll(A... a) {
ArrayList l = new ArrayList(a.length);
if (a != null)
for (A x : a) l.add(x);
return l;
}
static public boolean empty(Collection c) {
return c == null || c.isEmpty();
}
static public boolean empty(Iterable c) {
return c == null || !c.iterator().hasNext();
}
static public boolean empty(CharSequence s) {
return s == null || s.length() == 0;
}
static public boolean empty(Map map) {
return map == null || map.isEmpty();
}
static public boolean empty(Object[] o) {
return o == null || o.length == 0;
}
static public boolean empty(BitSet bs) {
return bs == null || bs.isEmpty();
}
static public 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));
}
static public boolean empty(Iterator i) {
return i == null || !i.hasNext();
}
static public boolean empty(double[] a) {
return a == null || a.length == 0;
}
static public boolean empty(float[] a) {
return a == null || a.length == 0;
}
static public boolean empty(int[] a) {
return a == null || a.length == 0;
}
static public boolean empty(long[] a) {
return a == null || a.length == 0;
}
static public boolean empty(byte[] a) {
return a == null || a.length == 0;
}
static public boolean empty(short[] a) {
return a == null || a.length == 0;
}
static public boolean empty(MultiSet ms) {
return ms == null || ms.isEmpty();
}
static public boolean empty(IMultiMap mm) {
return mm == null || mm.size() == 0;
}
static public boolean empty(File f) {
return getFileSize(f) == 0;
}
static public boolean empty(IntRange r) {
return r == null || r.empty();
}
static public boolean empty(Rect r) {
return !(r != null && r.w != 0 && r.h != 0);
}
static public boolean empty(Chain c) {
return c == null;
}
static public boolean empty(AppendableChain c) {
return c == null;
}
static public ArrayList cloneList(Iterable l) {
return l instanceof Collection ? cloneList((Collection) l) : asList(l);
}
static public ArrayList cloneList(Collection l) {
if (l == null)
return new ArrayList();
synchronized (collectionMutex(l)) {
return new ArrayList (l);
}
}
static volatile public boolean ping_pauseAll = false;
static public int ping_sleep = 100;
static volatile public boolean ping_anyActions = false;
static public Map ping_actions = newWeakHashMap();
static public ThreadLocal ping_isCleanUpThread = new ThreadLocal();
static public boolean ping(PingSource pingSource) {
return ping();
}
static public boolean ping() {
newPing();
if (ping_pauseAll || ping_anyActions)
ping_impl(true);
return true;
}
static public 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);
}
}
static public Object pcallF_minimalExceptionHandling(Object f, Object... args) {
try {
return callFunction(f, args);
} catch (Throwable e) {
System.out.println(getStackTrace(e));
_storeException(e);
}
return null;
}
static public Set vm_generalIdentityHashSet(Object name) {
synchronized (vm_generalMap()) {
Set set = (Set) (vm_generalMap_get(name));
if (set == null)
vm_generalMap_put(name, set = syncIdentityHashSet());
return set;
}
}
static public Map vm_generalHashMap(Object name) {
synchronized (vm_generalMap()) {
Map m = (Map) (vm_generalMap_get(name));
if (m == null)
vm_generalMap_put(name, m = syncHashMap());
return m;
}
}
static public Object getOpt(Object o, String field) {
return getOpt_cached(o, field);
}
static public Object getOpt(String field, Object o) {
return getOpt_cached(o, field);
}
static public Object getOpt_raw(Object o, String field) {
try {
Field f = getOpt_findField(o.getClass(), field);
if (f == null)
return null;
makeAccessible(f);
return f.get(o);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Object getOpt(Class c, String field) {
try {
if (c == null)
return null;
Field f = getOpt_findStaticField(c, field);
if (f == null)
return null;
makeAccessible(f);
return f.get(null);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Field getOpt_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
return null;
}
static public boolean eqic(String a, String b) {
if ((a == null) != (b == null))
return false;
if (a == null)
return true;
return a.equalsIgnoreCase(b);
}
static public boolean eqic(Symbol a, Symbol b) {
return eq(a, b);
}
static public boolean eqic(Symbol a, String b) {
return eqic(asString(a), b);
}
static public 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);
}
static public ArrayList litlist(A... a) {
ArrayList l = new ArrayList(a.length);
for (A x : a) l.add(x);
return l;
}
static public String collapseWord(String s) {
if (s == null)
return "";
StringBuilder buf = new StringBuilder();
for (int i = 0; i < l(s); i++) if (i == 0 || !charactersEqualIC(s.charAt(i), s.charAt(i - 1)))
buf.append(s.charAt(i));
return buf.toString();
}
static public List toLowerCase(List strings) {
List x = new ArrayList();
for (String s : strings) x.add(s.toLowerCase());
return x;
}
static public String[] toLowerCase(String[] strings) {
String[] x = new String[l(strings)];
for (int i = 0; i < l(strings); i++) x[i] = strings[i].toLowerCase();
return x;
}
static public String toLowerCase(String s) {
return s == null ? "" : s.toLowerCase();
}
static public String firstWord2(String s) {
s = xltrim(s);
if (empty(s))
return "";
if (isLetterOrDigit(first(s)))
return takeCharsWhile(__20 -> isLetterOrDigit(__20), s);
else
return "" + first(s);
}
static public int strL(String s) {
return s == null ? 0 : s.length();
}
static public int lCharSequence(CharSequence s) {
return s == null ? 0 : s.length();
}
static public int min(int a, int b) {
return Math.min(a, b);
}
static public long min(long a, long b) {
return Math.min(a, b);
}
static public float min(float a, float b) {
return Math.min(a, b);
}
static public float min(float a, float b, float c) {
return min(min(a, b), c);
}
static public double min(double a, double b) {
return Math.min(a, b);
}
static public double min(double[] c) {
double x = Double.MAX_VALUE;
for (double d : c) x = Math.min(x, d);
return x;
}
static public float min(float[] c) {
float x = Float.MAX_VALUE;
for (float d : c) x = Math.min(x, d);
return x;
}
static public byte min(byte[] c) {
byte x = 127;
for (byte d : c) if (d < x)
x = d;
return x;
}
static public short min(short[] c) {
short x = 0x7FFF;
for (short d : c) if (d < x)
x = d;
return x;
}
static public int min(int[] c) {
int x = Integer.MAX_VALUE;
for (int d : c) if (d < x)
x = d;
return x;
}
static public ThreadLocal print_byThread() {
synchronized (print_byThread_lock) {
if (print_byThread == null)
print_byThread = new ThreadLocal();
}
return print_byThread;
}
static public AutoCloseable tempInterceptPrint(F1 f) {
return tempSetThreadLocal(print_byThread(), f);
}
static public List getClasses(Object[] array) {
List l = emptyList(l(array));
for (Object o : array) l.add(_getClass(o));
return l;
}
static public 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);
}
static public void multiMapPut(MultiMap mm, A key, B value) {
if (mm != null && key != null && value != null)
mm.put(key, value);
}
static public Class __javax;
static public Class getJavaX() {
try {
return __javax;
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public void __setJavaX(Class j) {
__javax = j;
_onJavaXSet();
}
static public Map synchronizedMap() {
return synchroMap();
}
static public Map synchronizedMap(Map map) {
return synchroMap(map);
}
static public boolean endsWithLetterOrDigit(String s) {
return s != null && s.length() > 0 && Character.isLetterOrDigit(s.charAt(s.length() - 1));
}
static public A or(A a, A b) {
return a != null ? a : b;
}
static volatile public PersistableThrowable lastException_lastException;
static public PersistableThrowable lastException() {
return lastException_lastException;
}
static public void lastException(Throwable e) {
lastException_lastException = persistableThrowable(e);
}
static public String hideCredentials(URL url) {
return url == null ? null : hideCredentials(str(url));
}
static public 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|cookie)=[^&\\s\"]*", "$1$2=");
}
static public String hideCredentials(Object o) {
return hideCredentials(str(o));
}
static public int indexOf(List l, A a, int startIndex) {
if (l == null)
return -1;
int n = l(l);
for (int i = startIndex; i < n; i++) if (eq(l.get(i), a))
return i;
return -1;
}
static public int indexOf(List l, int startIndex, A a) {
return indexOf(l, a, startIndex);
}
static public int indexOf(List l, A a) {
if (l == null)
return -1;
return l.indexOf(a);
}
static public int indexOf(String a, String b) {
return a == null || b == null ? -1 : a.indexOf(b);
}
static public int indexOf(String a, String b, int i) {
return a == null || b == null ? -1 : a.indexOf(b, i);
}
static public int indexOf(String a, char b) {
return a == null ? -1 : a.indexOf(b);
}
static public int indexOf(String a, int i, char b) {
return indexOf(a, b, i);
}
static public int indexOf(String a, char b, int i) {
return a == null ? -1 : a.indexOf(b, i);
}
static public int indexOf(String a, int i, String b) {
return a == null || b == null ? -1 : a.indexOf(b, i);
}
static public int indexOf(A[] x, A a) {
int n = l(x);
for (int i = 0; i < n; i++) if (eq(x[i], a))
return i;
return -1;
}
static public int indexOf(Iterable l, A a) {
if (l == null)
return -1;
int i = 0;
for (A x : l) {
if (eq(x, a))
return i;
i++;
}
return -1;
}
static public 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);
}
}
static public 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);
}
}
static public Pair mapEntryToPair(Map.Entry e) {
return e == null ? null : pair(e.getKey(), e.getValue());
}
static public Set> entrySet(Map map) {
return _entrySet(map);
}
static public A firstThat(Iterable l, IF1 pred) {
for (A a : unnullForIteration(l)) if (pred.get(a))
return a;
return null;
}
static public A firstThat(A[] l, IF1 pred) {
for (A a : unnullForIteration(l)) if (pred.get(a))
return a;
return null;
}
static public A firstThat(IF1 pred, Iterable l) {
return firstThat(l, pred);
}
static public A firstThat(IF1 pred, A[] l) {
return firstThat(l, pred);
}
static public int max(int a, int b) {
return Math.max(a, b);
}
static public int max(int a, int b, int c) {
return max(max(a, b), c);
}
static public long max(int a, long b) {
return Math.max((long) a, b);
}
static public long max(long a, long b) {
return Math.max(a, b);
}
static public double max(int a, double b) {
return Math.max((double) a, b);
}
static public float max(float a, float b) {
return Math.max(a, b);
}
static public double max(double a, double b) {
return Math.max(a, b);
}
static public int max(Collection c) {
int x = Integer.MIN_VALUE;
for (int i : c) x = max(x, i);
return x;
}
static public double max(double[] c) {
if (c.length == 0)
return Double.MIN_VALUE;
double x = c[0];
for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]);
return x;
}
static public float max(float[] c) {
if (c.length == 0)
return Float.MAX_VALUE;
float x = c[0];
for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]);
return x;
}
static public byte max(byte[] c) {
byte x = -128;
for (byte d : c) if (d > x)
x = d;
return x;
}
static public short max(short[] c) {
short x = -0x8000;
for (short d : c) if (d > x)
x = d;
return x;
}
static public int max(int[] c) {
int x = Integer.MIN_VALUE;
for (int d : c) if (d > x)
x = d;
return x;
}
static public > A max(A a, A b) {
return cmp(a, b) >= 0 ? a : b;
}
static public String getType(Object o) {
return getClassName(o);
}
static public long getFileSize(String path) {
return path == null ? 0 : new File(path).length();
}
static public long getFileSize(File f) {
return f == null ? 0 : f.length();
}
static public Map newWeakHashMap() {
return _registerWeakMap(synchroMap(new WeakHashMap()));
}
static public void newPing() {
var tl = newPing_actionTL();
Runnable action = tl == null ? null : tl.get();
{
if (action != null)
action.run();
}
}
static public boolean isAWTThread() {
if (isAndroid())
return false;
if (isHeadless())
return false;
return isAWTThread_awt();
}
static public boolean isAWTThread_awt() {
return SwingUtilities.isEventDispatchThread();
}
static public boolean isTrue(Object o) {
if (o instanceof Boolean)
return ((Boolean) o).booleanValue();
if (o == null)
return false;
if (o instanceof ThreadLocal)
return isTrue(((ThreadLocal) o).get());
throw fail(getClassName(o));
}
static public boolean isTrue(Boolean b) {
return b != null && b.booleanValue();
}
static public void failIfUnlicensed() {
assertTrue("license off", licensed());
}
static public Thread currentThread() {
return Thread.currentThread();
}
static public Object callFunction(Object f, Object... args) {
return callF(f, args);
}
static public Throwable _storeException_value;
static public void _storeException(Throwable e) {
_storeException_value = e;
}
static public Map vm_generalMap_map;
static public Map vm_generalMap() {
if (vm_generalMap_map == null)
vm_generalMap_map = (Map) get(javax(), "generalMap");
return vm_generalMap_map;
}
static public Object vm_generalMap_get(Object key) {
return vm_generalMap().get(key);
}
static public Object vm_generalMap_put(Object key, Object value) {
return mapPutOrRemove(vm_generalMap(), key, value);
}
static public Set syncIdentityHashSet() {
return (Set) synchronizedSet(identityHashSet());
}
static public Map syncHashMap() {
return synchroHashMap();
}
static public class getOpt_Map extends WeakHashMap {
public getOpt_Map() {
if (getOpt_special == null)
getOpt_special = new HashMap();
clear();
}
public void clear() {
super.clear();
put(Class.class, getOpt_special);
put(String.class, getOpt_special);
}
}
static final public Map> getOpt_cache = _registerDangerousWeakMap(synchroMap(new getOpt_Map()));
static public HashMap getOpt_special;
static public Map getOpt_getFieldMap(Object o) {
Class c = _getClass(o);
HashMap map = getOpt_cache.get(c);
if (map == null)
map = getOpt_makeCache(c);
return map;
}
static public Object getOpt_cached(Object o, String field) {
try {
if (o == null)
return null;
Map map = getOpt_getFieldMap(o);
if (map == getOpt_special) {
if (o instanceof Class)
return getOpt((Class) o, field);
if (o instanceof Map)
return ((Map) o).get(field);
}
Field f = map.get(field);
if (f != null)
return f.get(o);
if (o instanceof DynamicObject)
return syncMapGet2(((DynamicObject) o).fieldValues, field);
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public HashMap getOpt_makeCache(Class c) {
HashMap map;
if (isSubtypeOf(c, Map.class))
map = getOpt_special;
else {
map = new HashMap();
if (!reflection_classesNotToScan().contains(c.getName())) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) {
makeAccessible(f);
String name = f.getName();
if (!map.containsKey(name))
map.put(name, f);
}
_c = _c.getSuperclass();
} while (_c != null);
}
}
if (getOpt_cache != null)
getOpt_cache.put(c, map);
return map;
}
static public String asString(Object o) {
return o == null ? null : o.toString();
}
static public boolean charactersEqualIC(char c1, char c2) {
if (c1 == c2)
return true;
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2)
return true;
return Character.toLowerCase(u1) == Character.toLowerCase(u2);
}
static public String xltrim(String s) {
int i = 0, n = l(s);
while (i < n && contains(" \t\r\n", s.charAt(i))) ++i;
return substr(s, i);
}
static public boolean isLetterOrDigit(char c) {
return Character.isLetterOrDigit(c);
}
static public String takeCharsWhile(String s, Object pred) {
int i = 0;
while (i < l(s) && isTrue(callF(pred, s.charAt(i)))) ++i;
return substring(s, 0, i);
}
static public String takeCharsWhile(IF1 f, String s) {
return takeCharsWhile(s, f);
}
static public 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);
}
};
}
static public Class> _getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
return null;
}
}
static public Class _getClass(Object o) {
return o == null ? null : o instanceof Class ? (Class) o : o.getClass();
}
static public Class _getClass(Object realm, String name) {
try {
return classLoaderForObject(realm).loadClass(classNameToVM(name));
} catch (ClassNotFoundException e) {
return null;
}
}
static public void _onJavaXSet() {
}
static public PersistableThrowable persistableThrowable(Throwable e) {
return e == null ? null : new PersistableThrowable(e);
}
static public boolean startsWithOneOf(String s, String... l) {
for (String x : l) if (startsWith(s, x))
return true;
return false;
}
static public boolean startsWithOneOf(String s, Matches m, String... l) {
for (String x : l) if (startsWith(s, x, m))
return true;
return false;
}
static public boolean isAGIBlueDomain(String domain) {
return domainIsUnder(domain, theAGIBlueDomain());
}
static public String hostNameFromURL(String url) {
try {
return empty(url) ? null : new URL(url).getHost();
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Set> _entrySet(Map map) {
return map == null ? Collections.EMPTY_SET : map.entrySet();
}
static public String unnullForIteration(String s) {
return s == null ? "" : s;
}
static public Collection unnullForIteration(Collection l) {
return l == null ? immutableEmptyList() : l;
}
static public List unnullForIteration(List l) {
return l == null ? immutableEmptyList() : l;
}
static public int[] unnullForIteration(int[] l) {
return l == null ? emptyIntArray() : l;
}
static public char[] unnullForIteration(char[] l) {
return l == null ? emptyCharArray() : l;
}
static public double[] unnullForIteration(double[] l) {
return l == null ? emptyDoubleArray() : l;
}
static public short[] unnullForIteration(short[] l) {
return l == null ? emptyShortArray() : l;
}
static public Map unnullForIteration(Map l) {
return l == null ? immutableEmptyMap() : l;
}
static public Iterable unnullForIteration(Iterable i) {
return i == null ? immutableEmptyList() : i;
}
static public A[] unnullForIteration(A[] a) {
return a == null ? (A[]) emptyObjectArray() : a;
}
static public BitSet unnullForIteration(BitSet b) {
return b == null ? new BitSet() : b;
}
static public Pt unnullForIteration(Pt p) {
return p == null ? new Pt() : p;
}
static public Symbol unnullForIteration(Symbol s) {
return s == null ? emptySymbol() : s;
}
static public Pair unnullForIteration(Pair p) {
return p != null ? p : new Pair(null, null);
}
static public long unnullForIteration(Long l) {
return l == null ? 0L : l;
}
static public int cmp(Number a, Number b) {
return a == null ? b == null ? 0 : -1 : cmp(a.doubleValue(), b.doubleValue());
}
static public int cmp(double a, double b) {
return a < b ? -1 : a == b ? 0 : 1;
}
static public int cmp(int a, int b) {
return a < b ? -1 : a == b ? 0 : 1;
}
static public int cmp(long a, long b) {
return a < b ? -1 : a == b ? 0 : 1;
}
static public int cmp(Object a, Object b) {
if (a == null)
return b == null ? 0 : -1;
if (b == null)
return 1;
return ((Comparable) a).compareTo(b);
}
static public List _registerWeakMap_preList;
static public A _registerWeakMap(A map) {
if (javax() == null) {
if (_registerWeakMap_preList == null)
_registerWeakMap_preList = synchroList();
_registerWeakMap_preList.add(map);
return map;
}
try {
call(javax(), "_registerWeakMap", map);
} catch (Throwable e) {
printException(e);
print("Upgrade JavaX!!");
}
return map;
}
static public void _onLoad_registerWeakMap() {
assertNotNull(javax());
if (_registerWeakMap_preList == null)
return;
for (Object o : _registerWeakMap_preList) _registerWeakMap(o);
_registerWeakMap_preList = null;
}
static public x30_pkg.x30_util.BetterThreadLocal newPing_actionTL;
static public x30_pkg.x30_util.BetterThreadLocal newPing_actionTL() {
if (newPing_actionTL == null)
newPing_actionTL = vm_generalMap_getOrCreate("newPing_actionTL", () -> {
Runnable value = (Runnable) (callF_gen(vm_generalMap_get("newPing_valueForNewThread")));
var tl = new x30_pkg.x30_util.BetterThreadLocal();
tl.set(value);
return tl;
});
return newPing_actionTL;
}
static public int isAndroid_flag;
static public boolean isAndroid() {
if (isAndroid_flag == 0)
isAndroid_flag = System.getProperty("java.vendor").toLowerCase().indexOf("android") >= 0 ? 1 : -1;
return isAndroid_flag > 0;
}
static public Boolean isHeadless_cache;
static public boolean isHeadless() {
if (isHeadless_cache != null)
return isHeadless_cache;
if (isAndroid())
return isHeadless_cache = true;
if (GraphicsEnvironment.isHeadless())
return isHeadless_cache = true;
try {
SwingUtilities.isEventDispatchThread();
return isHeadless_cache = false;
} catch (Throwable e) {
return isHeadless_cache = true;
}
}
static volatile public boolean licensed_yes = true;
static public boolean licensed() {
if (!licensed_yes)
return false;
ping_okInCleanUp();
return true;
}
static public void licensed_off() {
licensed_yes = false;
}
static public B mapPutOrRemove(Map map, A key, B value) {
if (map != null && key != null)
if (value != null)
return map.put(key, value);
else
return map.remove(key);
return null;
}
static public Set synchronizedSet() {
return synchroHashSet();
}
static public Set synchronizedSet(Set set) {
return Collections.synchronizedSet(set);
}
static public Set identityHashSet() {
return Collections.newSetFromMap(new IdentityHashMap());
}
static public void clear(Collection c) {
if (c != null)
c.clear();
}
static public void clear(Map map) {
if (map != null)
map.clear();
}
static public void put(Map map, A a, B b) {
if (map != null)
map.put(a, b);
}
static public void put(List l, int i, A a) {
if (l != null && i >= 0 && i < l(l))
l.set(i, a);
}
static public B syncMapGet2(Map map, A a) {
if (map == null)
return null;
synchronized (collectionMutex(map)) {
return map.get(a);
}
}
static public B syncMapGet2(A a, Map map) {
return syncMapGet2(map, a);
}
static public boolean isSubtypeOf(Class a, Class b) {
return a != null && b != null && b.isAssignableFrom(a);
}
static public Set reflection_classesNotToScan_value = litset("jdk.internal.loader.URLClassPath");
static public Set reflection_classesNotToScan() {
return reflection_classesNotToScan_value;
}
static public boolean contains(Collection c, Object o) {
return c != null && c.contains(o);
}
static public boolean contains(Iterable it, Object a) {
if (it != null)
for (Object o : it) if (eq(a, o))
return true;
return false;
}
static public boolean contains(Object[] x, Object o) {
if (x != null)
for (Object a : x) if (eq(a, o))
return true;
return false;
}
static public boolean contains(String s, char c) {
return s != null && s.indexOf(c) >= 0;
}
static public boolean contains(String s, String b) {
return s != null && s.indexOf(b) >= 0;
}
static public boolean contains(BitSet bs, int i) {
return bs != null && bs.get(i);
}
static public boolean contains(Producer p, A a) {
if (p != null && a != null)
while (true) {
A x = p.next();
if (x == null)
break;
if (eq(x, a))
return true;
}
return false;
}
static public boolean contains(Rect r, Pt p) {
return rectContains(r, p);
}
static public String substr(String s, int x) {
return substring(s, x);
}
static public String substr(String s, int x, int y) {
return substring(s, x, y);
}
static public A setThreadLocal(ThreadLocal tl, A value) {
if (tl == null)
return null;
A old = tl.get();
tl.set(value);
return old;
}
static public ClassLoader classLoaderForObject(Object o) {
if (o instanceof ClassLoader)
return ((ClassLoader) o);
if (o == null)
return null;
return _getClass(o).getClassLoader();
}
static public String classNameToVM(String name) {
return name.replace(".", "$");
}
static public boolean startsWith(String a, String b) {
return a != null && a.startsWith(unnull(b));
}
static public boolean startsWith(String a, char c) {
return nemptyString(a) && a.charAt(0) == c;
}
static public boolean startsWith(String a, String b, Matches m) {
if (!startsWith(a, b))
return false;
if (m != null)
m.m = new String[] { substring(a, strL(b)) };
return true;
}
static public 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;
}
static public boolean domainIsUnder(String domain, String mainDomain) {
return eqic(domain, mainDomain) || ewic(domain, "." + mainDomain);
}
static public String theAGIBlueDomain() {
return "agi.blue";
}
static public List immutableEmptyList() {
return Collections.emptyList();
}
static public int[] emptyIntArray_a = new int[0];
static public int[] emptyIntArray() {
return emptyIntArray_a;
}
static public char[] emptyCharArray = new char[0];
static public char[] emptyCharArray() {
return emptyCharArray;
}
static public double[] emptyDoubleArray = new double[0];
static public double[] emptyDoubleArray() {
return emptyDoubleArray;
}
static public short[] emptyShortArray = new short[0];
static public short[] emptyShortArray() {
return emptyShortArray;
}
static public Map immutableEmptyMap() {
return Collections.emptyMap();
}
static public Object[] emptyObjectArray_a = new Object[0];
static public Object[] emptyObjectArray() {
return emptyObjectArray_a;
}
static public Symbol emptySymbol_value;
static public Symbol emptySymbol() {
if (emptySymbol_value == null)
emptySymbol_value = symbol("");
return emptySymbol_value;
}
static public A printException(A e) {
printStackTrace(e);
return e;
}
static public A vm_generalMap_getOrCreate(Object key, F0 create) {
return vm_generalMap_getOrCreate(key, f0ToIF0(create));
}
static public A vm_generalMap_getOrCreate(Object key, IF0 create) {
Map generalMap = vm_generalMap();
if (generalMap == null)
return null;
synchronized (generalMap) {
A a = (A) (vm_generalMap_get(key));
if (a == null)
vm_generalMap_put(key, a = create == null ? null : create.get());
return a;
}
}
static public A callF_gen(F0 f) {
return f == null ? null : f.get();
}
static public B callF_gen(F1 f, A a) {
return f == null ? null : f.get(a);
}
static public A callF_gen(IF0 f) {
return f == null ? null : f.get();
}
static public B callF_gen(IF1 f, A a) {
return f == null ? null : f.get(a);
}
static public B callF_gen(A a, IF1 f) {
return f == null ? null : f.get(a);
}
static public C callF_gen(IF2 f, A a, B b) {
return f == null ? null : f.get(a, b);
}
static public void callF_gen(VF1 f, A a) {
{
if (f != null)
f.get(a);
}
}
static public void callF_gen(A a, IVF1 f) {
{
if (f != null)
f.get(a);
}
}
static public void callF_gen(IVF1 f, A a) {
{
if (f != null)
f.get(a);
}
}
static public Object callF_gen(Runnable r) {
{
if (r != null)
r.run();
}
return null;
}
static public Object callF_gen(Object f, Object... args) {
return callF(f, args);
}
static public Set synchroHashSet() {
return synchronizedSet(new HashSet ());
}
static public HashSet litset(A... items) {
return lithashset(items);
}
static public boolean rectContains(int x1, int y1, int w, int h, Pt p) {
return p.x >= x1 && p.y >= y1 && p.x < x1 + w && p.y < y1 + h;
}
static public boolean rectContains(Rect a, Rect b) {
return b.x >= a.x && b.y >= a.y && b.x2() <= a.x2() && b.y2() <= a.y2();
}
static public boolean rectContains(Rect a, Rectangle b) {
return rectContains(a, toRect(b));
}
static public boolean rectContains(Rect a, int x, int y) {
return a != null && a.contains(x, y);
}
static public boolean rectContains(Rect a, Pt p) {
return a != null && p != null && a.contains(p);
}
static public String unnull(String s) {
return s == null ? "" : s;
}
static public Collection unnull(Collection l) {
return l == null ? emptyList() : l;
}
static public List unnull(List l) {
return l == null ? emptyList() : l;
}
static public int[] unnull(int[] l) {
return l == null ? emptyIntArray() : l;
}
static public char[] unnull(char[] l) {
return l == null ? emptyCharArray() : l;
}
static public double[] unnull(double[] l) {
return l == null ? emptyDoubleArray() : l;
}
static public Map unnull(Map l) {
return l == null ? emptyMap() : l;
}
static public Iterable unnull(Iterable i) {
return i == null ? emptyList() : i;
}
static public A[] unnull(A[] a) {
return a == null ? (A[]) emptyObjectArray() : a;
}
static public BitSet unnull(BitSet b) {
return b == null ? new BitSet() : b;
}
static public Pt unnull(Pt p) {
return p == null ? new Pt() : p;
}
static public Symbol unnull(Symbol s) {
return s == null ? emptySymbol() : s;
}
static public Pair unnull(Pair p) {
return p != null ? p : new Pair(null, null);
}
static public int unnull(Integer i) {
return i == null ? 0 : i;
}
static public long unnull(Long l) {
return l == null ? 0L : l;
}
static public double unnull(Double l) {
return l == null ? 0.0 : l;
}
static public boolean nemptyString(String s) {
return s != null && s.length() > 0;
}
static public int listL(Collection l) {
return l == null ? 0 : l.size();
}
static public boolean neq(Object a, Object b) {
return !eq(a, b);
}
static public boolean ewic(String a, String b) {
return endsWithIgnoreCase(a, b);
}
static public boolean ewic(String a, String b, Matches m) {
return endsWithIgnoreCase(a, b, m);
}
static public WeakHasherMap symbol_map = new WeakHasherMap(new Hasher() {
public int hashCode(Symbol symbol) {
return symbol.text.hashCode();
}
public boolean equals(Symbol a, Symbol b) {
if (a == null)
return b == null;
return b != null && eq(a.text, b.text);
}
});
static public Symbol symbol(String s) {
if (s == null)
return null;
synchronized (symbol_map) {
Symbol symbol = new Symbol(s, true);
Symbol existingSymbol = symbol_map.findKey(symbol);
if (existingSymbol == null)
symbol_map.put(existingSymbol = symbol, true);
return existingSymbol;
}
}
static public Symbol symbol(CharSequence s) {
if (s == null)
return null;
if (s instanceof Symbol)
return (Symbol) s;
if (s instanceof String)
return symbol((String) s);
return symbol(str(s));
}
static public Symbol symbol(Object o) {
return symbol((CharSequence) o);
}
static public A printStackTrace(A e) {
if (e != null)
print(getStackTrace(e));
return e;
}
static public void printStackTrace() {
printStackTrace(new Throwable());
}
static public void printStackTrace(String msg) {
printStackTrace(new Throwable(msg));
}
static public void printStackTrace(String msg, Throwable e) {
printStackTrace(new Throwable(msg, e));
}
static public IF0 f0ToIF0(F0 f) {
return f == null ? null : () -> f.get();
}
static public HashSet lithashset(A... items) {
HashSet set = new HashSet();
for (A a : items) set.add(a);
return set;
}
static public Rect toRect(Rectangle r) {
return r == null ? null : new Rect(r);
}
static public Rect toRect(RectangularShape r) {
return r == null ? null : toRect(r.getBounds());
}
static public Rect toRect(Rect r) {
return r;
}
static public Map emptyMap() {
return new HashMap();
}
static public boolean endsWithIgnoreCase(String a, String b) {
int la = l(a), lb = l(b);
return la >= lb && regionMatchesIC(a, la - lb, b, 0, lb);
}
static public boolean endsWithIgnoreCase(String a, String b, Matches m) {
if (!endsWithIgnoreCase(a, b))
return false;
if (m != null)
m.m = new String[] { substring(a, 0, l(a) - l(b)) };
return true;
}
static public int iround(double d) {
return (int) Math.round(d);
}
static public int iround(Number n) {
return iround(toDouble(n));
}
static public boolean regionMatchesIC(String a, int offsetA, String b, int offsetB, int len) {
return a != null && a.regionMatches(true, offsetA, b, offsetB, len);
}
static public double toDouble(Object o) {
if (o instanceof Number)
return ((Number) o).doubleValue();
if (o instanceof BigInteger)
return ((BigInteger) o).doubleValue();
if (o instanceof String)
return parseDouble((String) o);
if (o == null)
return 0.0;
throw fail(o);
}
static public double parseDouble(String s) {
return empty(s) ? 0.0 : Double.parseDouble(s);
}
static abstract public class VF1 implements IVF1 {
public abstract void get(A a);
}
final static public class _MethodCache {
final public Class c;
final public HashMap> cache = new HashMap();
public _MethodCache(Class c) {
this.c = c;
_init();
}
public void _init() {
Class _c = c;
java.lang.Module myModule = getClass().getModule();
boolean anyHiddenClasses = false;
while (_c != null) {
boolean exported = classIsExportedTo(_c, myModule);
if (!exported)
anyHiddenClasses = true;
else
for (Method m : _c.getDeclaredMethods()) if ((anyHiddenClasses || !isAbstract(m)) && !reflection_isForbiddenMethod(m))
multiMapPut(cache, m.getName(), makeAccessible(m));
_c = _c.getSuperclass();
}
for (Class intf : allInterfacesImplementedBy(c)) for (Method m : intf.getDeclaredMethods()) if ((anyHiddenClasses || 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 enum JVMStackCellType {
none,
objValue,
intValue,
longValue,
floatValue,
doubleValue
}
static public class Matches {
public String[] m;
public Matches() {
}
public Matches(String... m) {
this.m = m;
}
public String get(int i) {
return i < m.length ? m[i] : null;
}
public String unq(int i) {
return unquote(get(i));
}
public String tlc(int i) {
return unq(i).toLowerCase();
}
public boolean bool(int i) {
return "true".equals(unq(i));
}
public String rest() {
return m[m.length - 1];
}
public int psi(int i) {
return Integer.parseInt(unq(i));
}
public String toString() {
return "Matches(" + joinWithComma(quoteAll(asList(m))) + ")";
}
public int hashCode() {
return _hashCode(toList(m));
}
public boolean equals(Object o) {
return o instanceof Matches && arraysEqual(m, ((Matches) o).m);
}
}
static public class Symbol implements CharSequence {
public String text;
public Symbol() {
}
public Symbol(String text, boolean dummy) {
this.text = text;
}
public int hashCode() {
return _hashCode(text);
}
public String toString() {
return text;
}
public boolean equals(Object o) {
return this == o;
}
public int length() {
return text.length();
}
public char charAt(int index) {
return text.charAt(index);
}
public CharSequence subSequence(int start, int end) {
return text.substring(start, end);
}
}
static public class PingSource {
final public PingSource setAction(IF0 action) {
return action(action);
}
public PingSource action(IF0 action) {
this.action = action;
return this;
}
final public IF0 getAction() {
return action();
}
public IF0 action() {
return action;
}
volatile public IF0 action;
public String text;
public ThreadPool threadPool;
public PingSource() {
}
public PingSource(ThreadPool threadPool) {
this.threadPool = threadPool;
}
public PingSource(ThreadPool threadPool, String text) {
this.text = text;
this.threadPool = threadPool;
}
public PingSource(IF0 action) {
this.action = action;
}
final public boolean get() {
var a = action;
return a != null && a.get();
}
final public void ping() {
var a = action;
if (a != null)
a.get();
}
public void cancel() {
action = new Cancelled();
}
public class Cancelled implements IF0 {
public Boolean get() {
throw new PingSourceCancelledException(PingSource.this);
}
}
public class Encapsulated implements Runnable, IFieldsToList {
public Runnable r;
public Encapsulated() {
}
public Encapsulated(Runnable r) {
this.r = r;
}
public Object[] _fieldsToList() {
return new Object[] { r };
}
public void run() {
try {
try {
pingSource_tl().set(PingSource.this);
ping();
r.run();
} finally {
pingSource_tl().set(null);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return PingSource.this + ": " + r;
}
}
public void dO(Runnable r) {
if (r == null)
return;
threadPool.acquireThreadOrQueue(new Encapsulated(r));
}
public String toString() {
String t = text;
return nempty(t) ? t : super.toString();
}
public ISleeper_v2 sleeper() {
return threadPool.sleeper();
}
}
static public class MultiMap implements IMultiMap {
public Map > data = new HashMap >();
public int fullSize;
public MultiMap() {
}
public MultiMap(boolean useTreeMap) {
if (useTreeMap)
data = new TreeMap();
}
public MultiMap(MultiMap map) {
putAll(map);
}
public MultiMap(Map > data) {
this.data = data;
}
public void put(A key, B value) {
synchronized (data) {
List list = data.get(key);
if (list == null)
data.put(key, list = _makeEmptyList());
list.add(value);
++fullSize;
}
}
public void add(A key, B value) {
put(key, value);
}
public void addAll(A key, Collection values) {
putAll(key, values);
}
public void addAllIfNotThere(A key, Collection values) {
synchronized (data) {
for (B value : values) setPut(key, value);
}
}
public void setPut(A key, B value) {
synchronized (data) {
if (!containsPair(key, value))
put(key, value);
}
}
public boolean containsPair(A key, B value) {
synchronized (data) {
return get(key).contains(value);
}
}
public void putAll(Collection keys, B value) {
synchronized (data) {
for (A key : unnullForIteration(keys)) put(key, value);
}
}
public void putAll(A key, Collection values) {
synchronized (data) {
if (nempty(values))
getActual(key).addAll(values);
}
}
public void putAll(Iterable> pairs) {
synchronized (data) {
for (Pair p : unnullForIteration(pairs)) put(p.a, p.b);
}
}
public void removeAll(A key, Collection values) {
synchronized (data) {
for (B value : values) remove(key, value);
}
}
public List get(A key) {
synchronized (data) {
List list = data.get(key);
return list == null ? Collections.emptyList() : list;
}
}
public List getOpt(A key) {
synchronized (data) {
return data.get(key);
}
}
public List getAndClear(A key) {
synchronized (data) {
List l = cloneList(data.get(key));
remove(key);
return l;
}
}
public List getActual(A key) {
synchronized (data) {
List list = data.get(key);
if (list == null)
data.put(key, list = _makeEmptyList());
return list;
}
}
public void clean(A key) {
synchronized (data) {
List list = data.get(key);
if (list != null && list.isEmpty()) {
fullSize -= l(list);
data.remove(key);
}
}
}
final public Set keys() {
return keySet();
}
public Set keySet() {
synchronized (data) {
return data.keySet();
}
}
public void remove(A key) {
synchronized (data) {
fullSize -= l(this.getOpt(key));
data.remove(key);
}
}
final public void remove(Pair p) {
removePair(p);
}
public void removePair(Pair p) {
if (p != null)
remove(p.a, p.b);
}
public void remove(A key, B value) {
synchronized (data) {
List list = data.get(key);
if (list != null) {
if (list.remove(value))
fullSize--;
if (list.isEmpty())
data.remove(key);
}
}
}
public void clear() {
synchronized (data) {
data.clear();
}
}
public boolean containsKey(A key) {
synchronized (data) {
return data.containsKey(key);
}
}
public B getFirst(A key) {
synchronized (data) {
List list = get(key);
return list.isEmpty() ? null : list.get(0);
}
}
public void addAll(MultiMap map) {
putAll(map);
}
public void putAll(MultiMap map) {
synchronized (data) {
for (A key : map.keySet()) putAll(key, map.get(key));
}
}
public void putAll(Map map) {
synchronized (data) {
if (map != null)
for (Map.Entry e : map.entrySet()) put(e.getKey(), e.getValue());
}
}
final public int keyCount() {
return keysSize();
}
public int keysSize() {
synchronized (data) {
return l(data);
}
}
final public int fullSize() {
return size();
}
public int size() {
synchronized (data) {
return fullSize;
}
}
public List reverseGet(B b) {
synchronized (data) {
List l = new ArrayList();
for (A key : data.keySet()) if (data.get(key).contains(b))
l.add(key);
return l;
}
}
public Map > asMap() {
synchronized (data) {
return cloneMap(data);
}
}
public boolean isEmpty() {
synchronized (data) {
return data.isEmpty();
}
}
public List _makeEmptyList() {
return new ArrayList();
}
public Collection> allLists() {
synchronized (data) {
return new ArrayList(data.values());
}
}
public Collection> values() {
return allLists();
}
public List allValues() {
return concatLists(data.values());
}
public Object mutex() {
return data;
}
public String toString() {
return "mm" + str(data);
}
}
static final public class WeakHasherMap extends AbstractMap implements Map {
public Hasher hasher = null;
final public boolean keyEquals(Object k1, Object k2) {
return (hasher == null ? k1.equals(k2) : hasher.equals(k1, k2));
}
final public int keyHashCode(Object k1) {
return (hasher == null ? k1.hashCode() : hasher.hashCode(k1));
}
final public WeakKey WeakKeyCreate(K k) {
if (k == null)
return null;
else
return new WeakKey(k);
}
final public WeakKey WeakKeyCreate(K k, ReferenceQueue super K> q) {
if (k == null)
return null;
else
return new WeakKey(k, q);
}
final public class WeakKey extends WeakReference {
public int hash;
public WeakKey(K k) {
super(k);
hash = keyHashCode(k);
}
final public WeakKey create(K k) {
if (k == null)
return null;
else
return new WeakKey(k);
}
public WeakKey(K k, ReferenceQueue super K> q) {
super(k, q);
hash = keyHashCode(k);
}
final public WeakKey create(K k, ReferenceQueue super K> q) {
if (k == null)
return null;
else
return new WeakKey(k, q);
}
@Override
public boolean equals(Object o) {
if (o == null)
return false;
if (this == o)
return true;
if (!(o.getClass().equals(WeakKey.class)))
return false;
Object t = this.get();
@SuppressWarnings("unchecked")
Object u = ((WeakKey) o).get();
if ((t == null) || (u == null))
return false;
if (t == u)
return true;
return keyEquals(t, u);
}
@Override
public int hashCode() {
return hash;
}
}
public HashMap hash;
public ReferenceQueue super K> queue = new ReferenceQueue();
@SuppressWarnings("unchecked")
final public void processQueue() {
WeakKey wk;
while ((wk = (WeakKey) queue.poll()) != null) {
hash.remove(wk);
}
}
public WeakHasherMap(int initialCapacity, float loadFactor) {
hash = new HashMap(initialCapacity, loadFactor);
}
public WeakHasherMap(int initialCapacity) {
hash = new HashMap(initialCapacity);
}
public WeakHasherMap() {
hash = new HashMap();
}
public WeakHasherMap(Hasher h) {
hash = new HashMap();
hasher = h;
}
@Override
public int size() {
return entrySet().size();
}
@Override
public boolean isEmpty() {
return entrySet().isEmpty();
}
@Override
public boolean containsKey(Object key) {
@SuppressWarnings("unchecked")
K kkey = (K) key;
return hash.containsKey(WeakKeyCreate(kkey));
}
@Override
public V get(Object key) {
@SuppressWarnings("unchecked")
K kkey = (K) key;
return hash.get(WeakKeyCreate(kkey));
}
@Override
public V put(K key, V value) {
processQueue();
return hash.put(WeakKeyCreate(key, queue), value);
}
@Override
public V remove(Object key) {
processQueue();
@SuppressWarnings("unchecked")
K kkey = (K) key;
return hash.remove(WeakKeyCreate(kkey));
}
@Override
public void clear() {
processQueue();
hash.clear();
}
@SuppressWarnings("TypeParameterShadowing")
final public class Entry implements Map.Entry {
public Map.Entry ent;
public K key;
public Entry(Map.Entry ent, K key) {
this.ent = ent;
this.key = key;
}
@Override
public K getKey() {
return key;
}
@Override
public V getValue() {
return ent.getValue();
}
@Override
public V setValue(V value) {
return ent.setValue(value);
}
final public boolean keyvalEquals(K o1, K o2) {
return (o1 == null) ? (o2 == null) : keyEquals(o1, o2);
}
final public boolean valEquals(V o1, V o2) {
return (o1 == null) ? (o2 == null) : o1.equals(o2);
}
@SuppressWarnings("NonOverridingEquals")
public boolean equals(Map.Entry e) {
return (keyvalEquals(key, e.getKey()) && valEquals(getValue(), e.getValue()));
}
@Override
public int hashCode() {
V v;
return (((key == null) ? 0 : keyHashCode(key)) ^ (((v = getValue()) == null) ? 0 : v.hashCode()));
}
}
final public class EntrySet extends AbstractSet> {
public Set> hashEntrySet = hash.entrySet();
@Override
public Iterator> iterator() {
return new Iterator>() {
public Iterator> hashIterator = hashEntrySet.iterator();
public Map.Entry next = null;
@Override
public boolean hasNext() {
while (hashIterator.hasNext()) {
Map.Entry ent = hashIterator.next();
WeakKey wk = ent.getKey();
K k = null;
if ((wk != null) && ((k = wk.get()) == null)) {
continue;
}
next = new Entry(ent, k);
return true;
}
return false;
}
@Override
public Map.Entry next() {
if ((next == null) && !hasNext())
throw new NoSuchElementException();
Map.Entry e = next;
next = null;
return e;
}
@Override
public void remove() {
hashIterator.remove();
}
};
}
@Override
public boolean isEmpty() {
return !(iterator().hasNext());
}
@Override
public int size() {
int j = 0;
for (Iterator> i = iterator(); i.hasNext(); i.next()) j++;
return j;
}
@Override
public boolean remove(Object o) {
processQueue();
if (!(o instanceof Map.Entry, ?>))
return false;
@SuppressWarnings("unchecked")
Map.Entry e = (Map.Entry) o;
Object ev = e.getValue();
WeakKey wk = WeakKeyCreate(e.getKey());
Object hv = hash.get(wk);
if ((hv == null) ? ((ev == null) && hash.containsKey(wk)) : hv.equals(ev)) {
hash.remove(wk);
return true;
}
return false;
}
@Override
public int hashCode() {
int h = 0;
for (Iterator> i = hashEntrySet.iterator(); i.hasNext(); ) {
Map.Entry ent = i.next();
WeakKey wk = ent.getKey();
Object v;
if (wk == null)
continue;
h += (wk.hashCode() ^ (((v = ent.getValue()) == null) ? 0 : v.hashCode()));
}
return h;
}
}
public Set> entrySet = null;
@Override
public Set> entrySet() {
if (entrySet == null)
entrySet = new EntrySet();
return entrySet;
}
public K findKey(Object key) {
processQueue();
K kkey = (K) key;
WeakKey wkey = WeakKeyCreate(kkey);
WeakKey found = hashMap_findKey(hash, wkey);
return found == null ? null : found.get();
}
}
static public class Pair implements Comparable> {
final public Pair setA(A a) {
return a(a);
}
public Pair a(A a) {
this.a = a;
return this;
}
final public A getA() {
return a();
}
public A a() {
return a;
}
public A a;
final public Pair setB(B b) {
return b(b);
}
public Pair b(B b) {
this.b = b;
return this;
}
final public B getB() {
return b();
}
public B b() {
return b;
}
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);
}
}
static public class Fail extends RuntimeException implements IFieldsToList {
public Object[] objects;
public Fail() {
}
public Fail(Object... objects) {
this.objects = objects;
}
public Object[] _fieldsToList() {
return new Object[] { objects };
}
public Fail(Throwable cause, Object... objects) {
super(cause);
this.objects = objects;
}
public String toString() {
return joinNemptiesWithColon("Fail", commaCombine(getCause(), objects));
}
}
static public class MethodMaker {
public ClassGen cg;
public MethodGen mg;
public InstructionList il = new InstructionList();
public ConstantPoolGen cp;
public InstructionFactory factory;
public int frameSize;
final public MethodMaker setVerboseAdd(boolean verboseAdd) {
return verboseAdd(verboseAdd);
}
public MethodMaker verboseAdd(boolean verboseAdd) {
this.verboseAdd = verboseAdd;
return this;
}
final public boolean getVerboseAdd() {
return verboseAdd();
}
public boolean verboseAdd() {
return verboseAdd;
}
public boolean verboseAdd = false;
public boolean classConstantWorkaround = false;
public MethodMaker(ClassMaker classMaker, Class returnType, String methodName, Class... argumentTypes) {
this(classMaker.cg, returnType, methodName, argumentTypes);
}
public MethodMaker(ClassGen cg, Class returnType, String methodName, Class... argumentTypes) {
this(cg, Const.ACC_PUBLIC, returnType, methodName, argumentTypes);
}
public MethodMaker(ClassGen cg, short modifiers, Class returnType, String methodName, Class... argumentTypes) {
this.cg = cg;
cp = cg.getConstantPool();
factory = new InstructionFactory(cg);
org.apache.bcel.generic.Type[] argTypes = wrapTypes(argumentTypes);
mg = new MethodGen(modifiers, wrapType(returnType), argTypes, null, methodName, cg.getClassName(), il, cp);
frameSize = l(argTypes) + 1;
}
static public org.apache.bcel.generic.Type[] wrapTypes(Class[] classes) {
org.apache.bcel.generic.Type[] types = new org.apache.bcel.generic.Type[l(classes)];
for (int i = 0; i < l(classes); i++) types[i] = wrapType(classes[i]);
return types;
}
static public org.apache.bcel.generic.Type wrapType(Class c) {
return classToBCELType(c);
}
public int newLocalVar() {
return frameSize++;
}
public MethodMaker newObject(Class c, Class... argTypes) {
il.append(factory.createNew(className(c)));
il.append(InstructionConst.DUP);
Constructor ctor = findConstructor_precise_onTypes(c, argTypes);
il.append(factory.createInvoke(className(c), "", org.apache.bcel.generic.Type.VOID, wrapTypes(ctor.getParameterTypes()), Const.INVOKESPECIAL));
return this;
}
public MethodMaker dup() {
il.append(InstructionConst.DUP);
return this;
}
public MethodMaker astore(int var) {
il.append(new ASTORE(var));
return this;
}
public MethodMaker aload(int var) {
il.append(new ALOAD(var));
return this;
}
public MethodMaker stringConstant(String s) {
il.append(new PUSH(cp, s));
return this;
}
public MethodMaker classConstant(Class c) {
if (classConstantWorkaround) {
stringConstant(c.getName());
invokeStatic(Class.class, Class.class, "forName", String.class);
} else {
var ldc = new LDC(classRef(c));
assertEquals("classConstant", ldc.getValue(cp), wrapType(c));
il.append(ldc);
}
return this;
}
final public MethodMaker intConst(int i) {
return intConstant(i);
}
public MethodMaker intConstant(int i) {
if (i >= -1 && i <= 5)
return add(new ICONST(i));
if (i == (byte) i)
return add(new BIPUSH((byte) i));
if (i == (short) i)
return add(new SIPUSH((short) i));
return add(new LDC(cp.addInteger(i)));
}
final public MethodMaker doubleConst(double d) {
return doubleConstant(d);
}
public MethodMaker doubleConstant(double d) {
return add(new LDC2_W(cp.addDouble(d)));
}
public MethodMaker boolConstant(boolean b) {
return intConstant(b ? 1 : 0);
}
public MethodMaker invokeVirtual(Class c, Class returnType, String methodName, Class... argTypes) {
Method m = findNonStaticMethod_precise_onTypes(c, methodName, argTypes);
if (m == null)
throw fail("Method not found: " + className(c) + "." + formatFunctionCall(methodName, argTypes) + " returning " + className(returnType));
il.append(factory.createInvoke(className(c), methodName, wrapType(m.getReturnType()), wrapTypes(m.getParameterTypes()), Const.INVOKEVIRTUAL));
return this;
}
public MethodMaker invokeInterface(Class c, Class returnType, String methodName, Class... argTypes) {
Method m = mostApplicableMethod_onTypes(filter(nonDefaultInterfaceMethods(c), _m -> _m.getName().equals(methodName)), argTypes);
if (m == null)
throw fail("Method not found: " + className(c) + "." + formatFunctionCall(methodName, argTypes) + " returning " + className(returnType));
il.append(factory.createInvoke(className(c), methodName, wrapType(m.getReturnType()), wrapTypes(m.getParameterTypes()), Const.INVOKEINTERFACE));
return this;
}
public MethodMaker invokeStatic(Class c, Class returnType, String methodName, Class... argTypes) {
Method m = findMethod_precise_onTypes(c, methodName, argTypes);
if (m == null)
throw fail("Method not found: " + className(c) + "." + formatFunctionCall(methodName, argTypes) + " returning " + className(returnType));
il.append(factory.createInvoke(className(c), methodName, wrapType(m.getReturnType()), wrapTypes(m.getParameterTypes()), Const.INVOKESTATIC));
return this;
}
public MethodMaker areturn() {
il.append(InstructionConst.ARETURN);
return this;
}
public MethodMaker _return() {
il.append(InstructionConst.RETURN);
return this;
}
public MethodMaker add(Instruction i) {
il.append(i);
if (verboseAdd)
print("> " + i);
return this;
}
public A addAndReturn(A i) {
add(i);
return i;
}
public MethodMaker add(BranchInstruction i) {
il.append(i);
if (verboseAdd)
print("> " + i);
return this;
}
public A addAndReturn(A i) {
add(i);
return i;
}
public void done() {
mg.stripAttributes(true);
mg.setMaxStack();
mg.setMaxLocals();
cg.addMethod(mg.getMethod());
}
public JVMStackCellType convertToObject(JVMStackCellType stackTop) {
if (stackTop == JVMStackCellType.objValue) {
} else if (stackTop == JVMStackCellType.intValue)
invokeStatic(Integer.class, Integer.class, "valueOf", int.class);
else if (stackTop == JVMStackCellType.doubleValue)
invokeStatic(Double.class, Double.class, "valueOf", double.class);
else if (stackTop == JVMStackCellType.none)
add(new ACONST_NULL());
else
throw fail("TODO: add conversion for stack cell type: " + stackTop);
return JVMStackCellType.objValue;
}
public void discardStackTop(JVMStackCellType stackTop) {
if (stackTop == JVMStackCellType.none) {
} else if (stackTop == JVMStackCellType.doubleValue || stackTop == JVMStackCellType.longValue)
add(new POP2());
else
add(new POP());
}
public int classRef(Class c) {
return cp.addClass((ObjectType) wrapType(assertNotNull(c)));
}
public MethodMaker checkCast(Class c) {
return add(new CHECKCAST(classRef(c)));
}
public MethodMaker loadNull() {
return add(new ACONST_NULL());
}
public InstructionHandle here() {
return il.append(new NOP());
}
public GOTO forwardGoto() {
return addAndReturn(new GOTO(null));
}
public void returnWithType(JVMStackCellType stackTop) {
if (stackTop == JVMStackCellType.objValue)
areturn();
else if (stackTop == JVMStackCellType.intValue)
add(new IRETURN());
else if (stackTop == JVMStackCellType.doubleValue)
add(new DRETURN());
else if (stackTop == JVMStackCellType.none)
_return();
else
throw fail("TODO: add return for stack cell type: " + stackTop);
}
public void getStaticField(String className, String fieldName, Class type) {
il.append(factory.createGetStatic(className, fieldName, wrapType(type)));
}
}
static public class Rect implements IFieldsToList {
static final public String _fieldOrder = "x y w h";
public int x;
public int y;
public int w;
public int h;
public Rect() {
}
public Rect(int x, int y, int w, int h) {
this.h = h;
this.w = w;
this.y = y;
this.x = x;
}
public boolean equals(Object o) {
if (!(o instanceof Rect))
return false;
Rect __1 = (Rect) o;
return x == __1.x && y == __1.y && w == __1.w && h == __1.h;
}
public int hashCode() {
int h = 2543108;
h = boostHashCombine(h, _hashCode(x));
h = boostHashCombine(h, _hashCode(y));
h = boostHashCombine(h, _hashCode(w));
h = boostHashCombine(h, _hashCode(h));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { x, y, w, h };
}
public Rect(Rectangle r) {
x = r.x;
y = r.y;
w = r.width;
h = r.height;
}
public Rect(Pt p, int w, int h) {
this.h = h;
this.w = w;
x = p.x;
y = p.y;
}
public Rect(Rect r) {
x = r.x;
y = r.y;
w = r.w;
h = r.h;
}
final public Rectangle getRectangle() {
return new Rectangle(x, y, w, h);
}
public String toString() {
return x + "," + y + " / " + w + "," + h;
}
final public int x1() {
return x;
}
final public int y1() {
return y;
}
final public int x2() {
return x + w;
}
final public int y2() {
return y + h;
}
final public boolean contains(Pt p) {
return contains(p.x, p.y);
}
final public boolean contains(int _x, int _y) {
return _x >= x && _y >= y && _x < x + w && _y < y + h;
}
final public boolean contains(Rectangle r) {
return rectContains(this, r);
}
final public boolean empty() {
return w <= 0 || h <= 0;
}
final public int getWidth() {
return w;
}
final public int getHeight() {
return h;
}
final public int area() {
return w * h;
}
}
static public class Pt implements Comparable, IDoublePt {
public int x, y;
public Pt() {
}
public Pt(Point p) {
x = p.x;
y = p.y;
}
public Pt(int x, int y) {
this.y = y;
this.x = x;
}
public Point getPoint() {
return new Point(x, y);
}
public boolean equals(Object o) {
return o instanceof Pt && x == ((Pt) o).x && y == ((Pt) o).y;
}
public int hashCode() {
return boostHashCombine(x, y);
}
public int compareTo(Pt p) {
if (y != p.y)
return cmp(y, p.y);
return cmp(x, p.x);
}
public String toString() {
return x + ", " + y;
}
public double length() {
return sqrt(x * x + y * y);
}
public Pt minus(Pt p) {
return ptMinus(this, p);
}
public double x_double() {
return x;
}
public double y_double() {
return y;
}
}
abstract static public class VarContext {
final public VarContext getParent() {
return parent();
}
public VarContext parent() {
return parent;
}
public VarContext parent;
public VarContext() {
}
public VarContext(VarContext parent) {
this.parent = parent;
}
abstract public Object get(String name);
final public void put(String name, Object value) {
set(name, value);
}
abstract public void set(String name, Object value);
final public AutoCloseable tempPut(String name, Object value) {
return tempSet(name, value);
}
abstract public AutoCloseable tempSet(String name, Object value);
abstract public void unset(String name);
abstract public Map varMap();
public void printMe() {
pnl(varMap());
print("parent", parent);
}
final public VarContext setExitFromScript(Object exitFromScript) {
return exitFromScript(exitFromScript);
}
public VarContext exitFromScript(Object exitFromScript) {
this.exitFromScript = exitFromScript;
return this;
}
final public Object getExitFromScript() {
return exitFromScript();
}
public Object exitFromScript() {
return exitFromScript;
}
public Object exitFromScript;
final public VarContext setReturnValue(Object returnValue) {
return returnValue(returnValue);
}
public VarContext returnValue(Object returnValue) {
this.returnValue = returnValue;
return this;
}
final public Object getReturnValue() {
return returnValue();
}
public Object returnValue() {
return returnValue;
}
public Object returnValue;
public boolean exiting() {
ping();
return exitFromScript != null;
}
}
static abstract public class F0 {
abstract public A get();
}
static abstract public class F1 {
abstract public B get(A a);
}
static abstract public class IterableIterator implements Iterator , Iterable {
public Iterator iterator() {
return this;
}
public void remove() {
unsupportedOperation();
}
}
public static interface IF0 {
public A get();
}
static public interface Hasher {
public int hashCode(A a);
public boolean equals(A a, A b);
}
static public interface IFieldsToList {
public Object[] _fieldsToList();
}
static public interface IF1 {
public B get(A a);
}
static public class PersistableThrowable extends DynamicObject {
public String className;
public String msg;
public String stacktrace;
public PersistableThrowable() {
}
public PersistableThrowable(Throwable e) {
if (e == null)
className = "Crazy Null Error";
else {
className = getClassName(e).replace('/', '.');
msg = e.getMessage();
stacktrace = getStackTrace_noRecord(e);
}
}
public String toString() {
return nempty(msg) ? className + ": " + msg : className;
}
public RuntimeException asRuntimeException() {
return new Fail(this);
}
}
static public interface IVF1 {
public void get(A a);
}
static public class GazelleV_LeftArrowScript {
abstract static public class Base extends HasTokenRangeWithSrc {
public RuntimeException rethrowWithSrc(Throwable e) {
return rethrowWithSrc("", e);
}
public RuntimeException rethrowWithSrc(String msg, Throwable e) {
if (src != null)
throw rethrowAndAppendToMessage(e, squareBracketed(joinNemptiesWithComma(msg, src)));
else
throw rethrow(e);
}
}
public interface Evaluable extends IF0, IHasTokenRangeWithSrc {
public default Object get() {
return get(new FlexibleVarContext());
}
public Object get(VarContext ctx);
public default LASValueDescriptor returnType() {
return null;
}
public default Evaluable optimize() {
return this;
}
public default Evaluable optimizeForReturnValueNotNeeded() {
return this;
}
}
abstract static public class EvaluableBase extends Base implements Evaluable {
final public EvaluableBase setReturnType(LASValueDescriptor returnType) {
return returnType(returnType);
}
public EvaluableBase returnType(LASValueDescriptor returnType) {
this.returnType = returnType;
return this;
}
final public LASValueDescriptor getReturnType() {
return returnType();
}
public LASValueDescriptor returnType() {
return returnType;
}
public LASValueDescriptor returnType;
public boolean returnValueNeeded = true;
public Evaluable optimizeForReturnValueNotNeeded() {
returnValueNeeded = false;
return optimize();
}
}
static public AtomicLong scriptIDCounter = new AtomicLong();
static public long scriptID() {
return incAtomicLong(scriptIDCounter);
}
static public class Script extends EvaluableBase {
transient public long id = scriptID();
public Map functionDefs;
public Evaluable[] steps;
public Object get(VarContext ctx) {
Object result = null;
var pingSource = pingSource();
for (var step : steps) {
ping(pingSource);
result = step.get(ctx);
var exiting = ctx.exitFromScript;
if (exiting != null) {
if (exiting == this) {
ctx.exitFromScript = null;
result = ctx.returnValue;
ctx.returnValue(null);
return result;
}
return null;
}
}
return result;
}
public String toStringLong() {
return pnlToLines(steps);
}
public String toString() {
return "Script " + n2(id);
}
public FunctionDef getFunction(String name) {
return mapGet(functionDefs, name);
}
final public Script optimize() {
return optimizeScript();
}
public Script optimizeScript() {
int n = returnValueNeeded ? steps.length - 1 : steps.length;
for (int i = 0; i < n; i++) steps[i] = steps[i].optimizeForReturnValueNotNeeded();
for (var f : values(functionDefs)) f.optimize();
return this;
}
}
static public class FunctionDef extends Base implements IFieldsToList {
public String name;
public String[] args;
public Script body;
public FunctionDef() {
}
public FunctionDef(String name, String[] args, Script body) {
this.body = body;
this.args = args;
this.name = name;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + name + ", " + args + ", " + body + ")";
}
public Object[] _fieldsToList() {
return new Object[] { name, args, body };
}
public FunctionDef(String name, List args, Script body) {
this.args = toStringArray(args);
this.body = body;
this.name = name;
}
public Object call(VarContext ctx, Object... args) {
var ctx2 = new FlexibleVarContext(ctx);
int n = min(l(args), l(this.args));
for (int i = 0; i < n; i++) ctx2.put(this.args[i], args[i]);
return body.get(ctx2);
}
public void optimize() {
body = body.optimize();
}
}
static public class Assignment extends Base implements Evaluable, IFieldsToList {
public String var;
public Evaluable expression;
public Assignment() {
}
public Assignment(String var, Evaluable expression) {
this.expression = expression;
this.var = var;
}
public Object[] _fieldsToList() {
return new Object[] { var, expression };
}
public Object get(VarContext ctx) {
Object o = expression.get(ctx);
ctx.set(var, o);
return o;
}
public String toString() {
return var + " <- " + expression;
}
}
static public class VarDeclaration extends EvaluableBase implements IFieldsToList {
public String var;
public Class type;
public Evaluable expression;
public VarDeclaration() {
}
public VarDeclaration(String var, Class type, Evaluable expression) {
this.expression = expression;
this.type = type;
this.var = var;
}
public Object[] _fieldsToList() {
return new Object[] { var, type, expression };
}
public Object get(VarContext ctx) {
Object o = expression == null ? null : expression.get(ctx);
ctx.set(var, o);
return o;
}
public String toString() {
return "var " + var + " <- " + expression;
}
}
static public class AssignmentToOuterVar extends EvaluableBase implements IFieldsToList {
public String var;
public Evaluable expression;
public AssignmentToOuterVar() {
}
public AssignmentToOuterVar(String var, Evaluable expression) {
this.expression = expression;
this.var = var;
}
public Object[] _fieldsToList() {
return new Object[] { var, expression };
}
public Object get(VarContext ctx) {
var parent = ctx.parent();
assertNotNull("No outer variable context", parent);
Object o = expression.get(ctx);
parent.set(var, o);
return o;
}
public String toString() {
return "outer " + var + " <- " + expression;
}
}
static public class NewObject extends Base implements Evaluable {
public NewObject() {
}
public Class c;
public Evaluable[] args;
public NewObject(Class c) {
this.c = c;
}
public NewObject(Class c, Evaluable[] args) {
this.args = args;
this.c = c;
}
public Object get(VarContext ctx) {
try {
return preciseNuObject(c, mapToArrayOrNull(args, arg -> arg.get(ctx)));
} catch (Throwable e) {
throw rethrowWithSrc(e);
}
}
public String toString() {
return "new " + formatFunctionCall(className(c), args);
}
}
static public class NewObject_LASClass extends NewObject {
public NewObject_LASClass() {
}
public ResolvableLASClass lasClass;
public NewObject_LASClass(ResolvableLASClass lasClass) {
this.lasClass = lasClass;
}
public NewObject_LASClass(ResolvableLASClass lasClass, Evaluable[] args) {
this.args = args;
this.lasClass = lasClass;
}
public void resolve() {
if (c == null)
c = lasClass.get();
}
public Object get(VarContext ctx) {
resolve();
return super.get(ctx);
}
public String toString() {
return "new " + formatFunctionCall(str(lasClass), args);
}
}
static public class NewObject_UnknownClass extends NewObject implements IFieldsToList {
public Evaluable classExpr;
public Evaluable[] args;
public NewObject_UnknownClass() {
}
public NewObject_UnknownClass(Evaluable classExpr, Evaluable[] args) {
this.args = args;
this.classExpr = classExpr;
}
public Object[] _fieldsToList() {
return new Object[] { classExpr, args };
}
public Object get(VarContext ctx) {
try {
Class c = (Class) (classExpr.get(ctx));
return preciseNuObject(c, mapToArrayOrNull(args, arg -> arg.get(ctx)));
} catch (Throwable e) {
throw rethrowWithSrc(e);
}
}
public String toString() {
return "new " + formatFunctionCall(classExpr, args);
}
}
static public class CallFunction extends Base implements Evaluable, IFieldsToList {
public FunctionDef f;
public Evaluable[] args;
public CallFunction() {
}
public CallFunction(FunctionDef f, Evaluable[] args) {
this.args = args;
this.f = f;
}
public Object[] _fieldsToList() {
return new Object[] { f, args };
}
public Object get(VarContext ctx) {
var evaledArgs = mapToArrayOrNull(args, a -> a.get(ctx));
if (ctx.exiting())
return null;
return f.call(ctx, evaledArgs);
}
public String toString() {
return formatFunctionCall(f.name, args);
}
}
static public class GetVar extends EvaluableBase implements IFieldsToList {
public String var;
public GetVar() {
}
public GetVar(String var) {
this.var = var;
}
public Object[] _fieldsToList() {
return new Object[] { var };
}
public Object get(VarContext ctx) {
return ctx.get(var);
}
public String toString() {
return var;
}
}
static public class Const extends Base implements Evaluable, IFieldsToList {
public Object value;
public Const() {
}
public Const(Object value) {
this.value = value;
}
public Object[] _fieldsToList() {
return new Object[] { value };
}
public Object get(VarContext ctx) {
return value;
}
public String toString() {
return strOrClassName(value);
}
public LASValueDescriptor returnType() {
return new LASValueDescriptor.KnownValue(value);
}
}
static public class GetStaticField extends Base implements Evaluable, IFieldsToList {
public Field field;
public GetStaticField() {
}
public GetStaticField(Field field) {
this.field = field;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + field + ")";
}
public Object[] _fieldsToList() {
return new Object[] { field };
}
public Object get(VarContext ctx) {
try {
return field.get(null);
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
static public class CallMethodOrGetField extends Base implements Evaluable, IFieldsToList {
public Evaluable target;
public String name;
public CallMethodOrGetField() {
}
public CallMethodOrGetField(Evaluable target, String name) {
this.name = name;
this.target = target;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + target + ", " + name + ")";
}
public Object[] _fieldsToList() {
return new Object[] { target, name };
}
final public CallMethodOrGetField setAllowNullReference(boolean allowNullReference) {
return allowNullReference(allowNullReference);
}
public CallMethodOrGetField allowNullReference(boolean allowNullReference) {
this.allowNullReference = allowNullReference;
return this;
}
final public boolean getAllowNullReference() {
return allowNullReference();
}
public boolean allowNullReference() {
return allowNullReference;
}
public boolean allowNullReference = false;
public Object handleNullReference() {
if (allowNullReference)
return null;
else
throw new NullPointerException();
}
public Object get(VarContext ctx) {
try {
Object object = target.get(ctx);
if (object == null)
return handleNullReference();
return preciseGetOrCallMethod(object, name);
} catch (Throwable e) {
throw rethrowWithSrc("Was getting " + name, e);
}
}
}
static public class GetVarContext extends Base implements Evaluable {
public Object get(VarContext ctx) {
return ctx;
}
}
static public class ThrowMethodNotFoundException extends Base implements Evaluable, IFieldsToList {
public CallMethod instruction;
public ThrowMethodNotFoundException() {
}
public ThrowMethodNotFoundException(CallMethod instruction) {
this.instruction = instruction;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + instruction + ")";
}
public Object[] _fieldsToList() {
return new Object[] { instruction };
}
public Object get(VarContext ctx) {
throw fail("Method not found: " + instruction);
}
}
static public class ThrowNullPointerException extends Base implements Evaluable, IFieldsToList {
public CallMethod instruction;
public ThrowNullPointerException() {
}
public ThrowNullPointerException(CallMethod instruction) {
this.instruction = instruction;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + instruction + ")";
}
public Object[] _fieldsToList() {
return new Object[] { instruction };
}
public Object get(VarContext ctx) {
throw fail("Null pointer exception: " + instruction);
}
}
static public class CallMethod extends Base implements Evaluable, IFieldsToList {
public Evaluable target;
public String methodName;
public Evaluable[] args;
public CallMethod() {
}
public CallMethod(Evaluable target, String methodName, Evaluable[] args) {
this.args = args;
this.methodName = methodName;
this.target = target;
}
public Object[] _fieldsToList() {
return new Object[] { target, methodName, args };
}
public Object get(VarContext ctx) {
return newPreciseCall(target.get(ctx), methodName, mapToArrayOrNull(args, arg -> arg.get(ctx)));
}
public String toString() {
return target + "." + formatFunctionCall(methodName, args);
}
public Evaluable optimize() {
var targetType = target.returnType();
if (targetType.knownValue()) {
Object o = targetType.value();
if (o == null)
return new ThrowNullPointerException(this);
Class[] argTypes = new Class[l(args)];
for (int i = 0; i < l(args); i++) {
var type = args[i].returnType();
if (!type.javaClassIsExact())
return this;
argTypes[i] = type.javaClass();
}
List methods = findMethodsNamed_cached(o, methodName);
if (any(methods, m -> m.isVarArgs()))
return this;
var method = findMethod_precise_onTypes(o, methodName, argTypes);
if (method == null)
return new ThrowMethodNotFoundException(this);
return new DirectMethodCallOnKnownTarget(o instanceof Class ? null : o, method, args);
}
return this;
}
}
static public class LambdaDef extends Base implements Evaluable, IFieldsToList {
public Class intrface;
public String[] args;
public Evaluable body;
public LambdaDef() {
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + intrface + ", " + args + ", " + body + ")";
}
public Object[] _fieldsToList() {
return new Object[] { intrface, args, body };
}
public Method implementedMethod;
public LambdaDef(Class intrface, String[] args, Evaluable body) {
this.body = body;
this.args = args;
this.intrface = intrface;
implementedMethod = findSingleInterfaceMethodOrFail(intrface);
if (implementedMethod.getParameterCount() != l(args))
throw fail("Bad parameter count for lambda: " + implementedMethod + " vs: " + joinWithComma(args));
}
public Object get(VarContext ctx) {
return proxyFromInvocationHandler(intrface, (proxy, method, actualArgs) -> {
ping();
if (method.getDeclaringClass() == intrface) {
var ctx2 = new FlexibleVarContext(ctx);
var argNames = args;
for (int i = 0; i < l(args); i++) ctx2.put(argNames[i], actualArgs[i]);
return body.get(ctx2);
} else
return handleObjectMethodsInProxyInvocationHandler(this, implementedMethod, method, proxy, actualArgs);
});
}
}
abstract static public class CurriedLambdaBase extends Base implements Evaluable, IFieldsToList {
public Class intrface;
public Evaluable[] curriedArgs;
public CurriedLambdaBase() {
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + intrface + ", " + curriedArgs + ")";
}
public Object[] _fieldsToList() {
return new Object[] { intrface, curriedArgs };
}
public Method implementedMethod;
public CurriedLambdaBase(Class intrface, Evaluable[] curriedArgs) {
this.curriedArgs = curriedArgs;
this.intrface = intrface;
implementedMethod = findSingleInterfaceMethodOrFail(intrface);
}
public Object get(VarContext ctx) {
Object[] curriedArguments = mapToArrayOrNull(curriedArgs, arg -> arg.get(ctx));
return proxyFromInvocationHandler(intrface, (proxy, method, actualArgs) -> {
if (method.getDeclaringClass() == intrface)
return forwardCall(ctx, concatMethodArgs(curriedArguments, actualArgs));
else
return handleObjectMethodsInProxyInvocationHandler(this, implementedMethod, method, proxy, actualArgs);
});
}
abstract public Object forwardCall(VarContext ctx, Object[] args);
}
static public class CurriedMethodLambda extends CurriedLambdaBase {
public Object target;
public String targetMethod;
public CurriedMethodLambda(Class intrface, Object target, String targetMethod, Evaluable[] curriedArgs) {
super(intrface, curriedArgs);
this.targetMethod = targetMethod;
this.target = target;
}
public Object forwardCall(VarContext ctx, Object[] args) {
return call(target, targetMethod, args);
}
}
static public class CurriedScriptFunctionLambda extends CurriedLambdaBase {
public FunctionDef f;
public CurriedScriptFunctionLambda(Class intrface, FunctionDef f, Evaluable[] curriedArgs) {
super(intrface, curriedArgs);
this.f = f;
}
public Object forwardCall(VarContext ctx, Object[] args) {
return f.call(ctx, args);
}
}
static public class CurriedConstructorLambda extends CurriedLambdaBase {
public Constructor[] ctors;
public CurriedConstructorLambda(Class intrface, Constructor[] ctors, Evaluable[] curriedArgs) {
super(intrface, curriedArgs);
this.ctors = ctors;
}
public Object forwardCall(VarContext ctx, Object[] args) {
return preciseNuObject(ctors, args);
}
}
static public class DirectMethodCallOnKnownTarget extends Base implements Evaluable, IFieldsToList {
public Object target;
public Method method;
public Evaluable[] args;
public DirectMethodCallOnKnownTarget() {
}
public DirectMethodCallOnKnownTarget(Object target, Method method, Evaluable[] args) {
this.args = args;
this.method = method;
this.target = target;
}
public Object[] _fieldsToList() {
return new Object[] { target, method, args };
}
public Object get(VarContext ctx) {
return invokeMethod(method, target, mapToArrayOrNull(args, arg -> arg.get(ctx)));
}
public String toString() {
return (target == null ? "" : target + ".") + formatFunctionCall(str(method), args);
}
public LASValueDescriptor returnType() {
return LASValueDescriptor.fromClass(method.getReturnType());
}
}
static public class While extends Base implements Evaluable, IFieldsToList {
public Evaluable condition;
public Evaluable body;
public While() {
}
public While(Evaluable condition, Evaluable body) {
this.body = body;
this.condition = condition;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + condition + ", " + body + ")";
}
public Object[] _fieldsToList() {
return new Object[] { condition, body };
}
public Object get(VarContext ctx) {
while (!ctx.exiting() && (Boolean) condition.get(ctx)) {
body.get(ctx);
}
return null;
}
}
abstract static public class ForEachBase extends Base implements Evaluable, IFieldsToList {
public Evaluable collection;
public Evaluable body;
public ForEachBase() {
}
public ForEachBase(Evaluable collection, Evaluable body) {
this.body = body;
this.collection = collection;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + collection + ", " + body + ")";
}
public Object[] _fieldsToList() {
return new Object[] { collection, body };
}
public Object get(VarContext ctx) {
var coll = collection.get(ctx);
Iterator iterator;
List out;
try {
if (coll instanceof Object[]) {
out = emptyList(((Object[]) coll).length);
for (var element : ((Object[]) coll)) {
if (ctx.exiting())
return null;
processElement(ctx, out, element);
}
} else if (coll instanceof Iterable) {
out = emptyList((Iterable) coll);
for (var element : ((Iterable) coll)) {
if (ctx.exiting())
return null;
processElement(ctx, out, element);
}
} else if (coll == null)
out = new ArrayList();
else
throw fail("Not iterable: " + className(coll));
} finally {
loopDone(ctx);
}
return out;
}
abstract public void processElement(VarContext ctx, List out, Object o);
abstract public void loopDone(VarContext ctx);
}
static public class ForEach extends ForEachBase {
public ForEach() {
}
public String var;
public ForEach(Evaluable collection, String var, Evaluable body) {
this.body = body;
this.var = var;
this.collection = collection;
}
public void processElement(VarContext ctx, List out, Object o) {
ctx.set(var, o);
out.add(body.get(ctx));
}
public void loopDone(VarContext ctx) {
ctx.unset(var);
}
}
static public class ForIterator extends Base implements Evaluable, IFieldsToList {
static final public String _fieldOrder = "iterable var body";
public Evaluable iterable;
public String var;
public Evaluable body;
public ForIterator() {
}
public ForIterator(Evaluable iterable, String var, Evaluable body) {
this.body = body;
this.var = var;
this.iterable = iterable;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + iterable + ", " + var + ", " + body + ")";
}
public boolean equals(Object o) {
if (!(o instanceof ForIterator))
return false;
ForIterator __4 = (ForIterator) o;
return eq(iterable, __4.iterable) && eq(var, __4.var) && eq(body, __4.body);
}
public int hashCode() {
int h = -214906825;
h = boostHashCombine(h, _hashCode(iterable));
h = boostHashCombine(h, _hashCode(var));
h = boostHashCombine(h, _hashCode(body));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { iterable, var, body };
}
public Object get(VarContext ctx) {
VarContext subContext = new FlexibleVarContext(ctx);
var iterable = this.iterable.get(ctx);
Iterator iterator = iterator_gen(iterable);
return mapI(iterator, value -> {
subContext.set(var, value);
return body.get(subContext);
});
}
}
static public class ForNested extends Base implements Evaluable, IFieldsToList {
static final public String _fieldOrder = "iterable var body";
public Evaluable iterable;
public String var;
public Evaluable body;
public ForNested() {
}
public ForNested(Evaluable iterable, String var, Evaluable body) {
this.body = body;
this.var = var;
this.iterable = iterable;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + iterable + ", " + var + ", " + body + ")";
}
public boolean equals(Object o) {
if (!(o instanceof ForNested))
return false;
ForNested __5 = (ForNested) o;
return eq(iterable, __5.iterable) && eq(var, __5.var) && eq(body, __5.body);
}
public int hashCode() {
int h = -1363247360;
h = boostHashCombine(h, _hashCode(iterable));
h = boostHashCombine(h, _hashCode(var));
h = boostHashCombine(h, _hashCode(body));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { iterable, var, body };
}
public Object get(VarContext ctx) {
VarContext subContext = new FlexibleVarContext(ctx);
var iterable = this.iterable.get(ctx);
Iterator iterator = iterator_gen(iterable);
return nestedIterator(iterator, value -> {
subContext.set(var, value);
return iterator_gen(body.get(subContext));
});
}
}
static public class ForPairs extends ForEachBase {
public ForPairs() {
}
public String varA, varB;
public ForPairs(Evaluable collection, Evaluable body, String varA, String varB) {
this.varB = varB;
this.varA = varA;
this.body = body;
this.collection = collection;
}
public void processElement(VarContext ctx, List out, Object o) {
Pair p = (Pair) o;
ctx.set(varA, p.a);
ctx.set(varB, p.b);
out.add(body.get(ctx));
}
public void loopDone(VarContext ctx) {
ctx.unset(varA);
ctx.unset(varB);
}
}
static public class ForKeyValue extends EvaluableBase implements IFieldsToList {
public Evaluable map;
public Evaluable body;
public String varA;
public String varB;
public ForKeyValue() {
}
public ForKeyValue(Evaluable map, Evaluable body, String varA, String varB) {
this.varB = varB;
this.varA = varA;
this.body = body;
this.map = map;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + map + ", " + body + ", " + varA + ", " + varB + ")";
}
public Object[] _fieldsToList() {
return new Object[] { map, body, varA, varB };
}
public Object get(VarContext ctx) {
Map, ?> theMap = (Map) map.get(ctx);
List out;
try {
if (theMap != null) {
out = emptyList(theMap.size());
for (var entry : theMap.entrySet()) {
if (ctx.exiting())
return null;
ctx.set(varA, entry.getKey());
ctx.set(varB, entry.getValue());
out.add(body.get(ctx));
}
} else
out = new ArrayList();
} finally {
ctx.unset(varA);
ctx.unset(varB);
}
return out;
}
}
static public class ForIntTo extends EvaluableBase implements IFieldsToList {
public Evaluable endValue;
public String var;
public Evaluable body;
public ForIntTo() {
}
public ForIntTo(Evaluable endValue, String var, Evaluable body) {
this.body = body;
this.var = var;
this.endValue = endValue;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + endValue + ", " + var + ", " + body + ")";
}
public Object[] _fieldsToList() {
return new Object[] { endValue, var, body };
}
public Evaluable optimize() {
if (!returnValueNeeded)
body = body.optimizeForReturnValueNotNeeded();
return this;
}
public Object get(VarContext ctx) {
int n = (Integer) endValue.get(ctx), i = 0;
List out = returnValueNeeded ? new ArrayList() : null;
try {
ctx.put(var, i);
while (i < n) {
if (ctx.exiting())
return null;
Object o = body.get(ctx);
{
if (out != null)
out.add(o);
}
ctx.set(var, i = (Integer) ctx.get(var) + 1);
}
} finally {
ctx.unset(var);
}
return out;
}
}
static public class ForIndex extends EvaluableBase {
public ForIndex() {
}
public Evaluable collection, body;
public String varIndex, varElement;
public ForIndex(Evaluable collection, Evaluable body, String varIndex, String varElement) {
this.varElement = varElement;
this.varIndex = varIndex;
this.body = body;
this.collection = collection;
}
public Object get(VarContext ctx) {
return new ForIndex_instance(collection, body, varIndex, varElement).get(ctx);
}
}
static public class ForIndex_instance extends ForEachBase {
public String varIndex, varElement;
public int index;
public ForIndex_instance(Evaluable collection, Evaluable body, String varIndex, String varElement) {
this.varElement = varElement;
this.varIndex = varIndex;
this.body = body;
this.collection = collection;
}
public void processElement(VarContext ctx, List out, Object o) {
ctx.set(varIndex, index++);
ctx.set(varElement, o);
out.add(body.get(ctx));
}
public void loopDone(VarContext ctx) {
ctx.unset(varIndex);
ctx.unset(varElement);
}
}
static public class IfThen extends Base implements Evaluable, IFieldsToList {
public Evaluable condition;
public Evaluable body;
public Evaluable elseBranch;
public IfThen() {
}
public IfThen(Evaluable condition, Evaluable body, Evaluable elseBranch) {
this.elseBranch = elseBranch;
this.body = body;
this.condition = condition;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + condition + ", " + body + ", " + elseBranch + ")";
}
public Object[] _fieldsToList() {
return new Object[] { condition, body, elseBranch };
}
public IfThen(Evaluable condition, Evaluable body) {
this.condition = condition;
this.body = body;
}
public Object get(VarContext ctx) {
if ((Boolean) condition.get(ctx))
return body.get(ctx);
else if (elseBranch != null)
return elseBranch.get(ctx);
else
return null;
}
}
static public class ReturnFromScript extends Base implements Evaluable, IFieldsToList {
public Script script;
public Evaluable value;
public ReturnFromScript() {
}
public ReturnFromScript(Script script, Evaluable value) {
this.value = value;
this.script = script;
}
public Object[] _fieldsToList() {
return new Object[] { script, value };
}
public Object get(VarContext ctx) {
Object result = value.get(ctx);
ctx.exitFromScript(script);
ctx.returnValue(result);
return null;
}
public String toString() {
return formatFunctionCall("ReturnFromScript", script, value);
}
}
static public class Continue extends Base implements Evaluable, IFieldsToList {
public Script loopBody;
public Continue() {
}
public Continue(Script loopBody) {
this.loopBody = loopBody;
}
public Object[] _fieldsToList() {
return new Object[] { loopBody };
}
public Object get(VarContext ctx) {
ctx.exitFromScript(loopBody);
ctx.returnValue(null);
return null;
}
public String toString() {
return formatFunctionCall("Continue", loopBody);
}
}
static public class RepeatN extends Base implements Evaluable, IFieldsToList {
public Evaluable n;
public Evaluable body;
public RepeatN() {
}
public RepeatN(Evaluable n, Evaluable body) {
this.body = body;
this.n = n;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + n + ", " + body + ")";
}
public Object[] _fieldsToList() {
return new Object[] { n, body };
}
public Object get(VarContext ctx) {
long count = ((Number) n.get(ctx)).longValue();
for (int _repeat_0 = 0; _repeat_0 < count; _repeat_0++) {
if (ctx.exiting())
return null;
body.get(ctx);
}
return null;
}
}
static public class BoolAnd extends Base implements Evaluable, IFieldsToList {
public Evaluable a;
public Evaluable b;
public BoolAnd() {
}
public BoolAnd(Evaluable a, Evaluable b) {
this.b = b;
this.a = a;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + a + ", " + b + ")";
}
public boolean equals(Object o) {
if (!(o instanceof BoolAnd))
return false;
BoolAnd __6 = (BoolAnd) o;
return eq(a, __6.a) && eq(b, __6.b);
}
public int hashCode() {
int h = 1729330797;
h = boostHashCombine(h, _hashCode(a));
h = boostHashCombine(h, _hashCode(b));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { a, b };
}
public Object get(VarContext ctx) {
if (!((Boolean) a.get(ctx)))
return false;
return b.get(ctx);
}
}
static public class BoolOr extends Base implements Evaluable, IFieldsToList {
public Evaluable a;
public Evaluable b;
public BoolOr() {
}
public BoolOr(Evaluable a, Evaluable b) {
this.b = b;
this.a = a;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + a + ", " + b + ")";
}
public boolean equals(Object o) {
if (!(o instanceof BoolOr))
return false;
BoolOr __7 = (BoolOr) o;
return eq(a, __7.a) && eq(b, __7.b);
}
public int hashCode() {
int h = 1995447949;
h = boostHashCombine(h, _hashCode(a));
h = boostHashCombine(h, _hashCode(b));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { a, b };
}
public Object get(VarContext ctx) {
if (((Boolean) a.get(ctx)))
return true;
return b.get(ctx);
}
}
static public class TempBlock extends Base implements Evaluable, IFieldsToList {
public Evaluable tempExpr;
public Evaluable body;
public TempBlock() {
}
public TempBlock(Evaluable tempExpr, Evaluable body) {
this.body = body;
this.tempExpr = tempExpr;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + tempExpr + ", " + body + ")";
}
public Object[] _fieldsToList() {
return new Object[] { tempExpr, body };
}
public Object get(VarContext ctx) {
AutoCloseable __2 = (AutoCloseable) (tempExpr.get(ctx));
try {
return body.get(ctx);
} finally {
_close(__2);
}
}
}
static public class ClassDef extends Base implements Evaluable, IFieldsToList {
public ResolvableLASClass lasClass;
public ClassDef() {
}
public ClassDef(ResolvableLASClass lasClass) {
this.lasClass = lasClass;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + lasClass + ")";
}
public boolean equals(Object o) {
if (!(o instanceof ClassDef))
return false;
ClassDef __8 = (ClassDef) o;
return eq(lasClass, __8.lasClass);
}
public int hashCode() {
int h = 757052301;
h = boostHashCombine(h, _hashCode(lasClass));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { lasClass };
}
public Object get(VarContext ctx) {
return lasClass.get();
}
}
static public class SetField extends Base implements Evaluable, IFieldsToList {
public Evaluable target;
public String name;
public Evaluable expr;
public SetField() {
}
public SetField(Evaluable target, String name, Evaluable expr) {
this.expr = expr;
this.name = name;
this.target = target;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + target + ", " + name + ", " + expr + ")";
}
public Object[] _fieldsToList() {
return new Object[] { target, name, expr };
}
final public SetField setAllowNullReference(boolean allowNullReference) {
return allowNullReference(allowNullReference);
}
public SetField allowNullReference(boolean allowNullReference) {
this.allowNullReference = allowNullReference;
return this;
}
final public boolean getAllowNullReference() {
return allowNullReference();
}
public boolean allowNullReference() {
return allowNullReference;
}
public boolean allowNullReference = false;
public Object handleNullReference() {
if (allowNullReference)
return null;
else
throw new NullPointerException();
}
public Object get(VarContext ctx) {
try {
Object value = expr.get(ctx);
Object object = target.get(ctx);
if (object == null)
handleNullReference();
else
set(object, name, value);
return value;
} catch (Throwable e) {
throw rethrowWithSrc(e);
}
}
}
static public class Throw extends Base implements Evaluable, IFieldsToList {
public Evaluable expr;
public Throw() {
}
public Throw(Evaluable expr) {
this.expr = expr;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + expr + ")";
}
public Object[] _fieldsToList() {
return new Object[] { expr };
}
public Object get(VarContext ctx) {
throw asRuntimeException((Throwable) expr.get(ctx));
}
}
static public class TryCatch extends Base implements Evaluable, IFieldsToList {
public Evaluable body;
public String var;
public Evaluable catchBlock;
public TryCatch() {
}
public TryCatch(Evaluable body, String var, Evaluable catchBlock) {
this.catchBlock = catchBlock;
this.var = var;
this.body = body;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + body + ", " + var + ", " + catchBlock + ")";
}
public Object[] _fieldsToList() {
return new Object[] { body, var, catchBlock };
}
public Object get(VarContext ctx) {
try {
return body.get(ctx);
} catch (Throwable e) {
AutoCloseable __3 = ctx.tempPut(var, e);
try {
return catchBlock.get(ctx);
} finally {
_close(__3);
}
}
}
}
}
static public class LASValueDescriptor {
public LASValueDescriptor() {
}
public boolean knownValue() {
return false;
}
public Object value() {
return null;
}
public Class javaClass() {
return null;
}
public boolean javaClassIsExact() {
return false;
}
public boolean canBeNull() {
return true;
}
public boolean canFail() {
return false;
}
public boolean willFail() {
return false;
}
static public class Exact extends LASValueDescriptor implements IFieldsToList {
public Class c;
public boolean canBeNull = false;
public Exact() {
}
public Exact(Class c, boolean canBeNull) {
this.canBeNull = canBeNull;
this.c = c;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + c + ", " + canBeNull + ")";
}
public boolean equals(Object o) {
if (!(o instanceof Exact))
return false;
Exact __1 = (Exact) o;
return eq(c, __1.c) && eq(canBeNull, __1.canBeNull);
}
public int hashCode() {
int h = 67394271;
h = boostHashCombine(h, _hashCode(c));
h = boostHashCombine(h, _hashCode(canBeNull));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { c, canBeNull };
}
public Class javaClass() {
return c;
}
public boolean javaClassIsExact() {
return true;
}
public boolean canBeNull() {
return canBeNull;
}
}
static public class NonExact extends LASValueDescriptor implements IFieldsToList {
public Class c;
public boolean canBeNull = false;
public NonExact() {
}
public NonExact(Class c, boolean canBeNull) {
this.canBeNull = canBeNull;
this.c = c;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + c + ", " + canBeNull + ")";
}
public boolean equals(Object o) {
if (!(o instanceof NonExact))
return false;
NonExact __2 = (NonExact) o;
return eq(c, __2.c) && eq(canBeNull, __2.canBeNull);
}
public int hashCode() {
int h = 1445514322;
h = boostHashCombine(h, _hashCode(c));
h = boostHashCombine(h, _hashCode(canBeNull));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { c, canBeNull };
}
public Class javaClass() {
return c;
}
public boolean javaClassIsExact() {
return false;
}
public boolean canBeNull() {
return canBeNull;
}
}
static public class KnownValue extends LASValueDescriptor implements IFieldsToList {
public Object value;
public KnownValue() {
}
public KnownValue(Object value) {
this.value = value;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + value + ")";
}
public boolean equals(Object o) {
if (!(o instanceof KnownValue))
return false;
KnownValue __3 = (KnownValue) o;
return eq(value, __3.value);
}
public int hashCode() {
int h = -1456305138;
h = boostHashCombine(h, _hashCode(value));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { value };
}
public boolean knownValue() {
return true;
}
public Object value() {
return value;
}
public Class javaClass() {
return value == null ? null : value.getClass();
}
public boolean javaClassIsExact() {
return value != null;
}
public boolean canBeNull() {
return value == null;
}
}
static public class WillFail extends LASValueDescriptor {
public boolean canFail() {
return true;
}
public boolean willFail() {
return true;
}
}
static public LASValueDescriptor fromClass(Class c) {
return new NonExact(c, true);
}
}
static public class ClassMaker {
final public String getClassName() {
return className();
}
public String className() {
return className;
}
public String className;
public ClassGen cg;
public JavaClass baked;
public InMemoryClassLoader classLoader;
public Class loadedClass;
final public ClassMaker setPrintDisassembly(boolean printDisassembly) {
return printDisassembly(printDisassembly);
}
public ClassMaker printDisassembly(boolean printDisassembly) {
this.printDisassembly = printDisassembly;
return this;
}
final public boolean getPrintDisassembly() {
return printDisassembly();
}
public boolean printDisassembly() {
return printDisassembly;
}
public boolean printDisassembly = false;
public ClassMaker(String className) {
this.className = className;
setClassGen(new ClassGen(className, "java.lang.Object", null, Const.ACC_PUBLIC, null));
}
public ClassMaker(Class interfaceToImplement) {
className = randomClassName();
setClassGen(new ClassGen(className, "java.lang.Object", null, Const.ACC_PUBLIC, new String[] { main.className(interfaceToImplement) }));
addDefaultConstructor();
}
public void addDefaultConstructor() {
cg.addEmptyConstructor(Const.ACC_PUBLIC);
}
public void setClassGen(ClassGen cg) {
this.cg = cg;
cg.setMajor(50);
cg.setMinor(0);
}
public JavaClass bake() {
if (baked == null) {
baked = cg.getJavaClass();
if (printDisassembly)
printClassWithMethods();
}
return baked;
}
public void printClassWithMethods() {
print_tabToSingleSpace(bake());
for (var method : baked.getMethods()) {
print_tabToSingleSpace("\n" + method);
print_tabToSingleSpace(method.getCode());
}
}
public byte[] getBytes_cache;
final public byte[] getBytes() {
if (getBytes_cache == null)
getBytes_cache = getBytes_load();
return getBytes_cache;
}
final public byte[] getBytes_load() {
return toBytes();
}
public byte[] toBytes() {
return bake().getBytes();
}
public Class load() {
if (loadedClass == null) {
var bytes = toBytes();
classLoader = new InMemoryClassLoader(myClassLoader());
loadedClass = (Class) classLoader.defineAClass(className, bytes);
}
return loadedClass;
}
public A newInstance() {
return main.newInstance(load());
}
public void addField(FieldGen fg) {
cg.addField(fg.getField());
}
public ConstantPoolGen getConstantPool() {
return cg.getConstantPool();
}
}
static public class FlexibleVarContext extends VarContext {
public Map vars;
public FlexibleVarContext() {
}
public FlexibleVarContext(VarContext parent) {
super(parent);
}
public Object get(String name) {
if (containsKey(vars, name))
return mapGet(vars, name);
if (parent != null)
return parent.get(name);
return null;
}
public void set(String name, Object value) {
vars = putOrCreateSyncMap(vars, name, value);
}
public AutoCloseable tempSet(String name, Object value) {
initMap();
return main.tempPut(vars, name, value);
}
public void unset(String name) {
remove(vars, name);
}
public Map varMap() {
return vars;
}
final public void initMap() {
makeThreadSafe();
}
public void makeThreadSafe() {
if (vars == null)
vars = syncHashMap();
}
}
static public class PingSourceCancelledException extends RuntimeException implements IFieldsToList {
public PingSource pingSource;
public PingSourceCancelledException() {
}
public PingSourceCancelledException(PingSource pingSource) {
this.pingSource = pingSource;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + pingSource + ")";
}
public Object[] _fieldsToList() {
return new Object[] { pingSource };
}
}
static public class ResolvableLASClass implements IFieldsToList {
static final public String _fieldOrder = "lasClassLoader classDef resolvedClass";
public LASClassLoader lasClassLoader;
public LASClassDef classDef;
public ResolvableLASClass() {
}
public ResolvableLASClass(LASClassLoader lasClassLoader, LASClassDef classDef) {
this.classDef = classDef;
this.lasClassLoader = lasClassLoader;
}
public boolean equals(Object o) {
if (!(o instanceof ResolvableLASClass))
return false;
ResolvableLASClass __2 = (ResolvableLASClass) o;
return eq(lasClassLoader, __2.lasClassLoader) && eq(classDef, __2.classDef);
}
public int hashCode() {
int h = -1660305875;
h = boostHashCombine(h, _hashCode(lasClassLoader));
h = boostHashCombine(h, _hashCode(classDef));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { lasClassLoader, classDef };
}
public Class resolvedClass;
public Class get() {
if (resolvedClass == null) {
if (lasClassLoader == null)
throw fail("Need LASClassLoader to define " + classDef.userGivenName);
resolvedClass = lasClassLoader.defineLASClass(classDef.finalClassName(), () -> classDef.toBytes());
classDef.init(resolvedClass);
}
return resolvedClass;
}
public String toString() {
if (resolvedClass != null)
return className(resolvedClass);
{
var __1 = classDef.userGivenName;
if (__1 != null)
return __1;
}
if (classDef.classHash_cache != null)
return classDef.finalClassNameWithoutPrefix();
return or2(classDef.userGivenName, "script-defined class") + " [unresolved]";
}
}
static public interface ISleeper_v2 {
public Sleeping doLater(Timestamp targetTime, Runnable r);
public default Sleeping doAfter(double seconds, Runnable r) {
return doLater(tsNow().plusSeconds(seconds), r);
}
}
static public class HasTokenRangeWithSrc implements IHasTokenRangeWithSrc {
public TokenRangeWithSrc src;
public void setTokenRangeWithSrc(TokenRangeWithSrc src) {
this.src = src;
}
public TokenRangeWithSrc tokenRangeWithSrc() {
return src;
}
}
static public class ThreadPool implements AutoCloseable {
public int max = numberOfCores();
public List all = new ArrayList();
public Set used = new HashSet();
public Set free = new HashSet();
public boolean verbose, retired;
public class InternalPingSource extends PingSource {
}
public InternalPingSource internalPingSource = new InternalPingSource();
public MultiSleeper sleeper = new MultiSleeper();
public ThreadPool() {
}
public ThreadPool(int max) {
this.max = max;
}
synchronized public int maxSize() {
return max;
}
synchronized public int total() {
return l(used) + l(free);
}
transient public Set onCustomerMustWaitAlert;
public ThreadPool onCustomerMustWaitAlert(Runnable r) {
onCustomerMustWaitAlert = createOrAddToSyncLinkedHashSet(onCustomerMustWaitAlert, r);
return this;
}
public ThreadPool removeCustomerMustWaitAlertListener(Runnable r) {
main.remove(onCustomerMustWaitAlert, r);
return this;
}
public void customerMustWaitAlert() {
if (onCustomerMustWaitAlert != null)
for (var listener : onCustomerMustWaitAlert) pcallF_typed(listener);
}
public void fireCustomerMustWaitAlert() {
vmBus_send("customerMustWaitAlert", this, currentThread());
customerMustWaitAlert();
}
public PooledThread acquireThreadOrQueue(Runnable action) {
if (action == null)
return null;
PooledThread t;
synchronized (this) {
if (_hasFreeAfterCreating()) {
t = _firstFreeThread();
markUsed(t);
} else
t = _anyThread();
}
t.addWork(action);
return t;
}
public boolean _hasFreeAfterCreating() {
checkNotRetired();
if (nempty(free))
return true;
if (total() < max) {
PooledThread t = newThread();
all.add(t);
free.add(t);
return true;
}
return false;
}
public PooledThread acquireThreadOrWait(Runnable action) {
try {
if (action == null)
return null;
PooledThread t;
while (true) {
synchronized (this) {
if (_hasFreeAfterCreating()) {
t = _firstFreeThread();
break;
} else
_waitWaitWait();
}
}
t.addWork(action);
return t;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public PooledThread _firstFreeThread() {
return first(free);
}
public PooledThread _anyThread() {
return random(used);
}
public class PooledThread extends Thread {
public PooledThread(String name) {
super(name);
}
public AppendableChain q;
synchronized public Runnable _grabWorkOrSleep() {
try {
Runnable r = first(q);
if (r == null) {
markFree(this);
if (verbose)
print("Thread sleeps");
synchronized (this) {
wait();
}
if (verbose)
print("Thread woke up");
return null;
}
q = popFirst(q);
return r;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public void run() {
try {
pingSource_tl().set(internalPingSource);
while (!retired()) {
ping();
Runnable r = _grabWorkOrSleep();
if (verbose)
print(this + " work: " + r);
if (r != null)
try {
if (verbose)
print(this + " running: " + r);
r.run();
pingSource_tl().set(internalPingSource);
if (verbose)
print(this + " done");
} catch (Throwable e) {
pingSource_tl().set(internalPingSource);
if (verbose)
print(this + " error");
printStackTrace(e);
} finally {
pingSource_tl().set(internalPingSource);
if (verbose)
print("ThreadPool finally");
}
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
synchronized public boolean isEmpty() {
return empty(q);
}
public void addWork(Runnable r) {
if (verbose)
print("Added work to " + this + ": " + r);
synchronized (this) {
q = chainPlus(q, r);
notifyAll();
}
}
}
public PooledThread newThread() {
PooledThread t = new PooledThread("Thread Pool Inhabitant " + n2(total() + 1));
t.start();
return t;
}
synchronized public void markFree(PooledThread t) {
used.remove(t);
free.add(t);
notifyAll();
}
synchronized public void markUsed(PooledThread t) {
free.remove(t);
used.add(t);
}
synchronized public String toString() {
return retired() ? "Retired ThreadPool" : "ThreadPool " + roundBracket(commaCombine(n2(used) + " used out of " + n2(total()), max <= total() ? null : "could grow to " + n2(max)));
}
synchronized public boolean retired() {
return retired;
}
synchronized public void retire() {
if (verbose)
print("ThreadPool Retiring");
retired = true;
for (var thread : free) syncNotifyAll(thread);
}
public void checkNotRetired() {
if (retired())
throw fail("retired");
}
synchronized public void close() {
try {
retire();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public void _waitWaitWait() {
try {
do {
fireCustomerMustWaitAlert();
wait();
checkNotRetired();
} while (empty(free));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public void dO(String text, Runnable r) {
if (r == null)
return;
new PingSource(this, text).dO(r);
}
public ISleeper_v2 sleeper() {
return sleeper;
}
}
public interface IHasTokenRangeWithSrc {
public void setTokenRangeWithSrc(TokenRangeWithSrc src);
public TokenRangeWithSrc tokenRangeWithSrc();
default public String srcText() {
var src = tokenRangeWithSrc();
return src == null ? null : src.text();
}
}
public interface IMultiMap {
public Set keySet();
public Collection get(A a);
public int size();
public int keyCount();
}
public interface IDoublePt {
public double x_double();
public double y_double();
}
static public class FailedRule extends RuleWithParams {
public List satisfiedConditions;
public Exp remainingCondition;
public FailedRule() {
}
public FailedRule(IfThen rule, VarMatches matches, Exp remainingCondition) {
this.remainingCondition = remainingCondition;
this.matches = matches;
this.rule = rule;
}
public FailedRule(IfThen rule, VarMatches matches, List satisfiedConditions, Exp remainingCondition) {
this.remainingCondition = remainingCondition;
this.satisfiedConditions = satisfiedConditions;
this.matches = matches;
this.rule = rule;
}
}
static public class RuleWithParams implements IFieldsToList {
static final public String _fieldOrder = "rule matches";
public IfThen rule;
public VarMatches matches;
public RuleWithParams() {
}
public RuleWithParams(IfThen rule, VarMatches matches) {
this.matches = matches;
this.rule = rule;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + rule + ", " + matches + ")";
}
public boolean equals(Object o) {
if (!(o instanceof RuleWithParams))
return false;
RuleWithParams __7 = (RuleWithParams) o;
return eq(rule, __7.rule) && eq(matches, __7.matches);
}
public int hashCode() {
int h = 1254104616;
h = boostHashCombine(h, _hashCode(rule));
h = boostHashCombine(h, _hashCode(matches));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { rule, matches };
}
public String ruleID() {
return rule.globalID;
}
}
static public class IfThen implements IFieldsToList {
static final public String _fieldOrder = "in out globalID options originalText";
public Exp in;
public Exp out;
public IfThen() {
}
public IfThen(Exp in, Exp out) {
this.out = out;
this.in = in;
}
public boolean equals(Object o) {
if (!(o instanceof IfThen))
return false;
IfThen __8 = (IfThen) o;
return eq(in, __8.in) && eq(out, __8.out);
}
public int hashCode() {
int h = -2108234502;
h = boostHashCombine(h, _hashCode(in));
h = boostHashCombine(h, _hashCode(out));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { in, out };
}
public String globalID;
public Set options;
public String originalText;
public String text() {
Collection opt = options;
if (nempty(globalID))
opt = concatLists(ll("id: " + globalID), opt);
return (nempty(opt) ? "[" + joinWithComma(opt) + "] " : "") + (in == null ? "" : in.text() + "\n => ") + nlLogic_text(out);
}
public String toString() {
return text();
}
}
abstract static public class Exp {
abstract public String text();
public String toString() {
return text();
}
}
static public class Func extends Exp implements IFieldsToList {
public String name;
public Exp arg;
public Func() {
}
public Func(String name, Exp arg) {
this.arg = arg;
this.name = name;
}
public boolean equals(Object o) {
if (!(o instanceof Func))
return false;
Func __0 = (Func) o;
return eq(name, __0.name) && eq(arg, __0.arg);
}
public int hashCode() {
int h = 2201316;
h = boostHashCombine(h, _hashCode(name));
h = boostHashCombine(h, _hashCode(arg));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { name, arg };
}
public List options;
public Func(String name, List options, Exp arg) {
this.arg = arg;
this.options = options;
this.name = name;
}
public String text() {
return name + (empty(options) ? "" : "[" + joinWithComma(options) + "]") + "(" + arg.text() + ")";
}
public String argText() {
return nlLogic_text(arg);
}
}
static public class And extends Exp implements IFieldsToList {
public Exp a;
public Exp b;
public And() {
}
public And(Exp a, Exp b) {
this.b = b;
this.a = a;
}
public boolean equals(Object o) {
if (!(o instanceof And))
return false;
And __1 = (And) o;
return eq(a, __1.a) && eq(b, __1.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 String text() {
return a.text() + "\n && " + b.text();
}
}
static public class ExpNot extends Exp implements IFieldsToList {
public Exp a;
public ExpNot() {
}
public ExpNot(Exp a) {
this.a = a;
}
public boolean equals(Object o) {
if (!(o instanceof ExpNot))
return false;
ExpNot __2 = (ExpNot) o;
return eq(a, __2.a);
}
public int hashCode() {
int h = 2089649046;
h = boostHashCombine(h, _hashCode(a));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { a };
}
public String text() {
return "!" + a.text();
}
}
abstract static public class Literal extends Exp {
}
static public class Sentence extends Literal implements IFieldsToList {
public List tok;
public Sentence() {
}
public Sentence(List tok) {
this.tok = tok;
}
public boolean equals(Object o) {
if (!(o instanceof Sentence))
return false;
Sentence __3 = (Sentence) o;
return eq(tok, __3.tok);
}
public int hashCode() {
int h = 1327381123;
h = boostHashCombine(h, _hashCode(tok));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { tok };
}
public String text() {
return join(tok);
}
}
static public class Sentence2 extends Literal implements IFieldsToList {
public String text;
public Sentence2() {
}
public Sentence2(String text) {
this.text = text;
}
public boolean equals(Object o) {
if (!(o instanceof Sentence2))
return false;
Sentence2 __4 = (Sentence2) o;
return eq(text, __4.text);
}
public int hashCode() {
int h = -1800858097;
h = boostHashCombine(h, _hashCode(text));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { text };
}
public String text() {
return text;
}
}
static public class Eq extends Exp implements IFieldsToList {
public Exp left;
public Exp right;
public Eq() {
}
public Eq(Exp left, Exp right) {
this.right = right;
this.left = left;
}
public boolean equals(Object o) {
if (!(o instanceof Eq))
return false;
Eq __5 = (Eq) o;
return eq(left, __5.left) && eq(right, __5.right);
}
public int hashCode() {
int h = 2252;
h = boostHashCombine(h, _hashCode(left));
h = boostHashCombine(h, _hashCode(right));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { left, right };
}
public String text() {
return left.text() + " = " + right.text();
}
}
static public class LASClassDef {
final public LASClassDef setUserGivenName(String userGivenName) {
return userGivenName(userGivenName);
}
public LASClassDef userGivenName(String userGivenName) {
this.userGivenName = userGivenName;
return this;
}
final public String getUserGivenName() {
return userGivenName();
}
public String userGivenName() {
return userGivenName;
}
public String userGivenName;
final public LASClassDef setClassDefPrefix(String classDefPrefix) {
return classDefPrefix(classDefPrefix);
}
public LASClassDef classDefPrefix(String classDefPrefix) {
this.classDefPrefix = classDefPrefix;
return this;
}
final public String getClassDefPrefix() {
return classDefPrefix();
}
public String classDefPrefix() {
return classDefPrefix;
}
public String classDefPrefix = "userCode.";
final public LASClassDef setFullCompilation(boolean fullCompilation) {
return fullCompilation(fullCompilation);
}
public LASClassDef fullCompilation(boolean fullCompilation) {
this.fullCompilation = fullCompilation;
return this;
}
final public boolean getFullCompilation() {
return fullCompilation();
}
public boolean fullCompilation() {
return fullCompilation;
}
public boolean fullCompilation = false;
final public LASClassDef setVerbose(boolean verbose) {
return verbose(verbose);
}
public LASClassDef verbose(boolean verbose) {
this.verbose = verbose;
return this;
}
final public boolean getVerbose() {
return verbose();
}
public boolean verbose() {
return verbose;
}
public boolean verbose = false;
public List fields = new ArrayList();
public List methods = new ArrayList();
public List methodBodies = new ArrayList();
static public class FieldDef {
final public FieldDef setName(String name) {
return name(name);
}
public FieldDef name(String name) {
this.name = name;
return this;
}
final public String getName() {
return name();
}
public String name() {
return name;
}
public String name;
final public FieldDef setType(Class type) {
return type(type);
}
public FieldDef type(Class type) {
this.type = type;
return this;
}
final public Class getType() {
return type();
}
public Class type() {
return type;
}
public Class type;
}
public String structForHash() {
return struct(litorderedmap("userGivenName", userGivenName, "fields", fields, "methods", methods, "fullCompilation", fullCompilation));
}
public String classHash_cache;
public String classHash() {
if (classHash_cache == null)
classHash_cache = classHash_load();
return classHash_cache;
}
public String classHash_load() {
String struct = structForHash();
if (verbose)
print("structForHash", struct);
return md5(struct);
}
public String finalClassName() {
return classDefPrefix() + finalClassNameWithoutPrefix();
}
public String finalClassNameWithoutPrefix() {
return or2(userGivenName, "C") + "_" + classHash();
}
public byte[] toBytes_cache;
public byte[] toBytes() {
if (toBytes_cache == null)
toBytes_cache = toBytes_load();
return toBytes_cache;
}
public byte[] toBytes_load() {
ClassMaker classMaker = new ClassMaker(finalClassName());
for (var field : fields) classMaker.addField(new FieldGen(Const.ACC_PUBLIC, classToBCELType(field.type), field.name, classMaker.getConstantPool()));
for (var method : methods) if (fullCompilation)
fullyCompileMethod(classMaker, method);
else
semiCompileMethod(classMaker, method);
classMaker.addDefaultConstructor();
return classMaker.toBytes();
}
public void semiCompileMethod(ClassMaker classMaker, GazelleV_LeftArrowScript.FunctionDef method) {
int iMethod = l(methodBodies);
methodBodies.add(method);
String bodyFieldName = "_body" + iMethod;
classMaker.addField(new FieldGen(Const.ACC_PUBLIC | Const.ACC_STATIC, classToBCELType(GazelleV_LeftArrowScript.Evaluable.class), bodyFieldName, classMaker.getConstantPool()));
int nArgs = l(method.args);
MethodMaker mm = new MethodMaker(classMaker, Object.class, method.name, repArray(Class.class, Object.class, nArgs));
int iThis = 0, iFirstArg = 1, iCtx = iFirstArg + nArgs;
mm.newObject(FlexibleVarContext.class);
mm.astore(iCtx);
mm.aload(iCtx);
mm.stringConstant("this");
mm.aload(iThis);
mm.invokeVirtual(VarContext.class, void.class, "put", String.class, Object.class);
for (int iArg = 0; iArg < nArgs; iArg++) {
mm.aload(iCtx);
mm.stringConstant(method.args[iArg]);
mm.aload(iFirstArg + iArg);
mm.invokeVirtual(VarContext.class, void.class, "put", String.class, Object.class);
}
mm.getStaticField(classMaker.className(), bodyFieldName, GazelleV_LeftArrowScript.Evaluable.class);
mm.aload(iCtx);
mm.invokeInterface(GazelleV_LeftArrowScript.Evaluable.class, Object.class, "get", VarContext.class);
mm.areturn();
mm.done();
}
public void fullyCompileMethod(ClassMaker classMaker, GazelleV_LeftArrowScript.FunctionDef method) {
MethodMaker mm = new MethodMaker(classMaker, Object.class, method.name, repArray(Class.class, Object.class, l(method.args)));
var tbc = new LASToByteCode(mm) {
public JVMStackCellType compileGetVar(GazelleV_LeftArrowScript.GetVar code) {
if (eq(code.var, "this")) {
mm.aload(0);
return JVMStackCellType.objValue;
}
int iArg = indexOf(method.args, code.var);
if (iArg >= 0) {
mm.aload(iArg + 1);
return JVMStackCellType.objValue;
}
return super.compileGetVar(code);
}
};
tbc.postConversion = stackTop -> mm.convertToObject(stackTop);
tbc.compileScript(method.body);
mm.areturn();
mm.done();
}
public void init(Class c) {
for (int iMethod = 0; iMethod < l(methodBodies); iMethod++) {
String bodyFieldName = "_body" + iMethod;
set(c, bodyFieldName, methodBodies.get(iMethod).body);
}
}
}
static public class TokenRangeWithSrc extends TokenRange {
public List tok;
public TokenRangeWithSrc() {
}
public TokenRangeWithSrc(List tok, int start) {
this.start = start;
end = start;
}
public TokenRangeWithSrc(List tok, int start, int end) {
this.end = end;
this.start = start;
}
public TokenRangeWithSrc(ListAndIndex startPtr, ListAndIndex endPtr) {
assertNotNull("startPtr", startPtr);
assertNotNull("endPtr", endPtr);
assertSame(tok = startPtr.list(), endPtr.list());
start = startPtr.idx();
end = endPtr.idx();
}
public ListAndIndex startPtr() {
return new ListAndIndex(tok, start);
}
public ListAndIndex endPtr() {
return new ListAndIndex(tok, end);
}
public LineAndColumn startLineAndCol() {
return tokenToLineAndColumn(startPtr());
}
public LineAndColumn endLineAndCol() {
return tokenToLineAndColumn(endPtr());
}
public String text() {
return joinSubList(tok, start, end);
}
public String toString() {
var start = startLineAndCol();
if (eq(start, end))
return str(start);
return start + " to " + endLineAndCol();
}
public String fullSourceText() {
return join(tok);
}
}
abstract static public class Sleeping implements AutoCloseable, IFieldsToList {
public Timestamp targetTime;
public Runnable action;
public Sleeping() {
}
public Sleeping(Timestamp targetTime, Runnable action) {
this.action = action;
this.targetTime = targetTime;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + targetTime + ", " + action + ")";
}
public Object[] _fieldsToList() {
return new Object[] { targetTime, action };
}
public long remainingMS() {
return targetTime.minus(tsNow());
}
}
static public class AppendableChain extends MinimalChain implements Iterable {
public MinimalChain last;
public int size;
public AppendableChain() {
}
public AppendableChain(A element) {
this.element = element;
size = 1;
last = this;
}
public AppendableChain(A element, AppendableChain next) {
this.next = next;
this.element = element;
if (next == null)
return;
MinimalChain b = new MinimalChain();
b.element = next.element;
b.next = next.next;
this.next = b;
last = next.last;
size = next.size + 1;
}
public String toString() {
return str(toList());
}
public boolean add(A a) {
MinimalChain newLast = new MinimalChain(a);
last.next = newLast;
last = newLast;
++size;
return true;
}
public AppendableChain popFirst() {
if (next == null)
return null;
element = next.element;
if (last == next)
last = this;
next = next.next;
--size;
return this;
}
public ArrayList toList() {
ArrayList l = emptyList(size);
MinimalChain c = this;
while (c != null) {
l.add(c.element);
c = c.next;
}
return l;
}
public class ACIt extends IterableIterator {
public MinimalChain c = AppendableChain.this;
public boolean hasNext() {
return c != null;
}
public A next() {
var a = c.element;
c = c.next;
return a;
}
}
public IterableIterator iterator() {
return new ACIt();
}
}
static public class MultiSleeper extends RestartableCountdown implements ISleeper_v2 {
public TreeMultiMap entries = new TreeMultiMap();
public void check() {
var time = nextWakeUpTime();
var action = firstValue(entries);
setTargetTime(time == null ? 0 : time.sysTime(), new Runnable() {
public void run() {
try {
List toCall;
synchronized (MultiSleeper.this) {
toCall = entries.get(time);
entries.remove(time);
}
check();
pcallFAll(toCall);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "List toCall;\r\n synchronized(MultiSleeper.this) {\r\n toCa...";
}
});
}
synchronized public void removeEntry(Timestamp targetTime, Runnable action) {
entries.remove(targetTime, action);
}
synchronized public Timestamp nextWakeUpTime() {
return firstKey(entries);
}
public synchronized Sleeping doLater(Timestamp targetTime, Runnable r) {
if (r == null || targetTime == null)
return null;
targetTime = max(targetTime, tsNow());
entries.put(targetTime, r);
check();
return new Sleeping(targetTime, r) {
public void close() {
try {
removeEntry(targetTime, r);
} catch (Exception __e) {
throw rethrow(__e);
}
}
};
}
}
static public class InMemoryClassLoader extends ClassLoader {
final public InMemoryClassLoader setRememberClassBytes(boolean rememberClassBytes) {
return rememberClassBytes(rememberClassBytes);
}
public InMemoryClassLoader rememberClassBytes(boolean rememberClassBytes) {
this.rememberClassBytes = rememberClassBytes;
return this;
}
final public boolean getRememberClassBytes() {
return rememberClassBytes();
}
public boolean rememberClassBytes() {
return rememberClassBytes;
}
transient public boolean rememberClassBytes = false;
transient public Map classBytes = syncMap();
public InMemoryClassLoader(ClassLoader parent) {
super(parent);
}
public Class> defineAClass(String name, byte[] bytes) {
Class c = defineClass(name, bytes, 0, bytes.length);
if (rememberClassBytes)
classBytes.put(c, bytes);
return c;
}
public byte[] getClassBytes(Class c) {
return classBytes.get(c);
}
}
static public class LASClassLoader extends InMemoryClassLoader {
public Map definedClasses = new HashMap();
public Lock lock = lock();
public LASClassLoader(ClassLoader parent) {
super(parent);
}
public LASClassLoader(Class parent) {
super(parent.getClassLoader());
}
public Class> defineLASClass(String name, IF0 generateClass) {
Lock __0 = lock;
lock(__0);
try {
try {
return loadClass(name);
} catch (ClassNotFoundException e) {
print("Generating class " + name);
return defineAClass(name, generateClass.get());
}
} finally {
unlock(__0);
}
}
}
static public class VarMatches extends WrappedMap {
public VarMatches() {
super(new LinkedHashMap());
}
public VarMatches(Map map) {
this();
main.putAll(this, map);
}
}
static public class Timestamp implements Comparable, IFieldsToList {
public long date;
public Timestamp(long date) {
this.date = date;
}
public boolean equals(Object o) {
if (!(o instanceof Timestamp))
return false;
Timestamp __1 = (Timestamp) o;
return date == __1.date;
}
public int hashCode() {
int h = 2059094262;
h = boostHashCombine(h, _hashCode(date));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { date };
}
public Timestamp() {
date = now();
}
public long unixDate() {
return date;
}
public String toString() {
return formatLocalDateWithSeconds(date);
}
public int compareTo(Timestamp t) {
return t == null ? 1 : cmp(date, t.date);
}
public Timestamp plus(Seconds seconds) {
return plus(seconds == null ? null : seconds.getDouble());
}
final public Timestamp plusSeconds(double seconds) {
return plus(seconds);
}
public Timestamp plus(double seconds) {
return new Timestamp(date + toMS(seconds));
}
public long minus(Timestamp ts) {
return unixDate() - ts.unixDate();
}
public long sysTime() {
return clockTimeToSystemTime(date);
}
public Duration minusAsDuration(Timestamp ts) {
return Duration.ofMillis(minus(ts));
}
}
static public class WrappedMap extends AbstractMap {
public Map map;
public WrappedMap() {
}
public WrappedMap(Map map) {
this.map = map;
}
public B get(Object key) {
return map.get(key);
}
public B put(A key, B value) {
return map.put(key, value);
}
public boolean containsKey(Object key) {
return map.containsKey(key);
}
public Set> entrySet() {
return map.entrySet();
}
}
static public class MinimalChain implements Iterable {
public A element;
public MinimalChain next;
public MinimalChain() {
}
public MinimalChain(A element) {
this.element = element;
}
public MinimalChain(A element, MinimalChain next) {
this.next = next;
this.element = element;
}
public String toString() {
return str(toList());
}
public ArrayList toList() {
ArrayList l = new ArrayList();
MinimalChain c = this;
while (c != null) {
l.add(c.element);
c = c.next;
}
return l;
}
public void setElement(A a) {
element = a;
}
public void setNext(MinimalChain next) {
this.next = next;
}
public Iterator iterator() {
return toList().iterator();
}
public A get() {
return element;
}
}
static public class ListAndIndex implements IFieldsToList {
static final public String _fieldOrder = "list idx";
public List list;
public int idx;
public ListAndIndex() {
}
public ListAndIndex(List list, int idx) {
this.idx = idx;
this.list = list;
}
public boolean equals(Object o) {
if (!(o instanceof ListAndIndex))
return false;
ListAndIndex __1 = (ListAndIndex) o;
return eq(list, __1.list) && idx == __1.idx;
}
public int hashCode() {
int h = 276903961;
h = boostHashCombine(h, _hashCode(list));
h = boostHashCombine(h, _hashCode(idx));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { list, idx };
}
public boolean atEnd() {
return idx >= l(list);
}
public A get() {
return _get(list, idx);
}
public int size() {
return l(list);
}
public String toString() {
return subList(list, 0, idx) + ", then " + subList(list, idx);
}
public ListAndIndex plus(int ofs) {
return new ListAndIndex(list, idx + ofs);
}
public ListAndIndex minus(int ofs) {
return new ListAndIndex(list, idx - ofs);
}
public List list() {
return list;
}
final public int idx() {
return index();
}
public int index() {
return idx;
}
public ListAndIndex mapIdx(IF1_IntToInt f) {
return new ListAndIndex (list, f.get(idx));
}
}
static public class RestartableCountdown implements AutoCloseable {
public java.util.Timer timer;
public long targetTime;
public long totalSleepTime;
synchronized public void setTargetTime(long targetTime, Runnable action) {
if (targetTime <= 0)
stop();
else if (targetTime != this.targetTime) {
start(targetTime - sysNow(), action);
this.targetTime = targetTime;
}
}
synchronized public void start(long delayMS, Object action) {
stop();
if (delayMS <= 0) {
startThread(new Runnable() {
public void run() {
try {
callF(action);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(action);";
}
});
} else {
totalSleepTime += delayMS;
timer = doLater_daemon(delayMS, action);
targetTime = sysNow() + delayMS;
}
}
public void start(double delaySeconds, Object action) {
start(toMS(delaySeconds), action);
}
synchronized public void stop() {
cancelTimer(timer);
timer = null;
targetTime = 0;
}
public void close() {
stop();
}
}
static public class TokenRange extends IntRange {
public TokenRange() {
}
public TokenRange(int start, int end) {
this.end = end;
this.start = start;
}
}
static public class Seconds implements Comparable, IFieldsToList {
public double seconds;
public Seconds() {
}
public Seconds(double seconds) {
this.seconds = seconds;
}
public boolean equals(Object o) {
if (!(o instanceof Seconds))
return false;
Seconds __1 = (Seconds) o;
return seconds == __1.seconds;
}
public int hashCode() {
int h = -660217249;
h = boostHashCombine(h, _hashCode(seconds));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { seconds };
}
final public double get() {
return seconds();
}
final public double getDouble() {
return seconds();
}
public double seconds() {
return seconds;
}
public String toString() {
return formatDouble(seconds, 3) + " s";
}
public int compareTo(Seconds s) {
return cmp(seconds, s.seconds);
}
public Seconds div(double x) {
return new Seconds(get() / x);
}
public Seconds minus(Seconds x) {
return new Seconds(get() - x.get());
}
}
static public class TreeMultiMap extends MultiMap {
public TreeMultiMap() {
super(true);
}
public TreeMultiMap(MultiMap map) {
this();
putAll(map);
}
}
static public class LineAndColumn implements IFieldsToList {
static final public String _fieldOrder = "line col getLineText";
public int line;
public int col;
public LineAndColumn() {
}
public LineAndColumn(int line, int col) {
this.col = col;
this.line = line;
}
public boolean equals(Object o) {
if (!(o instanceof LineAndColumn))
return false;
LineAndColumn __1 = (LineAndColumn) o;
return line == __1.line && col == __1.col;
}
public int hashCode() {
int h = -1128952231;
h = boostHashCombine(h, _hashCode(line));
h = boostHashCombine(h, _hashCode(col));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { line, col };
}
transient public IF1 getLineText;
public String getLineText(int line) {
return getLineText != null ? getLineText.get(line) : getLineText_base(line);
}
final public String getLineText_fallback(IF1 _f, int line) {
return _f != null ? _f.get(line) : getLineText_base(line);
}
public String getLineText_base(int line) {
return null;
}
public String toString() {
return "Line " + n2(line) + ", col " + n2(col);
}
}
static public class IntRange {
public int start, end;
public IntRange() {
}
public IntRange(int start, int end) {
this.end = end;
this.start = start;
}
public IntRange(IntRange r) {
start = r.start;
end = r.end;
}
public boolean equals(Object o) {
return stdEq2(this, o);
}
public int hashCode() {
return stdHash2(this);
}
final public int length() {
return end - start;
}
final public boolean empty() {
return start >= end;
}
final public boolean isEmpty() {
return start >= end;
}
static public String _fieldOrder = "start end";
public String toString() {
return "[" + start + ";" + end + "]";
}
}
static public interface IF1_IntToInt {
public int get(int i);
}
static public Class> getClass(String name) {
return _getClass(name);
}
static public Class getClass(Object o) {
return _getClass(o);
}
static public Class getClass(Object realm, String name) {
return _getClass(realm, name);
}
static public boolean classIsExportedTo(Class c, java.lang.Module destModule) {
if (c == null || destModule == null)
return false;
java.lang.Module srcModule = c.getModule();
String packageName = c.getPackageName();
return srcModule.isExported(packageName, destModule);
}
static public boolean isAbstract(Class c) {
return (c.getModifiers() & Modifier.ABSTRACT) != 0;
}
static public boolean isAbstract(Method m) {
return (m.getModifiers() & Modifier.ABSTRACT) != 0;
}
static public boolean reflection_isForbiddenMethod(Method m) {
return m.getDeclaringClass() == Object.class && eqOneOf(m.getName(), "finalize", "clone", "registerNatives");
}
static public Set allInterfacesImplementedBy(Object o) {
return allInterfacesImplementedBy(_getClass(o));
}
static public Set allInterfacesImplementedBy(Class c) {
if (c == null)
return null;
HashSet set = new HashSet();
allInterfacesImplementedBy_find(c, set);
return set;
}
static public 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);
}
static public Method findMethod(Object o, String method, Object... args) {
return findMethod_cached(o, method, args);
}
static public 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;
}
static public 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;
}
static public 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;
}
static public String unquote(String s) {
if (s == null)
return null;
if (startsWith(s, '[')) {
int i = 1;
while (i < s.length() && s.charAt(i) == '=') ++i;
if (i < s.length() && s.charAt(i) == '[') {
String m = s.substring(1, i);
if (s.endsWith("]" + m + "]"))
return s.substring(i + 1, s.length() - i - 1);
}
}
if (s.length() > 1) {
char c = s.charAt(0);
if (c == '\"' || c == '\'') {
int l = endsWith(s, c) ? s.length() - 1 : s.length();
StringBuilder sb = new StringBuilder(l - 1);
for (int i = 1; i < l; i++) {
char ch = s.charAt(i);
if (ch == '\\') {
char nextChar = (i == l - 1) ? '\\' : s.charAt(i + 1);
if (nextChar >= '0' && nextChar <= '7') {
String code = "" + nextChar;
i++;
if ((i < l - 1) && s.charAt(i + 1) >= '0' && s.charAt(i + 1) <= '7') {
code += s.charAt(i + 1);
i++;
if ((i < l - 1) && s.charAt(i + 1) >= '0' && s.charAt(i + 1) <= '7') {
code += s.charAt(i + 1);
i++;
}
}
sb.append((char) Integer.parseInt(code, 8));
continue;
}
switch(nextChar) {
case '\"':
ch = '\"';
break;
case '\\':
ch = '\\';
break;
case 'b':
ch = '\b';
break;
case 'f':
ch = '\f';
break;
case 'n':
ch = '\n';
break;
case 'r':
ch = '\r';
break;
case 't':
ch = '\t';
break;
case '\'':
ch = '\'';
break;
case 'u':
if (i >= l - 5) {
ch = 'u';
break;
}
int code = Integer.parseInt("" + s.charAt(i + 2) + s.charAt(i + 3) + s.charAt(i + 4) + s.charAt(i + 5), 16);
sb.append(Character.toChars(code));
i += 5;
continue;
default:
ch = nextChar;
}
i++;
}
sb.append(ch);
}
return sb.toString();
}
}
return s;
}
static public List quoteAll(String[] l) {
return quoteAll(asList(l));
}
static public List quoteAll(Collection l) {
List x = new ArrayList();
for (String s : l) x.add(quote(s));
return x;
}
static public int _hashCode(Object a) {
return a == null ? 0 : a.hashCode();
}
static public boolean arraysEqual(Object[] a, Object[] b) {
if (a.length != b.length)
return false;
for (int i = 0; i < a.length; i++) if (neq(a[i], b[i]))
return false;
return true;
}
static public BetterThreadLocal pingSource_tl_var = new BetterThreadLocal() {
@Override
public PingSource initialValue() {
return ping_v3_pingSourceMaker().get();
}
};
static public BetterThreadLocal pingSource_tl() {
return pingSource_tl_var;
}
static public boolean nempty(Collection c) {
return !empty(c);
}
static public boolean nempty(CharSequence s) {
return !empty(s);
}
static public boolean nempty(Object[] o) {
return !empty(o);
}
static public boolean nempty(byte[] o) {
return !empty(o);
}
static public boolean nempty(int[] o) {
return !empty(o);
}
static public boolean nempty(BitSet bs) {
return !empty(bs);
}
static public boolean nempty(Map m) {
return !empty(m);
}
static public boolean nempty(Iterator i) {
return i != null && i.hasNext();
}
static public boolean nempty(IMultiMap mm) {
return mm != null && mm.size() != 0;
}
static public boolean nempty(Object o) {
return !empty(o);
}
static public boolean nempty(IntRange r) {
return !empty(r);
}
static public boolean nempty(Rect r) {
return r != null && r.w != 0 && r.h != 0;
}
static public boolean nempty(MultiSet ms) {
return ms != null && !ms.isEmpty();
}
static public Map putAll(Map a, Map extends A, ? extends B> b) {
if (a != null && b != null)
a.putAll(b);
return a;
}
static public MultiMap putAll(MultiMap a, Map extends A, ? extends B> b) {
if (a != null)
a.putAll((Map) b);
return a;
}
static public Map putAll(Map a, Object... b) {
if (a != null)
litmap_impl(a, b);
return a;
}
static public void remove(List l, int i) {
if (l != null && i >= 0 && i < l(l))
l.remove(i);
}
static public void remove(Collection l, A a) {
if (l != null)
l.remove(a);
}
static public B remove(Map map, Object a) {
return map == null ? null : map.remove(a);
}
static public void remove(BitSet bs, int i) {
bs.clear(i);
}
static public A getAndClear(IVar v) {
A a = v.get();
v.set(null);
return a;
}
static public Set keys(Map map) {
return map == null ? new HashSet() : map.keySet();
}
static public Set keys(Object map) {
return keys((Map) map);
}
static public Set keys(MultiSet ms) {
return ms.keySet();
}
static public Set keys(IMultiMap mm) {
return mm.keySet();
}
static public Set keySet(Map map) {
return map == null ? new HashSet() : map.keySet();
}
static public Set keySet(Object map) {
return keys((Map) map);
}
static public Set keySet(MultiSet ms) {
return ms.keySet();
}
static public Set keySet(MultiMap mm) {
return mm.keySet();
}
static public int keysSize(MultiMap mm) {
return lKeys(mm);
}
static public A reverseGet(List l, int idx) {
if (l == null || idx < 0)
return null;
int n = l(l);
return idx < n ? l.get(n - 1 - idx) : null;
}
static public Map cloneMap(Map map) {
if (map == null)
return new HashMap();
synchronized (map) {
return map instanceof TreeMap ? new TreeMap((TreeMap) map) : map instanceof LinkedHashMap ? new LinkedHashMap(map) : new HashMap(map);
}
}
static public List cloneMap(Iterable l, IF1 f) {
List x = emptyList(l);
if (l != null)
for (A o : cloneList(l)) x.add(f.get(o));
return x;
}
static public Collection values(Map map) {
return map == null ? emptyList() : map.values();
}
static public Collection values(Object map) {
return values((Map) map);
}
static public Collection values(MultiMap mm) {
return mm == null ? emptyList() : concatLists(values(mm.data));
}
static public > List allValues(Map map) {
List out = new ArrayList();
for (var l : values(map)) addAll(out, l);
return out;
}
static public List concatLists(Iterable ... lists) {
List l = new ArrayList();
if (lists != null)
for (Iterable list : lists) addAll(l, list);
return l;
}
static public List concatLists(Collection extends Iterable > lists) {
List l = new ArrayList();
if (lists != null)
for (Iterable list : lists) addAll(l, list);
return l;
}
static public Iterator iterator(Iterable c) {
return c == null ? emptyIterator() : c.iterator();
}
static public Method hashMap_findKey_method;
static public A hashMap_findKey(HashMap map, Object key) {
try {
if (hashMap_findKey_method == null)
hashMap_findKey_method = findMethodNamed(HashMap.class, "getNode");
Map.Entry entry = (Map.Entry) hashMap_findKey_method.invoke(map, hashMap_internalHash(key), key);
return entry == null ? null : entry.getKey();
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public String a(String noun) {
if (eq(noun, ""))
return "?";
return ("aeiou".indexOf(noun.charAt(0)) >= 0 ? "an " : "a ") + noun;
}
static public String a(String contents, Object... params) {
return hfulltag("a", contents, params);
}
static public String b(Object contents, Object... params) {
return tag("b", contents, params);
}
static public int hashCodeFor(Object a) {
return a == null ? 0 : a.hashCode();
}
static public String joinNemptiesWithColon(String... strings) {
return joinNempties(": ", strings);
}
static public String joinNemptiesWithColon(Collection strings) {
return joinNempties(": ", strings);
}
static public String commaCombine(Object... l) {
return joinNemptiesWithComma(flattenCollectionsAndArrays(ll(l)));
}
static public org.apache.bcel.generic.Type classToBCELType(Class c) {
if (c == null)
return null;
if (isPrimitiveType(c)) {
if (c == byte.class)
return org.apache.bcel.generic.Type.BYTE;
if (c == int.class)
return org.apache.bcel.generic.Type.INT;
if (c == double.class)
return org.apache.bcel.generic.Type.DOUBLE;
if (c == void.class)
return org.apache.bcel.generic.Type.VOID;
if (c == boolean.class)
return org.apache.bcel.generic.Type.BOOLEAN;
throw fail("TODO: classToBCELType " + c);
}
if (isArrayType(c)) {
int dimensions = 0;
while (c.isArray()) {
++dimensions;
c = c.componentType();
}
return new ArrayType(classToBCELType(c), dimensions);
}
return new ObjectType(className(c));
}
static public Constructor findConstructor_precise_onTypes(Class c, Class... argTypes) {
try {
List ctors = constructorsWithNumberOfArguments(c, l(argTypes));
Lowest best = new Lowest();
if (ctors != null)
for (Constructor ctor : ctors) {
int score = methodApplicabilityScore_onTypes(ctor, argTypes);
if (score < Integer.MAX_VALUE)
best.put(ctor, score);
}
return best.get();
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public A assertEquals(Object x, A y) {
return assertEquals("", x, y);
}
static public A assertEquals(String msg, Object x, A y) {
if (assertVerbose())
return assertEqualsVerbose(msg, x, y);
if (!(x == null ? y == null : x.equals(y)))
throw fail((msg != null ? msg + ": " : "") + y + " != " + x);
return y;
}
static public void add(BitSet bs, int i) {
bs.set(i);
}
static public boolean add(Collection c, A a) {
return c != null && c.add(a);
}
static public void add(Container c, Component x) {
addToContainer(c, x);
}
static public long add(AtomicLong l, long b) {
return l.addAndGet(b);
}
static public Method findNonStaticMethod_precise_onTypes(Object o, String method, Class... argTypes) {
try {
Class c = _getClass(o);
if (c == null)
return null;
_MethodCache cache = callOpt_getCache(c);
List methods = cache.cache.get(method);
Lowest best = new Lowest();
if (methods != null)
for (Method m : methods) {
{
if (isStaticMethod(m))
continue;
}
int score = methodApplicabilityScore_onTypes(m, argTypes);
if (score < Integer.MAX_VALUE)
best.put(m, score);
}
return best.get();
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public String formatFunctionCall(String fname, Object... args) {
return formatFunctionCall((Object) fname, args);
}
static public String formatFunctionCall(Object fname, Object... args) {
return fname + "(" + joinWithComma(allToString(args)) + ")";
}
static public String formatFunctionCall(String fname, Iterable args) {
return formatFunctionCall((Object) fname, args);
}
static public String formatFunctionCall(Object fname, Iterable args) {
return formatFunctionCall(fname, toObjectArray(args));
}
static public Method mostApplicableMethod_onTypes(Iterable methods, Class... argTypes) {
Lowest best = new Lowest();
if (methods != null)
for (Method m : methods) {
int score = methodApplicabilityScore_onTypes(m, argTypes);
if (score < Integer.MAX_VALUE)
best.put(m, score);
}
return best.get();
}
static public List filter(Iterable c, Object pred) {
if (pred instanceof F1)
return filter(c, (F1 ) pred);
List x = new ArrayList();
if (c != null)
for (Object o : c) if (isTrue(callF(pred, o)))
x.add(o);
return x;
}
static public List filter(Object pred, Iterable c) {
return filter(c, pred);
}
static public List filter(Iterable c, F1 pred) {
List x = new ArrayList();
if (c != null)
for (B o : c) if (pred.get(o))
x.add(o);
return x;
}
static public List filter(F1 pred, Iterable