Warning : session_start(): open(/var/lib/php/sessions/sess_qknmmggd287sv2or583ljfcg7q, 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 static x30_pkg.x30_util.DynamicObject;
import java.nio.file.*;
import static java.nio.file.StandardWatchEventKinds.*;
import org.fife.ui.autocomplete.*;
import org.fife.rsta.ui.CollapsibleSectionPanel;
import org.fife.rsta.ui.GoToDialog;
import org.fife.rsta.ui.SizeGripIcon;
import org.fife.rsta.ui.search.FindDialog;
import org.fife.rsta.ui.search.ReplaceDialog;
import org.fife.rsta.ui.search.ReplaceToolBar;
import org.fife.rsta.ui.search.SearchEvent;
import org.fife.rsta.ui.search.SearchListener;
import org.fife.rsta.ui.search.FindToolBar;
import org.fife.ui.rsyntaxtextarea.ErrorStrip;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.fife.ui.rtextarea.SearchContext;
import org.fife.ui.rtextarea.SearchEngine;
import org.fife.ui.rtextarea.SearchResult;
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
import org.fife.ui.rsyntaxtextarea.SyntaxScheme;
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 java.util.jar.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.text.*;
import javax.swing.border.TitledBorder;
import java.nio.file.Path;
import org.fife.ui.rsyntaxtextarea.*;
import java.awt.datatransfer.StringSelection;
import javax.swing.event.AncestorListener;
import javax.swing.event.AncestorEvent;
import javax.swing.Timer;
import java.awt.geom.*;
import javax.swing.undo.UndoManager;
import javax.swing.border.*;
import java.text.NumberFormat;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import java.nio.charset.Charset;
import java.util.TimeZone;
import java.text.SimpleDateFormat;
import java.awt.datatransfer.UnsupportedFlavorException;
import javax.swing.Icon;
public class main {
static public class G22NetworkInstance implements IFieldsToList {
public boolean _isTransient() {
return true;
}
public G22Network network;
public G22NetworkInstance() {
}
public G22NetworkInstance(G22Network network) {
this.network = network;
}
public Object[] _fieldsToList() {
return new Object[] { network };
}
public Map valuesByIdentifier = new HashMap();
public Map valuesByBlueprint = new HashMap();
transient public Set onDirtyStatesChanged;
public G22NetworkInstance onDirtyStatesChanged(Runnable r) {
onDirtyStatesChanged = createOrAddToSyncLinkedHashSet(onDirtyStatesChanged, r);
return this;
}
public G22NetworkInstance removeDirtyStatesChangedListener(Runnable r) {
main.remove(onDirtyStatesChanged, r);
return this;
}
public void dirtyStatesChanged() {
if (onDirtyStatesChanged != null)
for (var listener : onDirtyStatesChanged) pcallF_typed(listener);
}
static public class Value {
final public Value setObject(Object object) {
return object(object);
}
public Value object(Object object) {
this.object = object;
return this;
}
final public Object getObject() {
return object();
}
public Object object() {
return object;
}
public Object object;
final public Value setCalculatedWhen(Timestamp calculatedWhen) {
return calculatedWhen(calculatedWhen);
}
public Value calculatedWhen(Timestamp calculatedWhen) {
this.calculatedWhen = calculatedWhen;
return this;
}
final public Timestamp getCalculatedWhen() {
return calculatedWhen();
}
public Timestamp calculatedWhen() {
return calculatedWhen;
}
public Timestamp calculatedWhen;
final public Value setDirty(boolean dirty) {
return dirty(dirty);
}
public Value dirty(boolean dirty) {
this.dirty = dirty;
return this;
}
final public boolean getDirty() {
return dirty();
}
public boolean dirty() {
return dirty;
}
public boolean dirty = false;
public Object get() {
return object;
}
public String toString() {
return classNameWithIdentity(this) + ": " + object;
}
}
public void calculateNode(G22Utils g22utils, G22NetworkElement e) {
if (e == null)
return;
Value value = valuesByBlueprint.get(e);
Object instance = e.makeInstance(g22utils, this);
print("Calculated: " + instance);
value.object(instance).calculatedWhen(tsNow());
if (value.dirty()) {
value.dirty(false);
dirtyStatesChanged();
}
invalidateDependentNodes(e);
}
public void init(G22Utils g22utils) {
for (var e : network.elements) {
Value value = new Value();
value.dirty(true);
dirtyStatesChanged();
valuesByBlueprint.put(e, value);
mapPut(valuesByIdentifier, e.identifier(), value);
}
}
public Object getObjectForBlueprint(G22NetworkElement element) {
var value = valuesByBlueprint.get(element);
Object object = value.get();
printVars("getObjectForBlueprint", "element", element, "value", value, "object", object);
return object;
}
public void invalidateDependentNodes(G22NetworkElement element) {
if (element == null)
return;
print("invalidateDependentNodes", element);
for (var e : element.downstreamNodes()) invalidateNode(e);
}
public boolean isCalculable(G22NetworkElement element) {
return all(element.upstreamNodes(), e -> !valuesByBlueprint.get(e).dirty());
}
public void invalidateNode(G22NetworkElement element) {
print("invalidateNode", element);
var value = valuesByBlueprint.get(element);
if (value.dirty())
return;
value.dirty(true);
dirtyStatesChanged();
invalidateDependentNodes(element);
}
}
static public Set createOrAddToSyncLinkedHashSet(Set set, A a) {
if (set == null)
set = syncLinkedHashSet();
set.add(a);
return set;
}
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 pcallF_typed(F0 f) {
try {
return f == null ? null : f.get();
} catch (Throwable __e) {
printStackTrace(__e);
}
return null;
}
static public B pcallF_typed(F1 f, A a) {
try {
return f == null ? null : f.get(a);
} catch (Throwable __e) {
printStackTrace(__e);
}
return null;
}
static public void pcallF_typed(VF1 f, A a) {
try {
{
if (f != null)
f.get(a);
}
} catch (Throwable __e) {
printStackTrace(__e);
}
}
static public void pcallF_typed(IVF1 f, A a) {
try {
{
if (f != null)
f.get(a);
}
} catch (Throwable __e) {
printStackTrace(__e);
}
}
static public void pcallF_typed(IVF2 f, A a, B b) {
try {
{
if (f != null)
f.get(a, b);
}
} catch (Throwable __e) {
printStackTrace(__e);
}
}
static public Object pcallF_typed(Runnable r) {
try {
{
if (r != null)
r.run();
}
} catch (Throwable __e) {
printStackTrace(__e);
}
return null;
}
static public A pcallF_typed(IF0 f) {
try {
return f == null ? null : f.get();
} catch (Throwable __e) {
printStackTrace(__e);
}
return null;
}
static public B pcallF_typed(IF1 f, A a) {
try {
return f == null ? null : f.get(a);
} catch (Throwable __e) {
printStackTrace(__e);
}
return null;
}
static public String classNameWithIdentity(Object o) {
return o == null ? null : withIdentity(o, className(o));
}
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 Timestamp tsNow() {
return new Timestamp();
}
static public void mapPut(Map map, A key, B value) {
if (map != null && key != null && value != null)
map.put(key, value);
}
static public void mapPut(Map map, Pair p) {
if (map != null && p != null)
map.put(p.a, p.b);
}
static public void printVars(Object... params) {
printVars_str(params);
}
static public boolean all(Object pred, Iterable l) {
if (l != null)
for (Object o : l) if (!isTrue(callF(pred, o)))
return false;
return true;
}
static public boolean all(Iterable l, IF1 f) {
if (l != null)
for (A a : l) if (!f.get(a))
return false;
return true;
}
static public boolean all(IF1 f, Iterable l) {
return all(l, f);
}
static public boolean all(int[] l, IIntPred f) {
if (l != null)
for (int i : l) if (!f.get(i))
return false;
return true;
}
static public AutoCloseable tempInterceptPrintIfNotIntercepted(F1 f) {
return print_byThread().get() == null ? tempInterceptPrint(f) : null;
}
static public Set syncLinkedHashSet() {
return synchroLinkedHashSet();
}
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 int l(IntSize o) {
return o == null ? 0 : o.size();
}
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 String withIdentity(Object o, String s) {
return withIdentityHash(o, s);
}
static public String className(Object o) {
return getClassName(o);
}
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 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 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 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 Class mc() {
return main.class;
}
static public void printVars_str(Object... params) {
print(renderVars_str(params));
}
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 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 Set synchroLinkedHashSet() {
return synchronizedSet(new CompactLinkedHashSet());
}
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 String withIdentityHash(Object o, String s) {
return o == null ? s : addSuffix(s, "@" + intToHex_flexLength(identityHashCode(o)));
}
static public String getClassName(Object o) {
return o == null ? "null" : o instanceof Class ? ((Class) o).getName() : o.getClass().getName();
}
static public boolean endsWithLetterOrDigit(String s) {
return s != null && s.length() > 0 && Character.isLetterOrDigit(s.charAt(s.length() - 1));
}
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 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 A or(A a, A b) {
return a != null ? a : b;
}
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 Map newDangerousWeakHashMap() {
return _registerDangerousWeakMap(synchroMap(new WeakHashMap()));
}
static public Map newDangerousWeakHashMap(Object initFunction) {
return _registerDangerousWeakMap(synchroMap(new WeakHashMap()), initFunction);
}
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 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 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 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 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 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 String renderVars_str(Object... params) {
List l = new ArrayList();
int i = 0;
if (odd(l(params))) {
l.add(strOrNull(first(params)));
++i;
}
for (; i + 1 < l(params); i += 2) l.add(params[i] + "=" + params[i + 1]);
return trim(joinWithComma(l));
}
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 Set synchronizedSet() {
return synchroHashSet();
}
static public Set synchronizedSet(Set set) {
return Collections.synchronizedSet(set);
}
static public String addSuffix(String s, String suffix) {
return s == null || s.endsWith(suffix) ? s : s + suffix;
}
static public String intToHex_flexLength(int i) {
return Integer.toHexString(i);
}
static public int identityHashCode(Object o) {
return System.identityHashCode(o);
}
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 void failIfUnlicensed() {
assertTrue("license off", licensed());
}
static public Thread currentThread() {
return Thread.currentThread();
}
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 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 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 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 RuntimeException asRuntimeException(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
return t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
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 public List classNames(Collection l) {
return getClassNames(l);
}
static public List classNames(Object[] l) {
return getClassNames(asList(l));
}
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 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 void _handleError(Error e) {
}
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 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 boolean odd(int i) {
return (i & 1) != 0;
}
static public boolean odd(long i) {
return (i & 1) != 0;
}
static public boolean odd(BigInteger i) {
return odd(toInt(i));
}
static public String strOrNull(Object o) {
return o == null ? null : str(o);
}
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 String trim(String s) {
return s == null ? null : s.trim();
}
static public String trim(StringBuilder buf) {
return buf.toString().trim();
}
static public String trim(StringBuffer buf) {
return buf.toString().trim();
}
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 A setThreadLocal(ThreadLocal tl, A value) {
if (tl == null)
return null;
A old = tl.get();
tl.set(value);
return old;
}
static public Set synchroHashSet() {
return synchronizedSet(new HashSet ());
}
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 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 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 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 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 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 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 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 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());
}
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 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 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 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 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 int toInt(Object o) {
if (o == null)
return 0;
if (o instanceof Number)
return ((Number) o).intValue();
if (o instanceof String)
return parseInt((String) o);
if (o instanceof Boolean)
return boolToInt((Boolean) o);
throw fail("woot not int: " + getClassName(o));
}
static public int toInt(long l) {
if (l != (int) l)
throw fail("Too large for int: " + l);
return (int) l;
}
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 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 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 HashSet litset(A... items) {
return lithashset(items);
}
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 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 Map synchronizedMap() {
return synchroMap();
}
static public Map synchronizedMap(Map map) {
return synchroMap(map);
}
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 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 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 int strL(String s) {
return s == null ? 0 : s.length();
}
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 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 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 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 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 identityHashSet() {
return Collections.newSetFromMap(new IdentityHashMap());
}
static public int parseInt(String s) {
return emptyString(s) ? 0 : Integer.parseInt(s);
}
static public int parseInt(char c) {
return Integer.parseInt(str(c));
}
static public int boolToInt(boolean b) {
return b ? 1 : 0;
}
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 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 void _onJavaXSet() {
}
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 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 > A max(Iterable l) {
A max = null;
var it = iterator(l);
if (it.hasNext()) {
max = it.next();
while (it.hasNext()) {
A a = it.next();
if (cmp(a, max) > 0)
max = a;
}
}
return max;
}
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 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 Map emptyMap() {
return new HashMap();
}
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 int lCharSequence(CharSequence s) {
return s == null ? 0 : s.length();
}
static public String asString(Object o) {
return o == null ? null : o.toString();
}
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 Object getOptDynOnly(DynamicObject o, String field) {
if (o == null || o.fieldValues == null)
return null;
return o.fieldValues.get(field);
}
static public boolean emptyString(String s) {
return s == null || s.length() == 0;
}
static public List immutableEmptyList() {
return Collections.emptyList();
}
static public short[] emptyShortArray = new short[0];
static public short[] emptyShortArray() {
return emptyShortArray;
}
static public Map immutableEmptyMap() {
return Collections.emptyMap();
}
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);
}
static public Iterator iterator(Iterable c) {
return c == null ? emptyIterator() : c.iterator();
}
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 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 boolean regionMatchesIC(String a, int offsetA, String b, int offsetB, int len) {
return a != null && a.regionMatches(true, offsetA, b, offsetB, len);
}
static public Iterator emptyIterator() {
return Collections.emptyIterator();
}
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);
}
}
}
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 G22NetworkElement extends MetaWithChangeListeners {
public G22NetworkElement() {
}
final public G22NetworkElement setNetwork(G22Network network) {
return network(network);
}
public G22NetworkElement network(G22Network network) {
this.network = network;
return this;
}
final public G22Network getNetwork() {
return network();
}
public G22Network network() {
return network;
}
public G22Network network;
final public G22NetworkElement setBounds(Rect bounds) {
return bounds(bounds);
}
public G22NetworkElement bounds(Rect bounds) {
this.bounds = bounds;
return this;
}
final public Rect getBounds() {
return bounds();
}
public Rect bounds() {
return bounds;
}
public Rect bounds;
public transient FieldVar varIdentifier_cache;
public FieldVar varIdentifier() {
if (varIdentifier_cache == null)
varIdentifier_cache = varIdentifier_load();
return varIdentifier_cache;
}
public FieldVar varIdentifier_load() {
return new FieldVar(this, "identifier", () -> identifier(), identifier -> identifier(identifier));
}
final public G22NetworkElement setIdentifier(String identifier) {
return identifier(identifier);
}
public G22NetworkElement identifier(String identifier) {
if (!eq(this.identifier, identifier)) {
this.identifier = identifier;
change();
}
return this;
}
final public String getIdentifier() {
return identifier();
}
public String identifier() {
return identifier;
}
public String identifier;
public transient FieldVar varCode_cache;
public FieldVar varCode() {
if (varCode_cache == null)
varCode_cache = varCode_load();
return varCode_cache;
}
public FieldVar varCode_load() {
return new FieldVar(this, "code", () -> code(), code -> code(code));
}
final public G22NetworkElement setCode(String code) {
return code(code);
}
public G22NetworkElement code(String code) {
if (!eq(this.code, code)) {
this.code = code;
change();
}
return this;
}
final public String getCode() {
return code();
}
public String code() {
return code;
}
public String code;
{
onChange(() -> {
{
if (network != null)
network.change();
}
});
}
public class Port extends MetaWithChangeListeners {
public transient FieldVar varPosition_cache;
public FieldVar varPosition() {
if (varPosition_cache == null)
varPosition_cache = varPosition_load();
return varPosition_cache;
}
public FieldVar varPosition_load() {
return new FieldVar(this, "position", () -> position(), position -> position(position));
}
final public Port setPosition(DoublePt position) {
return position(position);
}
public Port position(DoublePt position) {
if (!eq(this.position, position)) {
this.position = position;
change();
}
return this;
}
final public DoublePt getPosition() {
return position();
}
public DoublePt position() {
return position;
}
public DoublePt position;
public transient FieldVar varName_cache;
public FieldVar varName() {
if (varName_cache == null)
varName_cache = varName_load();
return varName_cache;
}
public FieldVar varName_load() {
return new FieldVar(this, "name", () -> name(), name -> name(name));
}
final public Port setName(String name) {
return name(name);
}
public Port name(String name) {
if (!eq(this.name, name)) {
this.name = name;
change();
}
return this;
}
final public String getName() {
return name();
}
public String name() {
return name;
}
public String name;
public transient FieldVar varCable_cache;
public FieldVar varCable() {
if (varCable_cache == null)
varCable_cache = varCable_load();
return varCable_cache;
}
public FieldVar varCable_load() {
return new FieldVar(this, "cable", () -> cable(), cable -> cable(cable));
}
final public Port setCable(G22NetworkCable cable) {
return cable(cable);
}
public Port cable(G22NetworkCable cable) {
if (!eq(this.cable, cable)) {
this.cable = cable;
change();
}
return this;
}
final public G22NetworkCable getCable() {
return cable();
}
public G22NetworkCable cable() {
return cable;
}
public G22NetworkCable cable;
public transient FieldVar varIsOutput_cache;
public FieldVar varIsOutput() {
if (varIsOutput_cache == null)
varIsOutput_cache = varIsOutput_load();
return varIsOutput_cache;
}
public FieldVar varIsOutput_load() {
return new FieldVar(this, "isOutput", () -> isOutput(), isOutput -> isOutput(isOutput));
}
final public Port setIsOutput(boolean isOutput) {
return isOutput(isOutput);
}
public Port isOutput(boolean isOutput) {
if (!eq(this.isOutput, isOutput)) {
this.isOutput = isOutput;
change();
}
return this;
}
final public boolean getIsOutput() {
return isOutput();
}
public boolean isOutput() {
return isOutput;
}
public boolean isOutput = false;
public transient FieldVar varDataType_cache;
public FieldVar varDataType() {
if (varDataType_cache == null)
varDataType_cache = varDataType_load();
return varDataType_cache;
}
public FieldVar varDataType_load() {
return new FieldVar(this, "dataType", () -> dataType(), dataType -> dataType(dataType));
}
final public Port setDataType(Class dataType) {
return dataType(dataType);
}
public Port dataType(Class dataType) {
if (!eq(this.dataType, dataType)) {
this.dataType = dataType;
change();
}
return this;
}
final public Class getDataType() {
return dataType();
}
public Class dataType() {
return dataType;
}
public Class dataType;
public G22NetworkElement element() {
return G22NetworkElement.this;
}
public String toString() {
return renderVars("Port", "name", name, "isOutput", isOutput);
}
public Rect bounds() {
int size = 10;
Rect r = element().bounds;
if (r == null)
return null;
r = growRectTopAndLeft(r, size);
return rect(r.x + iround(position.x * r.w), r.y + iround(position.y * r.h), size, size);
}
}
public List ports = syncL();
public LASCompileResult newCompileResult() {
return new LASCompileResult();
}
transient public LASCompileResult compileResult;
public LASCompileResult compile(G22Utils g22utils) {
String code = this.code;
if (code == null)
return null;
var cr = compileResult;
if (cr != null && eq(cr.script, code))
return cr;
cr = newCompileResult();
var parser = g22utils.leftArrowParser();
configureParser(parser);
cr.script(code).parser(parser).compile();
return compileResult = cr;
}
public void configureParser(GazelleV_LeftArrowScriptParser parser) {
parser.addVar("blueprint");
}
public GazelleV_LeftArrowScript.Script compileScript(G22Utils g22utils) {
try {
var compiled = compile(g22utils);
if (compiled == null)
return null;
if (!compiled.runnable())
return null;
return compiled.get();
} catch (Throwable __e) {
return null;
}
}
public void configureBlueprint(G22Utils g22utils) {
var script = compileScript(g22utils);
if (script == null)
return;
FlexibleVarContext ctx = new FlexibleVarContext();
var f = script.getFunction("configure");
if (f != null)
f.call(ctx, this);
}
public Object makeInstance(G22Utils g22utils, G22NetworkInstance networkInstance) {
try {
var script = compileScript(g22utils);
if (script == null)
return null;
FlexibleVarContext ctx = new FlexibleVarContext();
for (var port : ports) if (!port.isOutput() && port.cable != null) {
var outputPort = port.cable.from;
if (outputPort != null)
ctx.set(port.name, networkInstance.getObjectForBlueprint(outputPort.element()));
}
return script.get(ctx);
} catch (Throwable __e) {
return null;
}
}
public Set upstreamNodes() {
Set set = new HashSet();
for (var port : ports) if (!port.isOutput() && port.cable != null) {
var outputPort = port.cable.from;
if (outputPort != null)
set.add(outputPort.element());
}
return set;
}
public Set downstreamNodes() {
Set set = new HashSet();
for (var port : ports) if (port.isOutput() && port.cable != null) {
var outputPort = port.cable.to;
if (outputPort != null)
set.add(outputPort.element());
}
return set;
}
public String toString() {
return or2(identifier(), "Unnamed element");
}
public Port getPort(String name) {
return firstThat(ports, p -> eq(p.name, name));
}
final public void addSlot(String name, double position_x, double position_y) {
addSlot(name, doublePt(position_x, position_y));
}
final public void addSlot(String name, DoublePt position) {
addPort(name, position);
}
public void addPort(String name, double position_x, double position_y) {
addPort(name, doublePt(position_x, position_y));
}
public void addPort(String name, DoublePt position) {
printFunctionCall("addPort", "name", name, "position", position);
Port p = getPort(name);
if (p != null)
return;
ports.add(new Port().name(name).position(position));
change();
}
public void addInputPort(String name, double position_x, double position_y, Class type) {
addInputPort(name, doublePt(position_x, position_y), type);
}
public void addInputPort(String name, DoublePt position, Class type) {
Port p = getPort(name);
if (p != null)
return;
ports.add(new Port().name(name).position(position).isOutput(false).dataType(type));
change();
}
public void addOutputPort(String name, double position_x, double position_y, Class type) {
addOutputPort(name, doublePt(position_x, position_y), type);
}
public void addOutputPort(String name, DoublePt position, Class type) {
Port p = getPort(name);
if (p != null)
return;
p = new Port().name(name).position(position).isOutput(true).dataType(type);
ports.add(p);
print("Made port " + p);
change();
}
final public void deletePorts() {
removePorts();
}
final public void removeSlots() {
removePorts();
}
final public void deleteSlots() {
removePorts();
}
public void removePorts() {
ports.clear();
change();
}
public List ports() {
return cloneList(ports);
}
}
static public class G22Utils_Base {
transient public Set> onProjectFileChanged;
public G22Utils_Base onProjectFileChanged(IVF1 f) {
onProjectFileChanged = createOrAddToSyncLinkedHashSet(onProjectFileChanged, f);
return this;
}
public G22Utils_Base removeProjectFileChangedListener(IVF1 f) {
main.remove(onProjectFileChanged, f);
return this;
}
public void projectFileChanged(File file) {
if (onProjectFileChanged != null)
for (var listener : onProjectFileChanged) pcallF_typed(listener, file);
}
}
static public class G22Utils extends G22Utils_Base implements AutoCloseable, TransientObject {
final public G22Utils setBackgroundProcessesUI(IBackgroundProcesses backgroundProcessesUI) {
return backgroundProcessesUI(backgroundProcessesUI);
}
public G22Utils backgroundProcessesUI(IBackgroundProcesses backgroundProcessesUI) {
this.backgroundProcessesUI = backgroundProcessesUI;
return this;
}
final public IBackgroundProcesses getBackgroundProcessesUI() {
return backgroundProcessesUI();
}
public IBackgroundProcesses backgroundProcessesUI() {
return backgroundProcessesUI;
}
public IBackgroundProcesses backgroundProcessesUI;
final public G22Utils setModule(Enterable module) {
return module(module);
}
public G22Utils module(Enterable module) {
this.module = module;
return this;
}
final public Enterable getModule() {
return module();
}
public Enterable module() {
return module;
}
public Enterable module;
final public G22Utils setMasterStuff(G22MasterStuff masterStuff) {
return masterStuff(masterStuff);
}
public G22Utils masterStuff(G22MasterStuff masterStuff) {
this.masterStuff = masterStuff;
return this;
}
final public G22MasterStuff getMasterStuff() {
return masterStuff();
}
public G22MasterStuff masterStuff() {
return masterStuff;
}
public G22MasterStuff masterStuff;
final public G22Utils setConcepts(Concepts concepts) {
return concepts(concepts);
}
public G22Utils concepts(Concepts concepts) {
this.concepts = concepts;
return this;
}
final public Concepts getConcepts() {
return concepts();
}
public Concepts concepts() {
return concepts;
}
public Concepts concepts;
final public G22Utils setProjectActions(G22ProjectActions projectActions) {
return projectActions(projectActions);
}
public G22Utils projectActions(G22ProjectActions projectActions) {
this.projectActions = projectActions;
return this;
}
final public G22ProjectActions getProjectActions() {
return projectActions();
}
public G22ProjectActions projectActions() {
return projectActions;
}
public G22ProjectActions projectActions;
final public G22AutoStarter getAutoStarter() {
return autoStarter();
}
public G22AutoStarter autoStarter() {
return autoStarter;
}
public G22AutoStarter autoStarter = new G22AutoStarter(this);
final public G22Utils setFunctionTimings(FunctionTimings functionTimings) {
return functionTimings(functionTimings);
}
public G22Utils functionTimings(FunctionTimings functionTimings) {
this.functionTimings = functionTimings;
return this;
}
final public FunctionTimings getFunctionTimings() {
return functionTimings();
}
public FunctionTimings functionTimings() {
return functionTimings;
}
public FunctionTimings functionTimings = new FunctionTimings();
public FileWatchService fileWatcher;
public boolean projectFileListenerInitiated = false;
final public CombinedStringifier getStringifier() {
return stringifier();
}
public CombinedStringifier stringifier() {
return stringifier;
}
public CombinedStringifier stringifier = new CombinedStringifier(o -> o instanceof BufferedImage ? "Image (" + ((BufferedImage) o).getWidth() + "*" + ((BufferedImage) o).getHeight() + " px)" : null);
public ILASClassLoader lasClassLoader() {
return masterStuff == null ? null : masterStuff.lasClassLoader();
}
public ImageSurface stdImageSurface() {
var is = pixelatedImageSurface().setAutoZoomToDisplay(true).repaintInThread(false);
is.defaultImageDir = () -> dbDir();
is.specialPurposed = true;
new ImageSurface_PositionToolTip(is);
return is;
}
public ImageSurface stdImageSurface(MakesBufferedImage img) {
return stdImageSurface(toBufferedImage(img));
}
public ImageSurface stdImageSurface(BufferedImage img) {
var is = stdImageSurface();
is.setImage(img);
return is;
}
public ImageSurface stdImageSurfaceWithSelection(MakesBufferedImage img, Rect selection) {
return stdImageSurfaceWithSelection(toBufferedImage(img), selection);
}
public ImageSurface stdImageSurfaceWithSelection(BufferedImage img, Rect selection) {
var is = stdImageSurface(img);
is.setSelection(selection);
return is;
}
public String stringify(Object o) {
return stringifier.toString(o);
}
transient public Set> onSettingUpParser;
public G22Utils onSettingUpParser(IVF1 f) {
onSettingUpParser = createOrAddToSyncLinkedHashSet(onSettingUpParser, f);
return this;
}
public G22Utils removeSettingUpParserListener(IVF1 f) {
main.remove(onSettingUpParser, f);
return this;
}
public void settingUpParser(GazelleV_LeftArrowScriptParser parser) {
if (onSettingUpParser != null)
for (var listener : onSettingUpParser) pcallF_typed(listener, parser);
}
transient public Set> onSettingUpScriptIDE;
public G22Utils onSettingUpScriptIDE(IVF1 f) {
onSettingUpScriptIDE = createOrAddToSyncLinkedHashSet(onSettingUpScriptIDE, f);
return this;
}
public G22Utils removeSettingUpScriptIDEListener(IVF1 f) {
main.remove(onSettingUpScriptIDE, f);
return this;
}
public void settingUpScriptIDE(JLeftArrowScriptIDE ide) {
if (onSettingUpScriptIDE != null)
for (var listener : onSettingUpScriptIDE) pcallF_typed(listener, ide);
}
public GazelleV_LeftArrowScriptParser leftArrowParser() {
GazelleV_LeftArrowScriptParser parser = new GazelleV_LeftArrowScriptParser();
parser.classNameResolver(classNameResolver());
parser.lasClassLoader(lasClassLoader());
settingUpParser(parser);
parser.addClassAlias("Freq", "Frequency");
return parser;
}
public void basicParserTest() {
var parser = leftArrowParser();
print("classContainerPrefixes", parser.classContainerPrefixes());
assertEquals(pair(1, 2), parser.parse("new Pair 1 2").get());
}
public JLeftArrowScriptIDE leftArrowIDE() {
JLeftArrowScriptIDE ide = new JLeftArrowScriptIDE();
ide.g22utils(this);
ide.scriptTimeout(projectWideScriptTimeout());
settingUpScriptIDE(ide);
return ide;
}
public File byteCodePath() {
return assertNotNull(getBytecodePathForClass(this));
}
public ClassNameResolver classNameResolver_cache;
public ClassNameResolver classNameResolver() {
if (classNameResolver_cache == null)
classNameResolver_cache = classNameResolver_load();
return classNameResolver_cache;
}
public ClassNameResolver classNameResolver_load() {
return new ClassNameResolver().byteCodePath(byteCodePath()).init();
}
public File databasesMotherDir() {
return javaxDataDir("Gazelle-22");
}
public File dirOfProjectNamed(String name) {
assertNempty(name);
return newFile(databasesMotherDir(), name);
}
public AutoCloseable enter() {
return module == null ? null : module.enter();
}
public String defaultDBName() {
return "Default";
}
public File lastOpenedDBsFile() {
return newFile(databasesMotherDir(), "Last Opened");
}
public File autoUpdateFile() {
return newFile(databasesMotherDir(), "Auto-Update");
}
public boolean autoUpdateEnabled() {
return fileExists(autoUpdateFile());
}
public void setAutoUpdate(boolean b) {
createOrRemoveFile(autoUpdateFile(), b);
}
public List dbsToOpen() {
List dbNames = new ArrayList();
for (String name : tlft(loadTextFile(lastOpenedDBsFile()))) {
String name2 = dropPrefix("*", name);
if (fileExists(newFile(databasesMotherDir(), name2)))
dbNames.add(name);
}
if (empty(dbNames))
dbNames.add(defaultDBName());
return dbNames;
}
public void setOpenDBs(Collection extends IG22LoadedDB> dbs) {
List dbNames = new ArrayList();
for (var db : dbs) {
var dbDir = conceptsDir(db.concepts());
if (sameFile(databasesMotherDir(), dirOfFile(dbDir)))
dbNames.add((db.hidden() ? "*" : "") + fileName(dbDir));
}
saveTextFile(lastOpenedDBsFile(), lines(dbNames));
}
public Map scriptToMap(G22LeftArrowScript c) {
return scriptToMap(c, false);
}
public Map scriptToMap(G22LeftArrowScript c, boolean allowRunOnProjectOpen) {
return litorderedmap("Description", str(c), "Status", renderScriptStatus(c), "LoC", renderScriptLoC(c), "Import note", c.importNote, "Run on project open", c.renderRunOnProjectOpenStatus());
}
public String renderScriptStatus(G22LeftArrowScript c) {
return or2_rev("Empty", joinNemptiesWithSpacedPlus(c.isClearForAutoRun() ? "Clear for auto-run" : null, c.isSavedDistinctFromAutoRunVersion() ? "Saved (not cleared)" : null, c.isEditing() ? "Editing" : null));
}
public String renderScriptLoC(G22LeftArrowScript c) {
return n2(intMax(mapLL(__55 -> linesOfCode_javaTok(__55), c.editingText, c.text, c.codeForAutoRun())));
}
public List labelsForFile(File file) {
if (file == null)
return null;
File labelsFile = appendToFileName(file, ".labels");
List labels = tlft(loadTextFile(labelsFile));
return map(__56 -> getLabel(__56), labels);
}
public File labelsFile(File file) {
if (file == null)
return null;
return appendToFileName(file, ".labels");
}
public void setLabelsForFile(File file, List labels) {
List list = map(labels, label -> label.name);
File f = labelsFile(file);
saveTextFile(f, lines(list));
print("Saved " + nLabels(list) + " (" + joinWithComma(list) + ") to " + f);
}
public G22Label getLabel(String name) {
if (empty(name))
return null;
if (containsNewLine(name))
throw fail("No newlines in label names allowed: " + name);
return uniqCI(concepts, G22Label.class, "name", name);
}
final public File projectDir() {
return dbDir();
}
public File dbDir() {
return conceptsDir(concepts);
}
final public File projectFile(String name) {
return fileInDbDir(name);
}
public File fileInDbDir(String name) {
return newFile(dbDir(), name);
}
public class GazelleDB implements IFieldsToList {
public String name;
public File dir;
public GazelleDB() {
}
public GazelleDB(String name, File dir) {
this.dir = dir;
this.name = name;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + name + ", " + dir + ")";
}
public boolean equals(Object o) {
if (!(o instanceof GazelleDB))
return false;
GazelleDB __0 = (GazelleDB) o;
return eq(name, __0.name) && eq(dir, __0.dir);
}
public int hashCode() {
int h = 1669530526;
h = boostHashCombine(h, _hashCode(name));
h = boostHashCombine(h, _hashCode(dir));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { name, dir };
}
public String name() {
return name;
}
public File dir() {
return dir;
}
public boolean loaded() {
return loadedDB() != null;
}
public IG22LoadedDB loadedDB_cache;
public IG22LoadedDB loadedDB() {
if (loadedDB_cache == null)
loadedDB_cache = loadedDB_load();
return loadedDB_cache;
}
public IG22LoadedDB loadedDB_load() {
return masterStuff.getLoadedDBForConceptDir(dir);
}
public File conceptsFile() {
return conceptsFileIn(dir);
}
}
public List gazelleDBs() {
List dbs = new ArrayList();
for (File dir : listDirsContainingFileNamed(databasesMotherDir(), "concepts.structure.gz")) dbs.add(new GazelleDB(fileName(dir), dir));
return dbs;
}
public RSyntaxTextAreaWithSearch newSyntaxTextArea() {
return newSyntaxTextArea((IF1) null);
}
public RSyntaxTextAreaWithSearch newSyntaxTextArea(IF1 wrapStatusLabel) {
RSyntaxTextAreaWithSearch ta = new RSyntaxTextAreaWithSearch(wrapStatusLabel);
ta.textArea().setHighlightCurrentLine(false);
ta.menuLessOperation();
return ta;
}
public RSyntaxTextAreaWithSearch newSyntaxTextArea(String text) {
var ta = newSyntaxTextArea();
ta.setText(text);
return ta;
}
public File projectStoryTextFile() {
return newFile(dbDir(), "story.txt");
}
public String projectName() {
return fileName(dbDir());
}
public void close() {
try {
autoStarter.close();
{
cleanUp(fileWatcher);
fileWatcher = null;
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public G22Variable findProjectVar(String name) {
return conceptWhere(concepts, G22Variable.class, "name", name);
}
public Object getProjectVar(String name) {
G22Variable var = findProjectVar(name);
return var == null ? null : var.value;
}
public Object waitForProjectVar(String name) {
G22Variable var = optimizedUniq(concepts, G22Variable.class, "name", name);
Object o = var.value;
{
var __2 = o;
if (__2 != null)
return __2;
}
return waitUntilNotNull(var.varValue());
}
public void setProjectVar(boolean persistent, String name, Object value) {
G22Variable var = optimizedUniq(concepts, G22Variable.class, "name", name);
if (!persistent)
var.persistent(persistent);
var.value(value);
if (persistent)
var.persistent(persistent);
}
public void setTransientProjectVar(String name, Object value) {
G22Variable var = optimizedUniq(concepts, G22Variable.class, "name", name);
var.persistent(false).value(value);
}
public void deleteProjectVar(String name) {
deleteConcept(findProjectVar(name));
}
public IVarWithNotify liveProjectVar(String name) {
return liveProjectVar(name, null);
}
public IVarWithNotify liveProjectVar(String name, Object defaultValue) {
G22Variable var = optimizedUniq(concepts, G22Variable.class, "name", name);
var.persistent(true);
var.setValueIfNull(defaultValue);
return var.varValue();
}
public IVarWithNotify liveTransientProjectVar(String name) {
return liveTransientProjectVar(name, null);
}
public IVarWithNotify liveTransientProjectVar(String name, Object defaultValue) {
G22Variable var = optimizedUniq(concepts, G22Variable.class, "name", name);
var.persistent(false);
var.setValueIfNull(defaultValue);
return var.varValue();
}
public void replaceCloseableProjectVar(String name, IF0 extends AutoCloseable> calc) {
Object value = getProjectVar(name);
if (value instanceof AutoCloseable) {
main.close((AutoCloseable) value);
deleteProjectVar(name);
}
setTransientProjectVar(name, calc == null ? null : calc.get());
}
public double defaultScriptTimeout() {
return 10.0;
}
public double projectWideScriptTimeout() {
return or(toDoubleOrNull(getProjectVar("!Script Timeout")), defaultScriptTimeout());
}
public G22Analyzer getAnalyzer(long id) {
var a = getConcept(concepts, G22Analyzer.class, id);
if (a == null)
throw fail("Analyzer not found: " + id);
return a;
}
public G22LeftArrowScript getScript(long id) {
var a = getConcept(concepts, G22LeftArrowScript.class, id);
if (a == null)
throw fail("Script not found: " + id);
return a;
}
public Object callScript(long id) {
var script = getScript(id);
return script.evaluateWithoutTimeout();
}
public Object callAutoRunnableScript(long id) {
var script = getScript(id);
return script.evaluateAutoRunWithoutTimeout();
}
public double defaultTimeout() {
return infinity();
}
public A evalRegisteredCode(String processName, IF0 code) {
return evalRegisteredCode(defaultTimeout(), processName, code);
}
public A evalRegisteredCode(double timeoutSeconds, String processName, IF0 code) {
if (code == null)
return null;
return evalWithTimeoutOrTypedException(timeoutSeconds, () -> {
AutoCloseable __3 = enter();
try {
var process = backgroundProcessesUI.tempAdd(processName);
try {
Thread myThread = currentThread();
process.setInterruptAction(new Runnable() {
public void run() {
try {
cancelThread(myThread);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "cancelThread(myThread)";
}
});
return code.get();
} finally {
_close(process);
}
} finally {
_close(__3);
}
});
}
public Object host() {
AutoCloseable __4 = enter();
try {
return dm_os();
} finally {
_close(__4);
}
}
public A timeFunction(String name, IF0 f) {
return functionTimings.get(name, f);
}
public boolean isConceptsDir(File dir) {
return isSameFile(conceptsDir(concepts), dir);
}
synchronized public FileWatchService fileWatcher() {
{
if (fileWatcher == null)
fileWatcher = new FileWatchService();
return fileWatcher;
}
}
synchronized public G22Utils onProjectFileChanged(IVF1 listener) {
super.onProjectFileChanged(listener);
if (!projectFileListenerInitiated) {
projectFileListenerInitiated = true;
fileWatcher().addRecursiveListener(dbDir(), __5 -> projectFileChanged(__5));
}
return this;
}
public G22ProjectInfo projectInfo_cache;
public G22ProjectInfo projectInfo() {
if (projectInfo_cache == null)
projectInfo_cache = projectInfo_load();
return projectInfo_cache;
}
public G22ProjectInfo projectInfo_load() {
return optimizedUniq(concepts, G22ProjectInfo.class);
}
public RunnablesReferenceQueue runnablesReferenceQueue() {
return masterStuff.runnablesReferenceQueue();
}
public EphemeralObjectIDs ephemeralObjectIDs() {
return masterStuff.ephemeralObjectIDs();
}
public Object eph(long id) {
return ephemeralObjectIDs().get(id);
}
public void openInBrowser(String url) {
if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE))
main.openInBrowser(url);
else {
String cmd;
if (projectInfo().useFirefox() && isOnPATH("firefox"))
cmd = "firefox";
else {
cmd = chromeCmd();
if (isRoot())
cmd += " -no-sandbox";
}
cmd += " " + platformQuote(url);
nohup(cmd);
}
}
public String compilationDate() {
return or2(compilationDateFromClassPath(this), "unknown");
}
public String projectID() {
return projectInfo().projectID();
}
public IG22LoadedDB getLoadedDB() {
return masterStuff.getLoadedDB(concepts);
}
}
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 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 CompactLinkedHashSet extends AbstractSet {
public UnsynchronizedCompactHashSet> entries = new UnsynchronizedCompactHashSet();
public Entry head, tail;
static public class Entry {
public A value;
public Entry prev, next;
public int hashCode() {
return _hashCode(value);
}
public boolean equals(Object o) {
return o == this || eq(value, o);
}
}
public boolean add(A a) {
if (entries.contains(a))
return false;
Entry n = new Entry();
n.value = a;
n.prev = tail;
if (tail != null)
tail.next = n;
tail = n;
if (head == null)
head = n;
entries.add(n);
return true;
}
public boolean remove(Object a) {
return remove(entries.find(a));
}
public boolean remove(Entry node) {
if (node == null)
return false;
if (node.next != null)
node.next.prev = node.prev;
else
tail = node.prev;
if (node.prev != null)
node.prev.next = node.next;
else
head = node.next;
entries.remove(node);
return true;
}
public int size() {
return entries.size();
}
public IterableIterator iterator() {
return new IterableIterator () {
public Entry entry = head, prev = null;
public boolean hasNext() {
return entry != null;
}
public A next() {
A a = entry.value;
prev = entry;
entry = entry.next;
return a;
}
public void remove() {
if (prev == null)
throw new IllegalStateException();
CompactLinkedHashSet.this.remove(prev);
prev = null;
}
};
}
public void clear() {
entries.clear();
head = tail = null;
}
public boolean contains(Object a) {
return entries.contains(a);
}
public A find(Object o) {
Entry e = entries.find(o);
return e == null ? null : e.value;
}
public A prevElement(A a) {
Entry e = entries.find(a);
if (e == null || e.prev == null)
return null;
return e.prev.value;
}
public A nextElement(A a) {
Entry e = entries.find(a);
if (e == null || e.next == null)
return null;
return e.next.value;
}
public A first() {
return head == null ? null : head.value;
}
public A last() {
return tail == null ? null : tail.value;
}
public boolean removeIfSame(Object o) {
A value = find(o);
if (value == o) {
remove(value);
return true;
}
return false;
}
}
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 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 G22Network extends ConceptWithChangeListeners {
public transient FieldVar varDescription_cache;
public FieldVar varDescription() {
if (varDescription_cache == null)
varDescription_cache = varDescription_load();
return varDescription_cache;
}
public FieldVar varDescription_load() {
return new FieldVar(this, "description", () -> description(), description -> description(description));
}
final public G22Network setDescription(String description) {
return description(description);
}
public G22Network description(String description) {
if (!eq(this.description, description)) {
this.description = description;
change();
}
return this;
}
final public String getDescription() {
return description();
}
public String description() {
return description;
}
public String description;
public Collection elements = syncL();
public transient FieldVar varMagneticDistance_cache;
public FieldVar varMagneticDistance() {
if (varMagneticDistance_cache == null)
varMagneticDistance_cache = varMagneticDistance_load();
return varMagneticDistance_cache;
}
public FieldVar varMagneticDistance_load() {
return new FieldVar(this, "magneticDistance", () -> magneticDistance(), magneticDistance -> magneticDistance(magneticDistance));
}
final public G22Network setMagneticDistance(int magneticDistance) {
return magneticDistance(magneticDistance);
}
public G22Network magneticDistance(int magneticDistance) {
if (!eq(this.magneticDistance, magneticDistance)) {
this.magneticDistance = magneticDistance;
change();
}
return this;
}
final public int getMagneticDistance() {
return magneticDistance();
}
public int magneticDistance() {
return magneticDistance;
}
public int magneticDistance;
public String toString() {
return or2(description, super.toString());
}
public void doMagneticConnections() {
deleteMagneticConnections();
List inputPorts = new ArrayList();
List outputPorts = new ArrayList();
for (var element : elements) for (var port : element.ports()) (port.isOutput() ? outputPorts : inputPorts).add(port);
for (var port1 : inputPorts) {
Rect bounds1 = port1.bounds();
Lowest best = new Lowest();
for (var port2 : outputPorts) {
double distance = rectDistance(bounds1, port2.bounds());
if (distance >= magneticDistance)
continue;
if (!isSubclassOf(port2.dataType(), port1.dataType()))
continue;
best.put(port2, distance);
}
var port2 = best.get();
if (port2 != null) {
var cable = new G22NetworkCable().from(port2).to(port1);
cable.connect();
print("Made cable: " + cable);
}
}
}
public void deleteMagneticConnections() {
for (var cable : allCables()) if (cable.isAutomatic())
cable.remove();
}
public Set allCables() {
Set set = new HashSet();
for (var element : elements) for (var port : element.ports()) addIfNotNull(set, port.cable);
return set;
}
}
static public class Value implements IF0 , IFieldsToList {
public A value;
public Value() {
}
public Value(A value) {
this.value = value;
}
public boolean equals(Object o) {
if (!(o instanceof Value))
return false;
Value __1 = (Value) o;
return eq(value, __1.value);
}
public int hashCode() {
int h = 82420049;
h = boostHashCombine(h, _hashCode(value));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { value };
}
public A get() {
return value;
}
public String toString() {
return str(get());
}
}
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 interface IVF2 {
public void get(A a, B b);
}
static public interface IIntPred {
public boolean get(int a);
}
public interface IVarWithNotify extends IVar , IF0WithChangeListeners {
default public IVarWithNotify onChange(IVF1 r) {
if (r == null)
return this;
onChange(() -> r.get(get()));
return this;
}
default public IVarWithNotify onChangeAndNow(IVF1 r) {
if (r == null)
return this;
onChangeAndNow(() -> r.get(get()));
return this;
}
}
public interface Enterable {
public AutoCloseable enter();
}
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 G22NetworkCable {
final public G22NetworkCable setFrom(G22NetworkElement.Port from) {
return from(from);
}
public G22NetworkCable from(G22NetworkElement.Port from) {
this.from = from;
return this;
}
final public G22NetworkElement.Port getFrom() {
return from();
}
public G22NetworkElement.Port from() {
return from;
}
public G22NetworkElement.Port from;
final public G22NetworkCable setTo(G22NetworkElement.Port to) {
return to(to);
}
public G22NetworkCable to(G22NetworkElement.Port to) {
this.to = to;
return this;
}
final public G22NetworkElement.Port getTo() {
return to();
}
public G22NetworkElement.Port to() {
return to;
}
public G22NetworkElement.Port to;
final public G22NetworkCable setIsAutomatic(boolean isAutomatic) {
return isAutomatic(isAutomatic);
}
public G22NetworkCable isAutomatic(boolean isAutomatic) {
this.isAutomatic = isAutomatic;
return this;
}
final public boolean getIsAutomatic() {
return isAutomatic();
}
public boolean isAutomatic() {
return isAutomatic;
}
public boolean isAutomatic = false;
public void connect() {
from.cable(this);
to.cable(this);
}
public void remove() {
{
if (from != null)
from.cable(null);
}
{
if (to != null)
to.cable(null);
}
}
public String toString() {
return renderVars("G22NetworkCable", "from", from, "to", to, "isAutomatic", isAutomatic);
}
}
static public class LASCompileResult {
final public LASCompileResult setScript(String script) {
return script(script);
}
public LASCompileResult script(String script) {
this.script = script;
return this;
}
final public String getScript() {
return script();
}
public String script() {
return script;
}
public String script;
final public LASCompileResult setParser(GazelleV_LeftArrowScriptParser parser) {
return parser(parser);
}
public LASCompileResult parser(GazelleV_LeftArrowScriptParser parser) {
this.parser = parser;
return this;
}
final public GazelleV_LeftArrowScriptParser getParser() {
return parser();
}
public GazelleV_LeftArrowScriptParser parser() {
return parser;
}
public GazelleV_LeftArrowScriptParser parser;
final public LASCompileResult setCompileError(Throwable compileError) {
return compileError(compileError);
}
public LASCompileResult compileError(Throwable compileError) {
this.compileError = compileError;
return this;
}
final public Throwable getCompileError() {
return compileError();
}
public Throwable compileError() {
return compileError;
}
public Throwable compileError;
public GazelleV_LeftArrowScript.Script parsedScript;
public RunResultWithTimestamps compileLog;
public String toString() {
if (compileError != null)
return errorToString();
if (parsedScript == null)
return "Not compiled yet";
return "Compiled OK" + (compileLog == null ? "" : " in " + n2(max(1, compileLog.duration().toMillis())) + " ms");
}
public String errorToString() {
return exceptionToStringShorter_dontDropOuterExceptions(compileError);
}
public boolean runnable() {
return parsedScript != null;
}
public void compile() {
compileLog = runResultWithTimestamps(() -> {
if (parser == null)
parser = makeParser();
return parsedScript = parser.parse(script);
});
if (compileLog.isError()) {
var e = compileLog.getError();
print(e);
compileError(e);
}
}
final public GazelleV_LeftArrowScript.Script get() {
return parsedScript();
}
public GazelleV_LeftArrowScript.Script parsedScript() {
return parsedScript;
}
public GazelleV_LeftArrowScript.Script parsedScriptMandatory() {
if (compileError != null)
throw fail(compileError);
return parsedScript;
}
transient public IF0 makeParser;
public GazelleV_LeftArrowScriptParser makeParser() {
return makeParser != null ? makeParser.get() : makeParser_base();
}
final public GazelleV_LeftArrowScriptParser makeParser_fallback(IF0 _f) {
return _f != null ? _f.get() : makeParser_base();
}
public GazelleV_LeftArrowScriptParser makeParser_base() {
return null;
}
public LineAndColumn errorLineAndCol() {
return parseLineAndColumn(str(compileError));
}
}
static public class ClassNameResolver {
final public ClassNameResolver setByteCodePath(File byteCodePath) {
return byteCodePath(byteCodePath);
}
public ClassNameResolver byteCodePath(File byteCodePath) {
this.byteCodePath = byteCodePath;
return this;
}
final public File getByteCodePath() {
return byteCodePath();
}
public File byteCodePath() {
return byteCodePath;
}
public File byteCodePath = byteCodePathForClass(getClass());
public List importedPackages = itemPlusList("java.lang", endingWith_dropSuffix(standardImports(), ".*"));
public Set allFullyQualifiedClassNames_cache;
public Set allFullyQualifiedClassNames() {
if (allFullyQualifiedClassNames_cache == null)
allFullyQualifiedClassNames_cache = allFullyQualifiedClassNames_load();
return allFullyQualifiedClassNames_cache;
}
public Set allFullyQualifiedClassNames_load() {
Set set = new HashSet();
assertNotNull(byteCodePath);
set.addAll(classNamesInJarOrDir(byteCodePath));
printVars("ClassNameResolver", "byteCodePath", byteCodePath, "classesFound", l(set));
set.addAll(classNamesInLoadedJigsawModules());
return set;
}
public ClassNameResolver init() {
allFullyQualifiedClassNames();
return this;
}
public String findClass(String name) {
for (String pkg : importedPackages) {
String fullName = pkg + "." + name;
if (allFullyQualifiedClassNames().contains(fullName))
return fullName;
}
return null;
}
public void printMe() {
printVars("ClassNameResolver", "byteCodePath", byteCodePath);
print("importedPackages", importedPackages);
}
}
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;
}
}
static public class RunnablesReferenceQueue implements AutoCloseable {
public ReferenceQueue queue = new ReferenceQueue();
volatile public Thread thread;
public Flag closed = new Flag();
final public RunnablesReferenceQueue setTimeout(int timeout) {
return timeout(timeout);
}
public RunnablesReferenceQueue timeout(int timeout) {
this.timeout = timeout;
return this;
}
final public int getTimeout() {
return timeout();
}
public int timeout() {
return timeout;
}
public int timeout = 60000;
public RunnablesReferenceQueue() {
thread = startThread("RunnablesReferenceQueue", () -> _run());
}
public void _run() {
try {
try {
while (ping() && !closed.get()) {
Reference> ref = queue.remove(timeout);
if (ref != null) {
if (ref instanceof Runnable)
pcallF((Runnable) ref);
else
warn("RunnablesReferenceQueue: Reference not runnable - " + className(ref));
}
}
} catch (InterruptedException e) {
} finally {
thread = null;
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public void close() {
try {
closed.raise();
interruptThread(thread);
} catch (Exception __e) {
throw rethrow(__e);
}
}
final public ReferenceQueue get() {
return queue();
}
public ReferenceQueue queue() {
return queue;
}
}
static public class G22ProjectInfo extends Concept {
static final public String _fieldOrder = "projectID projectDir historicalProjectDirs useFirefox";
final public String getProjectID() {
return projectID();
}
public String projectID() {
return projectID;
}
public String projectID = aGlobalID();
public File projectDir;
public List historicalProjectDirs = new ArrayList();
final public boolean getUseFirefox() {
return useFirefox();
}
public boolean useFirefox() {
return useFirefox;
}
public boolean useFirefox = false;
public void addHistoricalProjectDir(File dir) {
if (syncSetAdd(historicalProjectDirs, dir))
change();
}
}
public interface G22ProjectActions {
public void openObjectInProject(long id);
public void openPathInProject(String path);
public void editProjectStory();
public void editScripts();
}
static public class ImageSurface extends Surface {
public BufferedImage image;
public double zoomX = 1, zoomY = 1, zoomFactor = 1.5;
public Rectangle selection;
public List tools = new ArrayList();
public Object overlay;
public List overlays = syncL();
public Runnable onSelectionChange;
final public ImageSurface setVerbose(boolean verbose) {
return verbose(verbose);
}
public ImageSurface verbose(boolean verbose) {
this.verbose = verbose;
return this;
}
final public boolean getVerbose() {
return verbose();
}
public boolean verbose() {
return verbose;
}
public boolean verbose = false;
public boolean noMinimumSize = true;
public String titleForUpload;
public Object onZoom;
public boolean specialPurposed = false;
final public ImageSurface setAllowPaste(boolean allowPaste) {
return allowPaste(allowPaste);
}
public ImageSurface allowPaste(boolean allowPaste) {
this.allowPaste = allowPaste;
return this;
}
final public boolean getAllowPaste() {
return allowPaste();
}
public boolean allowPaste() {
return allowPaste;
}
public boolean allowPaste = false;
final public ImageSurface setZoomable(boolean zoomable) {
return zoomable(zoomable);
}
public ImageSurface zoomable(boolean zoomable) {
this.zoomable = zoomable;
return this;
}
final public boolean getZoomable() {
return zoomable();
}
public boolean zoomable() {
return zoomable;
}
public boolean zoomable = true;
public boolean noAlpha = false;
public Object interpolationMode = RenderingHints.VALUE_INTERPOLATION_BILINEAR;
public Object onNewImage;
public BufferedImage imageToDraw;
public File file;
public boolean autoZoomToDisplay = false;
final public ImageSurface setRepaintInThread(boolean repaintInThread) {
return repaintInThread(repaintInThread);
}
public ImageSurface repaintInThread(boolean repaintInThread) {
this.repaintInThread = repaintInThread;
return this;
}
final public boolean getRepaintInThread() {
return repaintInThread();
}
public boolean repaintInThread() {
return repaintInThread;
}
public boolean repaintInThread = false;
public BoolVar showingVar;
public Pt mousePosition;
transient public Set onMousePositionChanged;
public ImageSurface onMousePositionChanged(Runnable r) {
onMousePositionChanged = createOrAddToSyncLinkedHashSet(onMousePositionChanged, r);
return this;
}
public ImageSurface removeMousePositionChangedListener(Runnable r) {
main.remove(onMousePositionChanged, r);
return this;
}
public void mousePositionChanged() {
if (onMousePositionChanged != null)
for (var listener : onMousePositionChanged) pcallF_typed(listener);
}
transient public Set onImageChanged;
public ImageSurface onImageChanged(Runnable r) {
onImageChanged = createOrAddToSyncLinkedHashSet(onImageChanged, r);
return this;
}
public ImageSurface removeImageChangedListener(Runnable r) {
main.remove(onImageChanged, r);
return this;
}
public void imageChanged() {
if (onImageChanged != null)
for (var listener : onImageChanged) pcallF_typed(listener);
}
transient public Set> onUserModifiedImage;
public ImageSurface onUserModifiedImage(IVF1