Warning : session_start(): open(/var/lib/php/sessions/sess_jcod3sjmmin1l0br7s0u3qvhjp, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning : session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import java.util.function.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
import java.time.Duration;
import java.lang.invoke.VarHandle;
import java.lang.invoke.MethodHandles;
import static x30_pkg.x30_util.DynamicObject;
import javax.swing.Icon;
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 javax.swing.border.TitledBorder;
import java.util.jar.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.text.*;
import java.nio.file.Path;
import javax.swing.event.AncestorListener;
import javax.swing.event.AncestorEvent;
import javax.swing.Timer;
import org.fife.ui.rsyntaxtextarea.*;
import java.awt.datatransfer.StringSelection;
import javax.swing.border.*;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.awt.geom.*;
import javax.swing.undo.UndoManager;
import java.text.NumberFormat;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import java.text.SimpleDateFormat;
import java.nio.charset.Charset;
import java.util.TimeZone;
import java.awt.datatransfer.UnsupportedFlavorException;
public class main {
static public class JG22ProjectSelector implements Swingable, IFieldsToList {
public G22Utils g22utils;
public JG22ProjectSelector() {
}
public JG22ProjectSelector(G22Utils g22utils) {
this.g22utils = g22utils;
}
public Object[] _fieldsToList() {
return new Object[] { g22utils };
}
transient public JLabel lblDB;
public transient JComponent visualize_cache;
public JComponent visualize() {
if (visualize_cache == null)
visualize_cache = visualize_load();
return visualize_cache;
}
public JComponent visualize_load() {
return markVisualizer(this, visualize_impl());
}
public JComponent visualize_impl() {
lblDB = toolTip("Currently selected project (" + f2s(g22utils.projectDir()) + ")", (jSimpleLabel(fileName(g22utils.projectDir()))));
onClick(lblDB, evt -> new PopupMenuMaker(evt, menu -> {
addMenuItem(menu, "New project...", runnableThread(new Runnable() {
public void run() {
try {
g22utils.projectActions().databasesPanel().newDatabase();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "g22utils.projectActions().databasesPanel().newDatabase()";
}
}));
addMenuItem(menu, "Projects...", runnableThread(new Runnable() {
public void run() {
try {
g22utils.showUIURL("Projects");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "g22utils.showUIURL(\"Projects\")";
}
}));
List recent = takeFirst(10, g22utils.dbNamesRecentlyOpened());
for (File otherDB : g22utils.masterStuff().openConceptDirs()) {
String name = fileName(otherDB);
if (!eq(otherDB, g22utils.projectDir()))
addMenuItem(menu, name + " [Open]", runnableThread(new Runnable() {
public void run() {
try {
g22utils.masterStuff().openDatabase(otherDB);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "g22utils.masterStuff().openDatabase(otherDB)";
}
}));
removeAll(recent, name, "*" + name);
}
for (var name : recent) {
String name2 = dropStarPrefix(name);
File otherDB = newFile(g22utils.databasesMotherDir(), name2);
if (isDirectory(otherDB))
addMenuItem(menu, name2, runnableThread(new Runnable() {
public void run() {
try {
g22utils.masterStuff().openDatabase(otherDB, neq(name, name2));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "g22utils.masterStuff().openDatabase(otherDB, neq(name, name2))";
}
}));
}
}).run());
return lblDB;
}
}
static public A markVisualizer(Object visualizer, A a) {
return setMetaSrc(a, visualizer);
}
static public A toolTip(A c, final Object toolTip) {
return setToolTipText(c, toolTip);
}
static public A toolTip(Object toolTip, A c) {
return setToolTipText(toolTip, c);
}
static public String f2s(File f) {
return f == null ? null : f.getAbsolutePath();
}
static public String f2s(String s) {
return f2s(newFile(s));
}
static public String f2s(java.nio.file.Path p) {
return p == null ? null : f2s(p.toFile());
}
static public JLabel jSimpleLabel() {
return jSimpleLabel("");
}
static public JLabel jSimpleLabel(String text) {
return swing(() -> new JLabel(text));
}
static public String fileName(File f) {
return f == null ? null : f.getName();
}
static public A onClick(A c, IVF1 runnable) {
return onClick(c, (Object) runnable);
}
static public A onClick(A c, Object runnable) {
if (c != null) {
swing(() -> {
c.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
callF(runnable, e);
}
});
});
}
return c;
}
static public void onClick(JButton btn, Object runnable) {
onEnter(btn, runnable);
}
static public void addMenuItem(JPopupMenu menu, String text, Object action) {
menu.add(jmenuItem(text, action));
}
static public void addMenuItem(JPopupMenu menu, JMenuItem menuItem) {
if (menu != null && menuItem != null)
menu.add(menuItem);
}
static public void addMenuItem(JMenu menu, String text, Object action) {
menu.add(jmenuItem(text, action));
}
static public void addMenuItem(Menu menu, String text, Object action) {
menu.add(menuItem(text, action));
}
static public void addMenuItem(JMenu menu, JMenuItem menuItem) {
menu.add(menuItem);
}
static public void addMenuItem(JMenuBar menuBar, String text, Runnable action) {
addMenuItem(menuBar, jmenuItem(text, action));
}
static public void addMenuItem(JMenuBar menuBar, JMenuItem menuItem) {
addDirectMenuItem(menuBar, menuItem);
}
static public Runnable runnableThread(final Runnable r) {
return new Runnable() {
public void run() {
try {
startThread(r);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "startThread(r)";
}
};
}
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 List takeFirst(List l, int n) {
return l(l) <= n ? l : newSubListOrSame(l, 0, n);
}
static public List takeFirst(int n, List l) {
return takeFirst(l, n);
}
static public String takeFirst(int n, String s) {
return substring(s, 0, n);
}
static public String takeFirst(String s, int n) {
return substring(s, 0, n);
}
static public CharSequence takeFirst(int n, CharSequence s) {
return subCharSequence(s, 0, n);
}
static public List takeFirst(int n, Iterator it) {
if (it == null)
return null;
List l = new ArrayList();
for (int _repeat_0 = 0; _repeat_0 < n; _repeat_0++) {
if (it.hasNext())
l.add(it.next());
else
break;
}
return l;
}
static public List takeFirst(int n, Iterable i) {
if (i == null)
return null;
return i == null ? null : takeFirst(n, i.iterator());
}
static public List takeFirst(int n, IterableIterator i) {
return takeFirst(n, (Iterator ) i);
}
static public int[] takeFirst(int n, int[] a) {
return takeFirstOfIntArray(n, a);
}
static public short[] takeFirst(int n, short[] a) {
return takeFirstOfShortArray(n, a);
}
static public byte[] takeFirst(int n, byte[] a) {
return takeFirstOfByteArray(n, a);
}
static public byte[] takeFirst(byte[] a, int n) {
return takeFirstOfByteArray(n, a);
}
static public double[] takeFirst(int n, double[] a) {
return takeFirstOfDoubleArray(n, a);
}
static public double[] takeFirst(double[] a, int n) {
return takeFirstOfDoubleArray(n, a);
}
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 boolean removeAll(Collection a, Collection b) {
return a != null && b != null && a.removeAll(b);
}
static public void removeAll(Map a, Collection b) {
if (a != null && b != null)
for (A x : b) a.remove(x);
}
static public boolean removeAll(Collection c, B... b) {
return c != null && b != null && c.removeAll(Arrays.asList(b));
}
static public void removeAll(Map a, A... b) {
if (a != null && b != null)
for (A x : b) a.remove(x);
}
static public String dropStarPrefix(String s) {
return dropPrefix("*", s);
}
static public File newFile(File base, String... names) {
for (String name : names) base = new File(base, name);
return base;
}
static public File newFile(String name) {
return name == null ? null : new File(name);
}
static public File newFile(String base, String... names) {
return newFile(newFile(base), names);
}
static public boolean isDirectory(File f) {
return f != null && f.isDirectory();
}
static public boolean isDirectory(String path) {
return path != null && isDirectory(newFile(path));
}
static public boolean neq(Object a, Object b) {
return !eq(a, b);
}
static public A setMetaSrc(A a, Object src) {
setMetaAndVerify(a, "src", src);
return a;
}
static public A setMetaSrc(A a, Object src) {
setMetaAndVerify(a, "src", src);
return a;
}
static public A setToolTipText(final A c, final Object toolTip) {
if (c == null)
return null;
{
swing(() -> {
String s = str_nullIfEmpty(toolTip);
if (neq(s, c.getToolTipText()))
c.setToolTipText(s);
});
}
return c;
}
static public A setToolTipText(Object toolTip, A c) {
return setToolTipText(c, toolTip);
}
static public Object swing(Object f) {
return swingAndWait(f);
}
static public void swing(Runnable f) {
swingAndWait(f);
}
static public A swing(F0 f) {
return (A) swingAndWait(f);
}
static public A swing(IF0 f) {
return (A) swingAndWait(f);
}
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(F2 f, A a, B b) {
return f == null ? null : f.get(a, b);
}
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 JTextField onEnter(JTextField tf, JButton btn) {
if (btn != null)
onEnter(tf, new Runnable() {
public void run() {
try {
clickButton(btn);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "clickButton(btn)";
}
});
return tf;
}
static public JTextField onEnter(JTextField tf, Object action) {
if (action == null || tf == null)
return tf;
tf.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent _evt) {
try {
tf.selectAll();
callF(action);
} catch (Throwable __e) {
messageBox(__e);
}
}
});
return tf;
}
static public JButton onEnter(JButton btn, final Object action) {
if (action == null || btn == null)
return btn;
btn.addActionListener(actionListener(action));
return btn;
}
static public JList onEnter(JList list, Object action) {
list.addKeyListener(enterKeyListener(rCallOnSelectedListItem(list, action)));
return list;
}
static public JComboBox onEnter(final JComboBox cb, Runnable action) {
{
swing(() -> {
if (cb.isEditable()) {
JTextField text = (JTextField) cb.getEditor().getEditorComponent();
onEnter(text, action);
} else {
cb.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enter");
cb.getActionMap().put("enter", abstractAction("", new Runnable() {
public void run() {
try {
cb.hidePopup();
callF(action);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "cb.hidePopup(); callF(action);";
}
}));
}
});
}
return cb;
}
static public JTable onEnter(final JTable table, final Object action) {
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
table.getActionMap().put("Enter", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
callF(action, table.getSelectedRow());
}
});
return table;
}
static public JTextField onEnter(Runnable action, JTextField tf) {
return onEnter(tf, action);
}
static public boolean jmenuItem_newThreads = false;
static public JMenuItem jmenuItem(final String text) {
return jMenuItem(text, null);
}
static public JMenuItem jmenuItem(final String text, final Object r) {
return swing(new F0() {
public JMenuItem get() {
try {
Pair p = jmenu_autoMnemonic(dropPrefix("[disabled] ", text));
JMenuItem mi = new JMenuItem(p.a);
if (startsWith(text, "[disabled] "))
disableMenuItem(mi);
if (p.b != 0)
mi.setMnemonic(p.b);
mi.addActionListener(jmenuItem_newThreads ? actionListenerInNewThread(r) : actionListener(r));
return mi;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Pair p = jmenu_autoMnemonic(dropPrefix(\"[disabled] \", text));\r\n JM...";
}
});
}
static public MenuItem menuItem(String text, final Object r) {
MenuItem mi = new MenuItem(text);
mi.addActionListener(actionListener(r));
return mi;
}
static public void addDirectMenuItem(JMenuBar mb, String text, Object action) {
if (mb != null) {
swing(() -> {
addDirectMenuItem(mb, directJMenuItem(text, action));
});
}
}
static public void addDirectMenuItem(Component c, String text, Object action) {
addDirectMenuItem(addMenuBar(c), text, action);
}
static public void addDirectMenuItem(JMenuBar mb, JMenuItem menuItem) {
if (mb != null) {
swing(() -> {
mb.add(menuItem);
revalidate(mb);
});
}
}
static public Thread startThread(Object runnable) {
return startThread(defaultThreadName(), runnable);
}
static public Thread startThread(String name, Runnable runnable) {
runnable = wrapAsActivity(runnable);
return startThread(newThread(runnable, name));
}
static public Thread startThread(String name, Object runnable) {
runnable = wrapAsActivity(runnable);
return startThread(newThread(toRunnable(runnable), name));
}
static public Thread startThread(Thread t) {
_registerThread(t);
t.start();
return t;
}
static public void _handleError(Error e) {
}
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(IntBuffer b) {
return b == null ? 0 : b.size();
}
static public int l(IntSize o) {
return o == null ? 0 : o.size();
}
static public List newSubListOrSame(List l, int startIndex) {
return newSubListOrSame(l, startIndex, l(l));
}
static public List newSubListOrSame(List l, int startIndex, int endIndex) {
if (l == null)
return null;
int n = l(l);
startIndex = max(0, startIndex);
endIndex = min(n, endIndex);
if (startIndex >= endIndex)
return ll();
if (startIndex == 0 && endIndex == n)
return l;
return cloneList(l.subList(startIndex, endIndex));
}
static public List newSubListOrSame(List l, IntRange r) {
return newSubListOrSame(l, r.start, r.end);
}
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 CharSequence subCharSequence(CharSequence s, int x) {
return subCharSequence(s, x, s == null ? 0 : s.length());
}
static public CharSequence subCharSequence(CharSequence s, int x, int y) {
if (s == null)
return null;
if (x < 0)
x = 0;
if (x >= s.length())
return "";
if (y < x)
y = x;
if (y > s.length())
y = s.length();
return s.subSequence(x, y);
}
static public int[] takeFirstOfIntArray(int[] b, int n) {
return subIntArray(b, 0, n);
}
static public int[] takeFirstOfIntArray(int n, int[] b) {
return takeFirstOfIntArray(b, n);
}
static public short[] takeFirstOfShortArray(short[] b, int n) {
return subShortArray(b, 0, n);
}
static public short[] takeFirstOfShortArray(int n, short[] b) {
return takeFirstOfShortArray(b, n);
}
static public byte[] takeFirstOfByteArray(byte[] b, int n) {
return subByteArray(b, 0, n);
}
static public byte[] takeFirstOfByteArray(int n, byte[] b) {
return takeFirstOfByteArray(b, n);
}
static public double[] takeFirstOfDoubleArray(double[] b, int n) {
return subDoubleArray(b, 0, n);
}
static public double[] takeFirstOfDoubleArray(int n, double[] b) {
return takeFirstOfDoubleArray(b, n);
}
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 String dropPrefix(String prefix, String s) {
return s == null ? null : s.startsWith(prefix) ? s.substring(l(prefix)) : s;
}
static public void setMetaAndVerify(Object o, Object key, Object value) {
setMeta(o, key, value);
assertSame(() -> "setMeta failed (class: " + className(o) + ", key: " + key + ")", value, metaGet(o, key));
}
static public void setMetaAndVerify(IMeta o, Object key, Object value) {
setMeta(o, key, value);
assertSame(() -> "setMeta failed (class: " + className(o) + ", key: " + key + ")", value, metaGet(o, key));
}
static public String str_nullIfEmpty(Object o) {
return nullIfEmpty(strOrNull(o));
}
static public void swingAndWait(Runnable r) {
try {
if (isAWTThread())
r.run();
else
EventQueue.invokeAndWait(addThreadInfoToRunnable(r));
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Object swingAndWait(final Object f) {
if (isAWTThread())
return callF(f);
else {
final Var result = new Var();
swingAndWait(new Runnable() {
public void run() {
try {
result.set(callF(f));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "result.set(callF(f));";
}
});
return result.get();
}
}
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 String getClassName(Object o) {
return o == null ? "null" : o instanceof Class ? ((Class) o).getName() : o.getClass().getName();
}
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 public void clickButton(final JButton b) {
if (b != null) {
swing(() -> {
if (b.isEnabled())
b.doClick();
});
}
}
static public void messageBox(final String msg) {
print(msg);
{
swing(() -> {
JOptionPane.showMessageDialog(null, msg, "JavaX", JOptionPane.INFORMATION_MESSAGE);
});
}
}
static public void messageBox(Throwable e) {
printStackTrace(e);
messageBox(hideCredentials(innerException2(e)));
}
static public ActionListener actionListener(final Object runnable) {
return actionListener(runnable, null);
}
static public ActionListener actionListener(final Object runnable, final Object instanceToHold) {
if (runnable instanceof ActionListener)
return (ActionListener) runnable;
final Object info = _threadInfo();
return new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent _evt) {
try {
_threadInheritInfo(info);
AutoCloseable __1 = holdInstance(instanceToHold);
try {
pcallF(runnable);
} finally {
_close(__1);
}
} catch (Throwable __e) {
messageBox(__e);
}
}
};
}
static public KeyListener enterKeyListener(final Object action) {
return new KeyAdapter() {
public void keyPressed(KeyEvent ke) {
if (ke.getKeyCode() == KeyEvent.VK_ENTER)
pcallF(action);
}
};
}
static public Runnable rCallOnSelectedListItem(final JList list, final Object action) {
return new Runnable() {
public void run() {
try {
pcallF(action, getSelectedItem(list));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "pcallF(action, getSelectedItem(list))";
}
};
}
static public AbstractAction abstractAction(String name, final Object runnable) {
return new AbstractAction(name) {
public void actionPerformed(ActionEvent evt) {
pcallF(runnable);
}
};
}
static public JMenuItem jMenuItem(final String text) {
return jmenuItem(text);
}
static public JMenuItem jMenuItem(String text, Object r) {
return jmenuItem(text, r);
}
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 Pair jmenu_autoMnemonic(String s) {
int i = indexOf(s, '&');
if (i >= 0 && i < l(s) && isLetterOrDigit(s.charAt(i + 1)))
return pair(substring(s, 0, i) + substring(s, i + 1), (int) s.charAt(i + 1));
return pair(s, 0);
}
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 JMenuItem disableMenuItem(final JMenuItem mi) {
if (mi != null) {
swing(() -> {
mi.setEnabled(false);
});
}
return mi;
}
static public ActionListener actionListenerInNewThread(final Object runnable) {
return actionListenerInNewThread(runnable, null);
}
static public ActionListener actionListenerInNewThread(final Object runnable, final Object instanceToHold) {
if (runnable instanceof ActionListener)
return (ActionListener) runnable;
return new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent _evt) {
try {
startThread("Action Listener", new Runnable() {
public void run() {
try {
AutoCloseable __1 = holdInstance(instanceToHold);
try {
callF(runnable);
} finally {
_close(__1);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "AutoCloseable __1 = holdInstance(instanceToHold); try {\r\n callF(runnable...";
}
});
} catch (Throwable __e) {
messageBox(__e);
}
}
};
}
static public JMenuItem directJMenuItem(Action a) {
return new JMenuItem(a) {
public Dimension getMaximumSize() {
return new Dimension(super.getPreferredSize().width, super.getMaximumSize().height);
}
};
}
static public JMenuItem directJMenuItem(String text, Object action) {
return directJMenuItem(abstractAction(text, action));
}
static public JMenuBar addMenuBar(final Component c) {
return swing(new F0() {
public JMenuBar get() {
try {
RootPaneContainer f = getPossiblyInternalFrame(c);
if (f == null)
return null;
JMenuBar bar = (JMenuBar) (call(f, "getJMenuBar"));
if (bar == null) {
setMenuBar(f, bar = new JMenuBar());
revalidate((Component) f);
}
return bar;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "RootPaneContainer f = getPossiblyInternalFrame(c);\r\n if (f == null) null;\r...";
}
});
}
static public A revalidate(final A c) {
if (c == null || !c.isShowing())
return c;
{
swing(() -> {
c.revalidate();
c.repaint();
});
}
return c;
}
static public void revalidate(JFrame f) {
revalidate((Component) f);
}
static public void revalidate(JInternalFrame f) {
revalidate((Component) f);
}
static public String defaultThreadName_name;
static public String defaultThreadName() {
if (defaultThreadName_name == null)
defaultThreadName_name = "A thread by " + programID();
return defaultThreadName_name;
}
static public Runnable wrapAsActivity(Object r) {
if (r == null)
return null;
Runnable r2 = toRunnable(r);
Object mod = dm_current_generic();
if (mod == null)
return r2;
return new Runnable() {
public void run() {
try {
AutoCloseable c = (AutoCloseable) (rcall("enter", mod));
AutoCloseable __1 = c;
try {
r2.run();
} finally {
_close(__1);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "AutoCloseable c = (AutoCloseable) (rcall enter(mod));\r\n temp c;\r\n r2.r...";
}
};
}
static public Thread newThread(Object runnable) {
return new BetterThread(_topLevelErrorHandling(toRunnable(runnable)));
}
static public Thread newThread(Object runnable, String name) {
if (name == null)
name = defaultThreadName();
return new BetterThread(_topLevelErrorHandling(toRunnable(runnable)), name);
}
static public Thread newThread(String name, Object runnable) {
return newThread(runnable, name);
}
static public Runnable toRunnable(final Object o) {
if (o == null)
return null;
if (o instanceof Runnable)
return (Runnable) o;
if (o instanceof String)
throw fail("callF_legacy");
return new Runnable() {
public void run() {
try {
callF(o);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(o)";
}
};
}
static public Map _registerThread_threads;
static public Object _onRegisterThread;
static public Thread _registerThread(Thread t) {
if (_registerThread_threads == null)
_registerThread_threads = newWeakHashMap();
_registerThread_threads.put(t, true);
vm_generalWeakSubMap("thread2mc").put(t, weakRef(mc()));
callF(_onRegisterThread, t);
return t;
}
static public void _registerThread() {
_registerThread(Thread.currentThread());
}
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 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 min(int a, int b) {
return Math.min(a, b);
}
static public long min(long a, long b) {
return Math.min(a, b);
}
static public float min(float a, float b) {
return Math.min(a, b);
}
static public float min(float a, float b, float c) {
return min(min(a, b), c);
}
static public double min(double a, double b) {
return Math.min(a, b);
}
static public double min(double[] c) {
double x = Double.MAX_VALUE;
for (double d : c) x = Math.min(x, d);
return x;
}
static public float min(float[] c) {
float x = Float.MAX_VALUE;
for (float d : c) x = Math.min(x, d);
return x;
}
static public byte min(byte[] c) {
byte x = 127;
for (byte d : c) if (d < x)
x = d;
return x;
}
static public short min(short[] c) {
short x = 0x7FFF;
for (short d : c) if (d < x)
x = d;
return x;
}
static public int min(int[] c) {
int x = Integer.MAX_VALUE;
for (int d : c) if (d < x)
x = d;
return x;
}
static public List ll(A... a) {
ArrayList l = new ArrayList(a.length);
if (a != null)
for (A x : a) l.add(x);
return l;
}
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 int strL(String s) {
return s == null ? 0 : s.length();
}
static public int lCharSequence(CharSequence s) {
return s == null ? 0 : s.length();
}
static public int[] subIntArray(int[] b, int start) {
return subIntArray(b, start, l(b));
}
static public int[] subIntArray(int[] b, int start, int end) {
start = max(start, 0);
end = min(end, l(b));
if (start == 0 && end == l(b))
return b;
if (start >= end)
return new int[0];
int[] x = new int[end - start];
System.arraycopy(b, start, x, 0, end - start);
return x;
}
static public int[] subIntArray(int[] a, IntRange r) {
return r == null ? null : subIntArray(a, r.start, r.end);
}
static public short[] subShortArray(short[] b, int start, int end) {
start = max(start, 0);
end = min(end, l(b));
if (start == 0 && end == l(b))
return b;
if (start >= end)
return new short[0];
short[] x = new short[end - start];
System.arraycopy(b, start, x, 0, end - start);
return x;
}
static public byte[] subByteArray(byte[] b, int start) {
return subByteArray(b, start, l(b));
}
static public byte[] subByteArray(byte[] b, int start, int end) {
start = max(start, 0);
end = min(end, l(b));
if (start == 0 && end == l(b))
return b;
if (start >= end)
return new byte[0];
byte[] x = new byte[end - start];
System.arraycopy(b, start, x, 0, end - start);
return x;
}
static public byte[] subByteArray(byte[] b, IntRange r) {
return r == null ? null : subByteArray(b, r.start, r.end);
}
static public double[] subDoubleArray(double[] b, int start) {
return subDoubleArray(b, start, l(b));
}
static public double[] subDoubleArray(double[] b, int start, int end) {
start = max(start, 0);
end = min(end, l(b));
if (start == 0 && end == l(b))
return b;
if (start >= end)
return new double[0];
double[] x = new double[end - start];
System.arraycopy(b, start, x, 0, end - start);
return x;
}
static public void setMeta(IMeta o, Object key, Object value) {
metaMapPut(o, key, value);
}
static public void setMeta(Object o, Object key, Object value) {
metaMapPut(o, key, value);
}
static public void assertSame(Object a, Object b) {
assertSame("", a, b);
}
static public void assertSame(String msg, Object a, Object b) {
if (a != b)
throw fail(joinNemptiesWithColon(msg, a + " != " + b + " (" + identityHash(a) + "/" + identityHash(b) + ")"));
}
static public void assertSame(IF0 msg, Object a, Object b) {
if (a != b)
throw fail(joinNemptiesWithColon(msg.get(), a + " != " + b + " (" + identityHash(a) + "/" + identityHash(b) + ")"));
}
static public String className(Object o) {
return getClassName(o);
}
static public Object metaGet(IMeta o, Object key) {
return metaMapGet(o, key);
}
static public Object metaGet(Object o, Object key) {
return metaMapGet(o, key);
}
static public Object metaGet(String key, IMeta o) {
return metaMapGet(o, key);
}
static public Object metaGet(String key, Object o) {
return metaMapGet(o, key);
}
static public String nullIfEmpty(String s) {
return isEmpty(s) ? null : s;
}
static public Map nullIfEmpty(Map map) {
return isEmpty(map) ? null : map;
}
static public List nullIfEmpty(List l) {
return isEmpty(l) ? null : l;
}
static public String strOrNull(Object o) {
return o == null ? null : str(o);
}
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 Runnable addThreadInfoToRunnable(final Object r) {
final Object info = _threadInfo();
return info == null ? asRunnable(r) : new Runnable() {
public void run() {
try {
_inheritThreadInfo(info);
callF(r);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "_inheritThreadInfo(info); callF(r);";
}
};
}
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(Object... c) {
return join(" ", c);
}
static public List classNames(Collection l) {
return getClassNames(l);
}
static public List classNames(Object[] l) {
return getClassNames(asList(l));
}
static volatile public StringBuffer local_log = new StringBuffer();
static public boolean printAlsoToSystemOut = true;
static volatile public Appendable print_log = local_log;
static volatile public int print_log_max = 1024 * 1024;
static volatile public int local_log_max = 100 * 1024;
static public boolean print_silent = false;
static public Object print_byThread_lock = new Object();
static volatile public ThreadLocal print_byThread;
static volatile public Object print_allThreads;
static volatile public Object print_preprocess;
static public void print() {
print("");
}
static public A print(String s, A o) {
print(combinePrintParameters(s, o));
return o;
}
static public A print(A o) {
ping_okInCleanUp();
if (print_silent)
return o;
String s = o + "\n";
print_noNewLine(s);
return o;
}
static public void print_noNewLine(String s) {
try {
Object f = getThreadLocal(print_byThread_dontCreate());
if (f == null)
f = print_allThreads;
if (f != null)
if (isFalse(f instanceof F1 ? ((F1) f).get(s) : callF(f, s)))
return;
} catch (Throwable e) {
System.out.println(getStackTrace(e));
}
print_raw(s);
}
static public void print_raw(String s) {
if (print_preprocess != null)
s = (String) callF(print_preprocess, s);
s = fixNewLines(s);
Appendable loc = local_log;
Appendable buf = print_log;
int loc_max = print_log_max;
if (buf != loc && buf != null) {
print_append(buf, s, print_log_max);
loc_max = local_log_max;
}
if (loc != null)
print_append(loc, s, loc_max);
if (printAlsoToSystemOut)
System.out.print(s);
vmBus_send("printed", mc(), s);
}
static public void print_autoRotate() {
}
static public boolean isInstanceX(Class type, Object arg) {
if (type == boolean.class)
return arg instanceof Boolean;
if (type == int.class)
return arg instanceof Integer;
if (type == long.class)
return arg instanceof Long;
if (type == float.class)
return arg instanceof Float;
if (type == short.class)
return arg instanceof Short;
if (type == char.class)
return arg instanceof Character;
if (type == byte.class)
return arg instanceof Byte;
if (type == double.class)
return arg instanceof Double;
return type.isInstance(arg);
}
static public 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 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 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 Throwable innerException2(Throwable e) {
if (e == null)
return null;
while (empty(e.getMessage()) && e.getCause() != null) e = e.getCause();
return e;
}
static public List> _threadInfo_makers = synchroList();
static public Object _threadInfo() {
if (empty(_threadInfo_makers))
return null;
HashMap map = new HashMap();
pcallFAll(_threadInfo_makers, map);
return map;
}
static public List> _threadInheritInfo_retrievers = synchroList();
static public void _threadInheritInfo(Object info) {
if (info == null)
return;
pcallFAll(_threadInheritInfo_retrievers, (Map) info);
}
static public ThreadLocal> holdInstance_l = new ThreadLocal();
static public AutoCloseable holdInstance(Object o) {
if (o == null)
return null;
listThreadLocalAdd(holdInstance_l, o);
return new AutoCloseable() {
public void close() {
listThreadLocalPopLast(holdInstance_l);
}
};
}
static public Object pcallF(Object f, Object... args) {
return pcallFunction(f, args);
}
static public A pcallF(F0 f) {
try {
return f == null ? null : f.get();
} catch (Throwable __e) {
printStackTrace(__e);
}
return null;
}
static public B pcallF(F1 f, A a) {
try {
return f == null ? null : f.get(a);
} catch (Throwable __e) {
printStackTrace(__e);
}
return null;
}
static public void pcallF(VF1 f, A a) {
try {
{
if (f != null)
f.get(a);
}
} catch (Throwable __e) {
printStackTrace(__e);
}
}
static public Object pcallF(Runnable r) {
try {
{
if (r != null)
r.run();
}
} catch (Throwable __e) {
printStackTrace(__e);
}
return null;
}
static public A pcallF(IF0 f) {
try {
return f == null ? null : f.get();
} catch (Throwable __e) {
printStackTrace(__e);
}
return null;
}
static public B pcallF(IF1 f, A a) {
try {
return f == null ? null : f.get(a);
} catch (Throwable __e) {
printStackTrace(__e);
}
return null;
}
static public void _close(AutoCloseable c) {
if (c != null)
try {
c.close();
} catch (Throwable e) {
if (c instanceof javax.imageio.stream.ImageOutputStream)
return;
else
throw rethrow(e);
}
}
static public String getSelectedItem(JList l) {
return (String) l.getSelectedValue();
}
static public String getSelectedItem(JComboBox cb) {
return strOrNull(cb.getSelectedItem());
}
static public Field getOpt_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
return null;
}
static public Object getOptDynOnly(DynamicObject o, String field) {
if (o == null || o.fieldValues == null)
return null;
return o.fieldValues.get(field);
}
static public 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 boolean isLetterOrDigit(char c) {
return Character.isLetterOrDigit(c);
}
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 String unnull(String s) {
return s == null ? "" : s;
}
static public Collection unnull(Collection l) {
return l == null ? emptyList() : l;
}
static public List unnull(List l) {
return l == null ? emptyList() : l;
}
static public int[] unnull(int[] l) {
return l == null ? emptyIntArray() : l;
}
static public char[] unnull(char[] l) {
return l == null ? emptyCharArray() : l;
}
static public double[] unnull(double[] l) {
return l == null ? emptyDoubleArray() : l;
}
static public Map unnull(Map l) {
return l == null ? emptyMap() : l;
}
static public Iterable unnull(Iterable i) {
return i == null ? emptyList() : i;
}
static public A[] unnull(A[] a) {
return a == null ? (A[]) emptyObjectArray() : a;
}
static public BitSet unnull(BitSet b) {
return b == null ? new BitSet() : b;
}
static public Pt unnull(Pt p) {
return p == null ? new Pt() : p;
}
static public Symbol unnull(Symbol s) {
return s == null ? emptySymbol() : s;
}
static public Pair unnull(Pair p) {
return p != null ? p : new Pair(null, null);
}
static public int unnull(Integer i) {
return i == null ? 0 : i;
}
static public long unnull(Long l) {
return l == null ? 0L : l;
}
static public double unnull(Double l) {
return l == null ? 0.0 : l;
}
static public boolean nemptyString(String s) {
return s != null && s.length() > 0;
}
static public int listL(Collection l) {
return l == null ? 0 : l.size();
}
static public RootPaneContainer getPossiblyInternalFrame(Component c) {
JInternalFrame f = getInternalFrame(c);
if (f != null)
return f;
return optCast(RootPaneContainer.class, getWindow(c));
}
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 void setMenuBar(final JMenuBar mb, final RootPaneContainer f) {
{
swing(() -> {
call(f, "setJMenuBar", mb);
revalidate((Component) f);
});
}
}
static public void setMenuBar(RootPaneContainer f, JMenuBar mb) {
setMenuBar(mb, f);
}
static public String programID() {
return getProgramID();
}
static public String programID(Object o) {
return getProgramID(o);
}
static public Object dm_current_generic() {
return getWeakRef(dm_current_generic_tl().get());
}
static public Object rcall(String method, Object o, Object... args) {
return call_withVarargs(o, method, args);
}
static public Runnable _topLevelErrorHandling(Runnable r) {
if (r == null)
return null;
Object info = _threadInfo();
Object mod = dm_current_generic();
Runnable r2 = r;
if (info != null || mod == null)
r2 = new Runnable() {
public void run() {
try {
AutoCloseable __1 = (AutoCloseable) (rcall("enter", mod));
try {
_threadInheritInfo(info);
r.run();
} finally {
_close(__1);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "temp (AutoCloseable) rcall enter(mod);\r\n _threadInheritInfo(info);\r\n ...";
}
};
r2 = rPcall(r2);
return r2;
}
static public Map newWeakHashMap() {
return _registerWeakMap(synchroMap(new WeakHashMap()));
}
static public Map vm_generalWeakSubMap(Object name) {
synchronized (vm_generalMap()) {
Map map = (Map) (vm_generalMap_get(name));
if (map == null)
vm_generalMap_put(name, map = newWeakMap());
return map;
}
}
static public WeakReference weakRef(A a) {
return newWeakReference(a);
}
static public Class mc() {
return main.class;
}
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 ArrayList asList(A[] a) {
return a == null ? new ArrayList () : new ArrayList (Arrays.asList(a));
}
static public ArrayList asList(byte[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (var i : a) l.add(i);
return l;
}
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 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 AutoCloseable tempInterceptPrintIfNotIntercepted(F1 f) {
return print_byThread().get() == null ? tempInterceptPrint(f) : null;
}
static public void metaMapPut(IMeta o, Object key, Object value) {
{
if (o != null)
o.metaPut(key, value);
}
}
static public void metaMapPut(Object o, Object key, Object value) {
var meta = initIMeta(o);
{
if (meta != null)
meta.metaPut(key, value);
}
}
static public String joinNemptiesWithColon(String... strings) {
return joinNempties(": ", strings);
}
static public String joinNemptiesWithColon(Collection strings) {
return joinNempties(": ", strings);
}
static public int identityHash(Object o) {
return identityHashCode(o);
}
static public Object metaMapGet(IMeta o, Object key) {
return o == null ? null : o.metaGet(key);
}
static public Object metaMapGet(Object o, Object key) {
return metaMapGet(toIMeta(o), key);
}
static public boolean isEmpty(Collection c) {
return c == null || c.isEmpty();
}
static public boolean isEmpty(CharSequence s) {
return s == null || s.length() == 0;
}
static public boolean isEmpty(Object[] a) {
return a == null || a.length == 0;
}
static public boolean isEmpty(byte[] a) {
return a == null || a.length == 0;
}
static public boolean isEmpty(Map map) {
return map == null || map.isEmpty();
}
static public boolean isEmpty(AppendableChain c) {
return c == null;
}
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 Runnable asRunnable(Object o) {
return toRunnable(o);
}
static public void _inheritThreadInfo(Object info) {
_threadInheritInfo(info);
}
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 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 String combinePrintParameters(String s, Object o) {
return (endsWithLetterOrDigit(s) ? s + ": " : s) + o;
}
static public void ping_okInCleanUp() {
if (ping_pauseAll || ping_anyActions)
ping_impl(true);
}
static public Object getThreadLocal(Object o, String name) {
ThreadLocal t = (ThreadLocal) (getOpt(o, name));
return t != null ? t.get() : null;
}
static public A getThreadLocal(ThreadLocal tl) {
return tl == null ? null : tl.get();
}
static public A getThreadLocal(ThreadLocal tl, A defaultValue) {
return or(getThreadLocal(tl), defaultValue);
}
static public ThreadLocal print_byThread_dontCreate() {
return print_byThread;
}
static public boolean isFalse(Object o) {
return eq(false, o);
}
static public String getStackTrace(Throwable throwable) {
lastException(throwable);
return getStackTrace_noRecord(throwable);
}
static public String getStackTrace_noRecord(Throwable throwable) {
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
return hideCredentials(writer.toString());
}
static public String getStackTrace() {
return getStackTrace_noRecord(new Throwable());
}
static public String getStackTrace(String msg) {
return getStackTrace_noRecord(new Throwable(msg));
}
static public String fixNewLines(String s) {
int i = indexOf(s, '\r');
if (i < 0)
return s;
int l = s.length();
StringBuilder out = new StringBuilder(l);
out.append(s, 0, i);
for (; i < l; i++) {
char c = s.charAt(i);
if (c != '\r')
out.append(c);
else {
out.append('\n');
if (i + 1 < l && s.charAt(i + 1) == '\n')
++i;
}
}
return out.toString();
}
static public void print_append(Appendable buf, String s, int max) {
try {
synchronized (buf) {
buf.append(s);
if (buf instanceof StringBuffer)
rotateStringBuffer(((StringBuffer) buf), max);
else if (buf instanceof StringBuilder)
rotateStringBuilder(((StringBuilder) buf), max);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Object vmBus_wrapArgs(Object... args) {
return empty(args) ? null : l(args) == 1 ? args[0] : args;
}
static public void pcallFAll_minimalExceptionHandling(Collection l, Object... args) {
if (l != null)
for (Object f : cloneList(l)) {
ping();
pcallF_minimalExceptionHandling(f, args);
}
}
static public void pcallFAll_minimalExceptionHandling(Iterator it, Object... args) {
while (it.hasNext()) {
ping();
pcallF_minimalExceptionHandling(it.next(), args);
}
}
static public Set vm_busListeners_live_cache;
static public Set vm_busListeners_live() {
if (vm_busListeners_live_cache == null)
vm_busListeners_live_cache = vm_busListeners_live_load();
return vm_busListeners_live_cache;
}
static public Set vm_busListeners_live_load() {
return vm_generalIdentityHashSet("busListeners");
}
static public Map vm_busListenersByMessage_live_cache;
static public Map vm_busListenersByMessage_live() {
if (vm_busListenersByMessage_live_cache == null)
vm_busListenersByMessage_live_cache = vm_busListenersByMessage_live_load();
return vm_busListenersByMessage_live_cache;
}
static public Map vm_busListenersByMessage_live_load() {
return vm_generalHashMap("busListenersByMessage");
}
static public boolean 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 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(IntBuffer b) {
return b == null || b.isEmpty();
}
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 void pcallFAll(Collection l, Object... args) {
if (l != null)
for (Object f : cloneList(l)) pcallF(f, args);
}
static public void pcallFAll(Iterator it, Object... args) {
while (it.hasNext()) pcallF(it.next(), args);
}
static public void listThreadLocalAdd(ThreadLocal> tl, A a) {
List l = tl.get();
if (l == null)
tl.set(l = new ArrayList());
l.add(a);
}
static public A listThreadLocalPopLast(ThreadLocal> tl) {
List l = tl.get();
if (l == null)
return null;
A a = popLast(l);
if (empty(l))
tl.set(null);
return a;
}
static public Object pcallFunction(Object f, Object... args) {
try {
return callFunction(f, args);
} catch (Throwable __e) {
printStackTrace(__e);
}
return null;
}
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 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 JInternalFrame getInternalFrame(final Object _o) {
return _o == null ? null : swing(new F0() {
public JInternalFrame get() {
try {
Object o = _o;
if (o instanceof ButtonGroup)
o = first(buttonsInGroup((ButtonGroup) o));
if (!(o instanceof Component))
return null;
Component c = (Component) o;
while (c != null) {
if (c instanceof JInternalFrame)
return (JInternalFrame) c;
c = c.getParent();
}
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "O o = _o;\r\n if (o instanceof ButtonGroup) o = first(buttonsInGroup((Button...";
}
});
}
static public A optCast(Class c, Object o) {
return isInstance(c, o) ? (A) o : null;
}
static public Window getWindow(Object o) {
if (!(o instanceof Component))
return null;
return swing(() -> {
Component c = (Component) o;
while (c != null) {
if (c instanceof Window)
return ((Window) c);
c = c.getParent();
}
return null;
});
}
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 String programID;
static public String getProgramID() {
return nempty(programID) ? formatSnippetIDOpt(programID) : "?";
}
static public String getProgramID(Class c) {
String id = (String) getOpt(c, "programID");
if (nempty(id))
return formatSnippetID(id);
return "?";
}
static public String getProgramID(Object o) {
return getProgramID(getMainClass(o));
}
static public A getWeakRef(Reference ref) {
return ref == null ? null : ref.get();
}
static public x30_pkg.x30_util.BetterThreadLocal dm_current_generic_tl;
static public x30_pkg.x30_util.BetterThreadLocal dm_current_generic_tl() {
if (dm_current_generic_tl == null)
dm_current_generic_tl = vm_generalMap_getOrCreate("currentModule", () -> new x30_pkg.x30_util.BetterThreadLocal());
return dm_current_generic_tl;
}
static public Runnable rPcall(Runnable r) {
return r == null ? null : () -> {
try {
r.run();
} catch (Throwable __e) {
printStackTrace(__e);
}
};
}
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 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 Map newWeakMap() {
return newWeakHashMap();
}
static public WeakReference newWeakReference(A a) {
return a == null ? null : new WeakReference(a);
}
static public Iterator emptyIterator() {
return Collections.emptyIterator();
}
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 IMeta initIMeta(Object o) {
if (o == null)
return null;
if (o instanceof IMeta)
return ((IMeta) o);
if (o instanceof JComponent)
return initMetaOfJComponent((JComponent) o);
if (o instanceof BufferedImage)
return optCast(IMeta.class, ((BufferedImage) o).getProperty("meta"));
return null;
}
static public String joinNempties(String sep, Object... strings) {
return joinStrings(sep, strings);
}
static public String joinNempties(String sep, Iterable strings) {
return joinStrings(sep, strings);
}
static public int identityHashCode(Object o) {
return System.identityHashCode(o);
}
static public IMeta toIMeta(Object o) {
return initIMeta(o);
}
static public String joinWithComma(Collection c) {
return join(", ", c);
}
static public String joinWithComma(Object... c) {
return join(", ", c);
}
static public String joinWithComma(String... c) {
return join(", ", c);
}
static public String joinWithComma(Pair p) {
return p == null ? "" : joinWithComma(str(p.a), str(p.b));
}
static public List 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 void assertTrue(Object o) {
if (!(eq(o, true)))
throw fail(str(o));
}
static public boolean assertTrue(String msg, boolean b) {
if (!b)
throw fail(msg);
return b;
}
static public boolean assertTrue(boolean b) {
if (!b)
throw fail("oops");
return b;
}
static public Map synchronizedMap() {
return synchroMap();
}
static public Map synchronizedMap(Map map) {
return synchroMap(map);
}
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 int first(IntBuffer buf) {
return buf.get(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 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 volatile public PersistableThrowable lastException_lastException;
static public PersistableThrowable lastException() {
return lastException_lastException;
}
static public void lastException(Throwable e) {
lastException_lastException = persistableThrowable(e);
}
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 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 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 A popLast(List l) {
return liftLast(l);
}
static public List popLast(int n, List l) {
return liftLast(n, l);
}
static public Object callFunction(Object f, Object... args) {
return callF(f, args);
}
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 List buttonsInGroup(ButtonGroup g) {
if (g == null)
return ll();
return asList(g.getElements());
}
static public boolean isInstance(Class type, Object arg) {
return type.isInstance(arg);
}
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 boolean nempty(Collection c) {
return !empty(c);
}
static public boolean nempty(CharSequence s) {
return !empty(s);
}
static public boolean nempty(Object[] o) {
return !empty(o);
}
static public boolean nempty(byte[] o) {
return !empty(o);
}
static public boolean nempty(int[] o) {
return !empty(o);
}
static public boolean nempty(BitSet bs) {
return !empty(bs);
}
static public boolean nempty(Map m) {
return !empty(m);
}
static public boolean nempty(Iterator i) {
return i != null && i.hasNext();
}
static public boolean nempty(IMultiMap mm) {
return mm != null && mm.size() != 0;
}
static public boolean nempty(Object o) {
return !empty(o);
}
static public boolean nempty(IntRange r) {
return !empty(r);
}
static public boolean nempty(IntBuffer b) {
return b != null && !b.isEmpty();
}
static public boolean nempty(Rect r) {
return r != null && r.w != 0 && r.h != 0;
}
static public boolean nempty(MultiSet ms) {
return ms != null && !ms.isEmpty();
}
static public String formatSnippetIDOpt(String s) {
return isSnippetID(s) ? formatSnippetID(s) : s;
}
static public String formatSnippetID(String id) {
return "#" + parseSnippetID(id);
}
static public String formatSnippetID(long id) {
return "#" + id;
}
static public Class getMainClass() {
return mc();
}
static public Class getMainClass(Object o) {
try {
if (o == null)
return null;
if (o instanceof Class && eq(((Class) o).getName(), "x30"))
return (Class) o;
ClassLoader cl = (o instanceof Class ? (Class) o : o.getClass()).getClassLoader();
if (cl == null)
return null;
String name = mainClassNameForClassLoader(cl);
return loadClassFromClassLoader_orNull(cl, name);
} catch (Exception __e) {
throw rethrow(__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 printException(A e) {
printStackTrace(e);
return e;
}
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 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 IMeta initMetaOfJComponent(JComponent c) {
if (c == null)
return null;
IMeta meta = (IMeta) (c.getClientProperty(IMeta.class));
if (meta == null)
c.putClientProperty(IMeta.class, meta = new Meta());
return meta;
}
static public String joinStrings(String sep, Object... strings) {
return joinStrings(sep, Arrays.asList(strings));
}
static public String joinStrings(String sep, Iterable strings) {
StringBuilder buf = new StringBuilder();
for (Object o : unnull(strings)) {
String s = strOrNull(o);
if (nempty(s)) {
if (nempty(buf))
buf.append(sep);
buf.append(s);
}
}
return str(buf);
}
static public Class> _getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
return null;
}
}
static public Class _getClass(Object o) {
return o == null ? null : o instanceof Class ? (Class) o : o.getClass();
}
static public Class _getClass(Object realm, String name) {
try {
return classLoaderForObject(realm).loadClass(classNameToVM(name));
} catch (ClassNotFoundException e) {
return null;
}
}
static public void _onJavaXSet() {
}
static public 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 void newPing() {
var tl = newPing_actionTL();
Runnable action = tl == null ? null : tl.get();
{
if (action != null)
action.run();
}
}
static public boolean isTrue(Object o) {
if (o instanceof Boolean)
return ((Boolean) o).booleanValue();
if (o == null)
return false;
if (o instanceof ThreadLocal)
return isTrue(((ThreadLocal) o).get());
throw fail(getClassName(o));
}
static public boolean isTrue(Boolean b) {
return b != null && b.booleanValue();
}
static public void failIfUnlicensed() {
assertTrue("license off", licensed());
}
static public Thread currentThread() {
return Thread.currentThread();
}
static public 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 PersistableThrowable persistableThrowable(Throwable e) {
return e == null ? null : new PersistableThrowable(e);
}
static public Throwable _storeException_value;
static public void _storeException(Throwable e) {
_storeException_value = e;
}
static public Set syncIdentityHashSet() {
return (Set) synchronizedSet(identityHashSet());
}
static public Map syncHashMap() {
return synchroHashMap();
}
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 liftLast(List l) {
if (empty(l))
return null;
int i = l(l) - 1;
A a = l.get(i);
l.remove(i);
return a;
}
static public List liftLast(int n, List l) {
int i = l(l) - n;
List part = cloneSubList(l, i);
removeSubList(l, i);
return part;
}
static public boolean methodIsStatic(Method m) {
return (m.getModifiers() & Modifier.STATIC) != 0;
}
static public boolean argumentCompatibleWithType(Object arg, Class type) {
return arg == null ? !type.isPrimitive() : isInstanceX(type, arg);
}
static public void arraycopy(Object[] a, Object[] b) {
if (a != null && b != null)
arraycopy(a, 0, b, 0, Math.min(a.length, b.length));
}
static public void arraycopy(Object src, int srcPos, int destPos, int n) {
arraycopy(src, srcPos, src, destPos, n);
}
static public void arraycopy(Object src, int srcPos, Object dest, int destPos, int n) {
if (n != 0)
System.arraycopy(src, srcPos, dest, destPos, n);
}
public static boolean isSnippetID(String s) {
try {
parseSnippetID(s);
return true;
} catch (RuntimeException e) {
return false;
}
}
public static long parseSnippetID(String snippetID) {
long id = Long.parseLong(shortenSnippetID(snippetID));
if (id == 0)
throw fail("0 is not a snippet ID");
return id;
}
static public String mainClassNameForClassLoader(ClassLoader cl) {
return or((String) callOpt(cl, "mainClassName"), "main");
}
static public Class loadClassFromClassLoader_orNull(ClassLoader cl, String name) {
try {
return cl == null ? null : cl.loadClass(name);
} catch (ClassNotFoundException e) {
return null;
}
}
static public IF0 f0ToIF0(F0 f) {
return f == null ? null : () -> f.get();
}
static public A setThreadLocal(ThreadLocal tl, A value) {
if (tl == null)
return null;
A old = tl.get();
tl.set(value);
return old;
}
static public ClassLoader classLoaderForObject(Object o) {
if (o instanceof ClassLoader)
return ((ClassLoader) o);
if (o == null)
return null;
return _getClass(o).getClassLoader();
}
static public String classNameToVM(String name) {
return name.replace(".", "$");
}
static public 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 byte[] unnullForIteration(byte[] l) {
return l == null ? emptyByteArray() : 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 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 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 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 Set synchronizedSet() {
return synchroHashSet();
}
static public Set synchronizedSet(Set set) {
return Collections.synchronizedSet(set);
}
static public Set identityHashSet() {
return Collections.newSetFromMap(new IdentityHashMap());
}
static public 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 List cloneSubList(List l, int startIndex, int endIndex) {
return newSubList(l, startIndex, endIndex);
}
static public List cloneSubList(List l, int startIndex) {
return newSubList(l, startIndex);
}
static public void removeSubList(List l, int from, int to) {
if (l != null)
subList(l, from, to).clear();
}
static public void removeSubList(List l, int from) {
if (l != null)
subList(l, from).clear();
}
static public String shortenSnippetID(String snippetID) {
if (snippetID.startsWith("#"))
snippetID = snippetID.substring(1);
String httpBlaBla = "http://tinybrain.de/";
if (snippetID.startsWith(httpBlaBla))
snippetID = snippetID.substring(httpBlaBla.length());
return "" + parseLong(snippetID);
}
static public Object callOpt(Object o) {
return callF(o);
}
static public Object callOpt(Object o, String method, Object... args) {
return callOpt_withVarargs(o, method, args);
}
static public List immutableEmptyList() {
return Collections.emptyList();
}
static public byte[] emptyByteArray_a = new byte[0];
static public byte[] emptyByteArray() {
return emptyByteArray_a;
}
static public short[] emptyShortArray = new short[0];
static public short[] emptyShortArray() {
return emptyShortArray;
}
static public Map immutableEmptyMap() {
return Collections.emptyMap();
}
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(F2 f, A a, B b) {
return f == null ? null : f.get(a, b);
}
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 HashSet litset(A... items) {
return lithashset(items);
}
static public Set synchroHashSet() {
return synchronizedSet(new HashSet ());
}
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 List newSubList(List l, int startIndex, int endIndex) {
return cloneList(subList(l, startIndex, endIndex));
}
static public List newSubList(List l, int startIndex) {
return cloneList(subList(l, startIndex));
}
static public List subList(List l, int startIndex) {
return subList(l, startIndex, l(l));
}
static public List subList(int startIndex, List l) {
return subList(l, startIndex);
}
static public List subList(int startIndex, int endIndex, List l) {
return subList(l, startIndex, endIndex);
}
static public List subList(List l, int startIndex, int endIndex) {
if (l == null)
return null;
int n = l(l);
startIndex = Math.max(0, startIndex);
endIndex = Math.min(n, endIndex);
if (startIndex > endIndex)
return ll();
if (startIndex == 0 && endIndex == n)
return l;
return l.subList(startIndex, endIndex);
}
static public List subList(List l, IntRange r) {
return subList(l, r.start, r.end);
}
static public long parseLong(String s) {
if (empty(s))
return 0;
return Long.parseLong(dropSuffix("L", s));
}
static public long parseLong(Object s) {
return Long.parseLong((String) s);
}
static public Object callOpt_withVarargs(Object o, String method, Object... args) {
try {
if (o == null)
return null;
if (o instanceof Class) {
Class c = (Class) o;
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(method, args);
if (me == null) {
return null;
}
if ((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(method, args);
if (me != null)
return invokeMethod(me, o, args);
List methods = cache.cache.get(method);
if (methods != null)
methodSearch: for (Method m : methods) {
{
if (!(m.isVarArgs()))
continue;
}
Object[] newArgs = massageArgsForVarArgsCall(m, args);
if (newArgs != null)
return invokeMethod(m, o, newArgs);
}
return null;
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public HashSet lithashset(A... items) {
HashSet set = new HashSet();
for (A a : items) set.add(a);
return set;
}
static public String dropSuffix(String suffix, String s) {
return nempty(suffix) && endsWith(s, suffix) ? s.substring(0, l(s) - l(suffix)) : s;
}
static public boolean endsWith(String a, String b) {
return a != null && a.endsWith(b);
}
static public boolean endsWith(String a, char c) {
return nempty(a) && lastChar(a) == c;
}
static public boolean endsWith(String a, String b, Matches m) {
if (!endsWith(a, b))
return false;
m.m = new String[] { dropLast(l(b), a) };
return true;
}
static public char lastChar(String s) {
return empty(s) ? '\0' : s.charAt(l(s) - 1);
}
static public A[] dropLast(A[] a) {
return dropLast(a, 1);
}
static public A[] dropLast(A[] a, int n) {
if (a == null)
return null;
n = Math.min(n, a.length);
A[] b = arrayOfSameType(a, a.length - n);
System.arraycopy(a, 0, b, 0, b.length);
return b;
}
static public List dropLast(List l) {
return subList(l, 0, l(l) - 1);
}
static public List dropLast(int n, List l) {
return subList(l, 0, l(l) - n);
}
static public List dropLast(Iterable l) {
return dropLast(asList(l));
}
static public String dropLast(String s) {
return substring(s, 0, l(s) - 1);
}
static public String dropLast(String s, int n) {
return substring(s, 0, l(s) - n);
}
static public String dropLast(int n, String s) {
return dropLast(s, n);
}
static public A[] arrayOfSameType(A[] a, int n) {
return newObjectArrayOfSameType(a, n);
}
static public A[] newObjectArrayOfSameType(A[] a) {
return newObjectArrayOfSameType(a, a.length);
}
static public A[] newObjectArrayOfSameType(A[] a, int n) {
return (A[]) Array.newInstance(a.getClass().getComponentType(), n);
}
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 Meta implements IMeta {
volatile public Object meta;
public void _setMeta(Object meta) {
this.meta = meta;
}
public Object _getMeta() {
return meta;
}
final public boolean scaffolding() {
return scaffoldingEnabled();
}
final public boolean scaffolded() {
return scaffoldingEnabled();
}
public boolean scaffoldingEnabled() {
return main.scaffoldingEnabled(this);
}
public boolean scaffoldingEnabled(Object o) {
return main.scaffoldingEnabled(o);
}
public String toString_base() {
return super.toString();
}
public String toString() {
Object o = metaGet("toString", this);
if (o instanceof String)
return ((String) o);
if (o instanceof IF1)
return str(((IF1) o).get(this));
return toString_base();
}
}
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 Var implements IVar , ISetter {
public Var() {
}
public Var(A v) {
this.v = v;
}
public A v;
public synchronized void set(A a) {
if (v != a) {
v = a;
notifyAll();
}
}
public synchronized A get() {
return v;
}
public synchronized boolean has() {
return v != null;
}
public void clear() {
set(null);
}
public synchronized A getAndSet(A a) {
var value = v;
set(a);
return value;
}
public IF0 getter() {
return () -> get();
}
public IVF1 setter() {
return __49 -> set(__49);
}
public String toString() {
return str(this.get());
}
}
static public interface IMeta {
public void _setMeta(Object meta);
public Object _getMeta();
default public IAutoCloseableF0 _tempMetaMutex() {
return new IAutoCloseableF0() {
public Object get() {
return IMeta.this;
}
public void close() {
}
};
}
default public Object getMeta(Object obj, Object key) {
return metaGet(obj, key);
}
default public Object metaGet(Object obj, Object key) {
return metaMapGet(obj, key);
}
default public Object metaGet(String key, Object obj) {
return metaMapGet(obj, key);
}
default public Object getMeta(Object key) {
return metaGet(key);
}
default public Object metaGet(Object key) {
if (key == null)
return null;
Object meta = _getMeta();
if (meta instanceof Map)
return ((Map) meta).get(key);
return null;
}
default public void metaSet(IMeta obj, Object key, Object value) {
metaPut(obj, key, value);
}
default public void metaPut(IMeta obj, Object key, Object value) {
metaMapPut(obj, key, value);
}
default public void metaSet(Object key, Object value) {
metaPut(key, value);
}
default public void metaPut(Object key, Object value) {
if (key == null)
return;
Map map = convertObjectMetaToMap(this);
syncMapPutOrRemove(map, key, value);
}
}
static public class BetterThread extends Thread {
public Runnable target;
public BetterThread(Runnable target) {
this.target = target;
_created();
}
public BetterThread(Runnable target, String name) {
super(name);
this.target = target;
_created();
}
public void _created() {
vmBus_send("threadCreated", this);
}
public void run() {
try {
try {
vmBus_send("threadStarted", this);
if (target != null)
target.run();
} finally {
vmBus_send("threadEnded", this);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public Runnable getTarget() {
return target;
}
}
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_noToolTip() {
return stdImageSurface_noToolTip(imageSurface());
}
public ImageSurface stdImageSurface_noToolTip(ImageSurface is) {
imageSurface_pixelated(is);
is.setAutoZoomToDisplay(true).repaintInThread(false);
is.defaultImageDir = () -> dbDir();
is.specialPurposed = true;
return is;
}
public ImageSurface stdImageSurface() {
return stdImageSurface(imageSurface());
}
public ImageSurface stdImageSurface(ImageSurface is) {
stdImageSurface_noToolTip(is);
new ImageSurface_PositionToolTip(is);
return is;
}
public List stdImageSurfaces(Collection images) {
return map(__60 -> stdImageSurface(__60), toBufferedImages(images));
}
public ImageSurface stdImageSurface(MakesBufferedImage img) {
return stdImageSurface(toBufferedImage(img));
}
public ImageSurface stdImageSurface(BufferedImage img) {
var is = stdImageSurface();
is.setImage(img);
return is;
}
public ImageSurface stdImageSurface(File file) {
var is = stdImageSurface();
is.setImage(file);
return is;
}
public ImageSurface stdImageSurface(G22GalleryImage img) {
return stdImageSurface(img == null ? null : img.path);
}
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");
parser.addClassAlias("MRUAndAllTimeTop", "MRUAndAllTimeTop_optimized");
return parser;
}
public Object leftArrow(String script) {
return leftArrowParse(script).get();
}
public GazelleV_LeftArrowScript.Script leftArrowParse(String script) {
return leftArrowParser().parse(script);
}
public Object leftArrowWithVars(String script, Object... vars) {
var parser = leftArrowParser();
for (int i = 0; i < l(vars); i += 2) parser.addVar((String) vars[i], or(_getClass(vars[i + 1]), Object.class), true);
var parsed = parser.parse(script);
FlexibleVarContext varContext = new FlexibleVarContext();
for (int i = 0; i < l(vars); i += 2) varContext.set((String) vars[i], vars[i + 1]);
return parsed.get(varContext);
}
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 masterStuff.databasesMotherDir();
}
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 recentlyOpenedDBsFile() {
return newFile(databasesMotherDir(), "Recently 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() {
return loadRecentProjectsFile(lastOpenedDBsFile());
}
public List dbNamesRecentlyOpened() {
return loadRecentProjectsFile(recentlyOpenedDBsFile());
}
public void addToRecentDBNames(String dbName, boolean hidden) {
List list = dbNamesRecentlyOpened();
List list2 = cloneList(list);
removeAll(list2, dbName, "*" + dbName);
list2.add(0, hidden ? "*" + dbName : dbName);
truncateList(list2, 100);
if (!eq(list, list2))
saveTextFile(recentlyOpenedDBsFile(), lines(list2));
}
public List loadRecentProjectsFile(File file) {
List dbNames = new ArrayList();
for (String name : tlft(loadTextFile(file))) {
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 void setupScriptCRUD(SimpleCRUD_v2 crud) {
setupScriptCRUD(crud, false);
}
public void setupScriptCRUD(SimpleCRUD_v2 crud, boolean allowRunOnProjectOpen) {
crud.useNewChangeHandler(true);
crud.editableFieldsForItem = x -> llNonNulls("description", allowRunOnProjectOpen ? "runOnProjectOpen" : null, allowRunOnProjectOpen ? "runOrder" : null);
crud.multiLineField("text");
crud.multiLineField("editingText");
crud.makeTextArea = text -> jMinHeight(200, crud.makeTextArea_base(text));
crud.humanizeFieldNames = false;
crud.iconButtons(true);
crud.itemToMap_inner2 = c -> scriptToMap(c, allowRunOnProjectOpen);
crud.dontDuplicateFields = litset("runOnProjectOpen", "runOrder", "runCount", "lastResultByMode");
}
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(__61 -> linesOfCode_javaTok(__61), 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(__62 -> getLabel(__62), 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 IterableIterator peekAllProjectsConcepts() {
var classFinder = masterStuff.makeClassFinder();
return mapI_pcall(gazelleDBs(), db -> {
var cc = newConceptsWithClassFinder(db.conceptsFile(), classFinder);
cc.loadFromDisk();
return cc;
});
}
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 conceptWhereCI(concepts, G22Variable.class, "name", name);
}
public Collection projectVarNames() {
return collect("name", list(concepts, G22Variable.class));
}
public Object getProjectVar(String name) {
G22Variable var = findProjectVar(name);
return var == null ? null : var.value();
}
public Object getProjectVarOrCallScript(String name, long scriptID) {
{
var __2 = getProjectVar(name);
if (__2 != null)
return __2;
}
return callScript(scriptID);
}
public Object getProjectVarSetByScript(String name, long scriptID) {
{
var __3 = getProjectVar(name);
if (__3 != null)
return __3;
}
callScript(scriptID);
return getProjectVar(name);
}
public Object getProjectVarFromAnyProject(String name) {
for (var project : masterStuff().openProjects()) {
var __4 = project.g22utils().getProjectVar(name);
if (__4 != null)
return __4;
}
return null;
}
final public List getVarFromAnyProject(String name) {
return getProjectVarFromAllProjects(name);
}
public List getProjectVarFromAllProjects(String name) {
return nonNulls(masterStuff().openProjects(), project -> project.g22utils().getProjectVar(name));
}
public G22Variable projectVarConcept(String name) {
return optimizedUniqCI(concepts, G22Variable.class, "name", name);
}
public Object waitForProjectVar(String name) {
return waitForProjectVar(infinity(), name);
}
public Object waitForProjectVar(double timeoutSeconds, String name) {
G22Variable var = projectVarConcept(name);
return waitForCalculatedValueUsingChangeListener(timeoutSeconds, () -> var.value(), var);
}
public void setBigProjectVar(boolean persistent, String name, Object value) {
if (persistent)
setBigProjectVar(name, value);
else
setTransientProjectVar(name, value);
}
public G22Variable setProjectVar(boolean persistent, String name, Object value) {
G22Variable var = projectVarConcept(name);
if (!persistent)
var.persistent(persistent);
var.value(value);
if (persistent)
var.persistent(persistent);
return var;
}
public void unloadProjectVar(String name) {
var var = findProjectVar(name);
{
if (var != null)
var.unload();
}
}
public void setBigProjectVar(String name, Object value) {
setPersistentProjectVar(name, value);
G22Variable var = projectVarConcept(name);
var.makeBig();
}
public Object getCachedProjectVar(String name) {
var var = findProjectVar(name);
return var == null ? null : var.cachedValue();
}
public boolean isBigProjectVar(String name) {
var v = findProjectVar(name);
return v != null && v.big();
}
public void setPersistentProjectVar(String name, Object value) {
setProjectVar(true, name, value);
}
public G22Variable setTransientProjectVar(String name, Object value) {
return setProjectVar(false, name, value);
}
public void setAutoClosingProjectVar(String name, Object value) {
setTransientProjectVar(name, value).autoClose(true);
}
public void deleteProjectVar(String name) {
deleteConcept(findProjectVar(name));
}
public Object getOrCreateProjectVar(String name, IF0 maker) {
return getOrCreateProjectVar(projectVarConcept(name), maker);
}
public Object getOrCreatePersistentProjectVar(String name, IF0 maker) {
var var = projectVarConcept(name);
Object value = getOrCreateProjectVar(var, maker);
var.persistent(true);
return value;
}
public Object getOrCreateProjectVar(G22Variable var, IF0 maker) {
if (!var.has()) {
Object value = maker.get();
if (value != null)
var.setValueIfNull(value);
}
return var.get();
}
public IVarWithNotify liveProjectVar(String name) {
return liveProjectVar(name, null);
}
public IVarWithNotify liveProjectVar(String name, Object defaultValue) {
G22Variable var = projectVarConcept(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 = projectVarConcept(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 void projectVarChanged(String name) {
var var = findProjectVar(name);
{
if (var != null)
var.changeInsideOfValue();
}
}
public Collection projectVarChanged(Object value) {
var vars = conceptsWhere(concepts, G22Variable.class, "value", value);
for (var var : vars) var.change();
return vars;
}
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 __5 = 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(__5);
}
});
}
public Object host() {
AutoCloseable __6 = enter();
try {
return dm_os();
} finally {
_close(__6);
}
}
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(), __7 -> projectFileChanged(__7));
}
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);
}
public ConceptsComboBox galleryImagesComboBox() {
return swing(() -> new ConceptsComboBox(concepts, G22GalleryImage.class));
}
public IBackgroundProcess tempAddBackgroundProcess(String name) {
return backgroundProcessesUI == null ? null : backgroundProcessesUI.tempAdd(name);
}
public IF1 classFinder() {
return masterStuff.makeClassFinder();
}
public Object restructure(Object o) {
return unstructure(structure(o), false, concepts.classFinder);
}
public G22ProjectActions project() {
return projectActions();
}
public boolean openPathInProject(String path) {
return projectActions().openPathInProject(path);
}
final public boolean showUIURL(String url) {
return openUIURL(url);
}
public boolean openUIURL(String url) {
return projectActions().openUIURL(url);
}
public BufferedImage loadProjectImage(String fileName) {
return loadImage2(projectFile(fileName));
}
public IG22LoadedDB openDB(String name) {
return openDB(name, false);
}
public IG22LoadedDB openDB(String name, boolean hidden) {
return masterStuff().openDB(name, hidden);
}
public G22Utils getProject(String name) {
return openDB(name, true).g22utils();
}
public G22JavaObjectVisualizer visualizeObject(Object o) {
return new G22JavaObjectVisualizer(this, o);
}
transient public IF0 makeVariablesPanel;
public G22VariablesPanel makeVariablesPanel() {
return makeVariablesPanel != null ? makeVariablesPanel.get() : makeVariablesPanel_base();
}
final public G22VariablesPanel makeVariablesPanel_fallback(IF0 _f) {
return _f != null ? _f.get() : makeVariablesPanel_base();
}
public G22VariablesPanel makeVariablesPanel_base() {
return new G22VariablesPanel().g22utils(this);
}
transient public IF0 jGazelleLogo;
public JComponent jGazelleLogo() {
return jGazelleLogo != null ? jGazelleLogo.get() : jGazelleLogo_base();
}
final public JComponent jGazelleLogo_fallback(IF0 _f) {
return _f != null ? _f.get() : jGazelleLogo_base();
}
public JComponent jGazelleLogo_base() {
return main.jGazelleLogo();
}
public boolean devMode() {
return masterStuff().devMode();
}
public List list(Class type) {
return list(type, concepts());
}
public List list(Class type, Concepts cc) {
return main.list(cc, type);
}
public List list(Concepts concepts, Class type) {
return main.list(type, concepts);
}
public G22GalleryImage galleryImageForMD5(String md5) {
return firstThat(list(concepts, G22GalleryImage.class), img -> cic(fileName(img.path), md5));
}
public JComponent wrapImageSurface(ImageSurface is) {
return is == null ? null : jscroll_centered_borderless(is);
}
public JComponent wrap(Object o) {
var c = main.wrap(o);
if (c instanceof ImageSurface)
return wrapImageSurface((ImageSurface) c);
return c;
}
transient public IF0 byUser;
public String byUser() {
return byUser != null ? byUser.get() : byUser_base();
}
final public String byUser_fallback(IF0 _f) {
return _f != null ? _f.get() : byUser_base();
}
public String byUser_base() {
return "";
}
final public Collection extends IG22LoadedDB> openProjects() {
return getLoadedDBs();
}
public Collection extends IG22LoadedDB> getLoadedDBs() {
return masterStuff().openProjects();
}
public List listInOpenProjects(Class type) {
return concatMap(openProjects(), db -> db.g22utils().list(type));
}
transient public PicturesByMD5 picturesByMD5_cache;
public PicturesByMD5 picturesByMD5() {
if (picturesByMD5_cache == null)
picturesByMD5_cache = picturesByMD5_load();
return picturesByMD5_cache;
}
public PicturesByMD5 picturesByMD5_load() {
return new PicturesByMD5(projectFile("Images")).extension(".qoi");
}
public JButton reloadButton(String toolTip, Runnable action) {
return jimageButton("#1101440", toolTip, action);
}
public void registerConcept(Concept c) {
main.registerConcept(concepts, c);
}
public void registerConcept(Concepts cc, Concept c) {
main.registerConcept(cc, c);
}
}
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 PopupMenuMaker {
final public PopupMenuMaker setAllowScrolling(boolean allowScrolling) {
return allowScrolling(allowScrolling);
}
public PopupMenuMaker allowScrolling(boolean allowScrolling) {
this.allowScrolling = allowScrolling;
return this;
}
final public boolean getAllowScrolling() {
return allowScrolling();
}
public boolean allowScrolling() {
return allowScrolling;
}
public boolean allowScrolling = true;
final public PopupMenuMaker setEvent(MouseEvent event) {
return event(event);
}
public PopupMenuMaker event(MouseEvent event) {
this.event = event;
return this;
}
final public MouseEvent getEvent() {
return event();
}
public MouseEvent event() {
return event;
}
public MouseEvent event;
final public PopupMenuMaker setPtInComponent(PtInComponent ptInComponent) {
return ptInComponent(ptInComponent);
}
public PopupMenuMaker ptInComponent(PtInComponent ptInComponent) {
this.ptInComponent = ptInComponent;
return this;
}
final public PtInComponent getPtInComponent() {
return ptInComponent();
}
public PtInComponent ptInComponent() {
return ptInComponent;
}
public PtInComponent ptInComponent;
final public PopupMenuMaker setFillMenu(IVF1 fillMenu) {
return fillMenu(fillMenu);
}
public PopupMenuMaker fillMenu(IVF1 fillMenu) {
this.fillMenu = fillMenu;
return this;
}
final public IVF1 getFillMenu() {
return fillMenu();
}
public IVF1 fillMenu() {
return fillMenu;
}
public IVF1 fillMenu;
final public PopupMenuMaker setExistingMenu(JPopupMenu existingMenu) {
return existingMenu(existingMenu);
}
public PopupMenuMaker existingMenu(JPopupMenu existingMenu) {
this.existingMenu = existingMenu;
return this;
}
final public JPopupMenu getExistingMenu() {
return existingMenu();
}
public JPopupMenu existingMenu() {
return existingMenu;
}
public JPopupMenu existingMenu;
final public PopupMenuMaker setAddSeparator(boolean addSeparator) {
return addSeparator(addSeparator);
}
public PopupMenuMaker addSeparator(boolean addSeparator) {
this.addSeparator = addSeparator;
return this;
}
final public boolean getAddSeparator() {
return addSeparator();
}
public boolean addSeparator() {
return addSeparator;
}
public boolean addSeparator = true;
public JPopupMenu menu;
public PopupMenuMaker() {
}
public PopupMenuMaker(MouseEvent event, IVF1 fillMenu) {
this.fillMenu = fillMenu;
this.event = event;
}
public void run() {
swing(() -> {
if (existingMenu != null) {
fix();
var menu = existingMenu;
int emptyCount = menu.getComponentCount();
if (addSeparator)
menu.addSeparator();
int emptyCount2 = menu.getComponentCount();
{
if (fillMenu != null)
fillMenu.get(menu);
}
if (menu.getComponentCount() == emptyCount2)
truncateContainer(menu, emptyCount);
packWindow(menu);
} else {
JPopupMenu menu = new JPopupMenu();
int emptyCount = menu.getComponentCount();
{
if (fillMenu != null)
fillMenu.get(menu);
}
if (menu.getComponentCount() == emptyCount)
return;
if (allowScrolling) {
menu = new JPopupMenu();
JMenuScroller scroller = JMenuScroller.setScrollerFor(menu);
scroller.fillMenu = toVF1(fillMenu);
}
if (ptInComponent == null)
ptInComponent = ptInComponentFromEvent(event);
if (hasParentOfType(JPopupMenu.class, ptInComponent.component)) {
menu.setInvoker(ptInComponent.component);
menu.setVisible(true);
} else
menu.show(ptInComponent.component, ptInComponent.p.x, ptInComponent.p.y);
}
});
}
static public void fix() {
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
}
}
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;
private boolean keyEquals(Object k1, Object k2) {
return (hasher == null ? k1.equals(k2) : hasher.equals(k1, k2));
}
private int keyHashCode(Object k1) {
return (hasher == null ? k1.hashCode() : hasher.hashCode(k1));
}
private WeakKey WeakKeyCreate(K k) {
if (k == null)
return null;
else
return new WeakKey(k);
}
private 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);
}
private 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);
}
private 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")
private 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);
}
private boolean keyvalEquals(K o1, K o2) {
return (o1 == null) ? (o2 == null) : keyEquals(o1, o2);
}
private boolean valEquals(V o1, V o2) {
return (o1 == null) ? (o2 == null) : o1.equals(o2);
}
@SuppressWarnings("NonOverridingEquals")
public boolean equals(Map.Entry e) {
return (keyvalEquals(key, e.getKey()) && valEquals(getValue(), e.getValue()));
}
@Override
public int hashCode() {
V v;
return (((key == null) ? 0 : keyHashCode(key)) ^ (((v = getValue()) == null) ? 0 : v.hashCode()));
}
}
final public class EntrySet extends AbstractSet> {
public Set> hashEntrySet = hash.entrySet();
@Override
public Iterator> iterator() {
return new Iterator>() {
public Iterator> hashIterator = hashEntrySet.iterator();
public Map.Entry next = null;
@Override
public boolean hasNext() {
while (hashIterator.hasNext()) {
Map.Entry ent = hashIterator.next();
WeakKey wk = ent.getKey();
K k = null;
if ((wk != null) && ((k = wk.get()) == null)) {
continue;
}
next = new Entry(ent, k);
return true;
}
return false;
}
@Override
public Map.Entry next() {
if ((next == null) && !hasNext())
throw new NoSuchElementException();
Map.Entry e = next;
next = null;
return e;
}
@Override
public void remove() {
hashIterator.remove();
}
};
}
@Override
public boolean isEmpty() {
return !(iterator().hasNext());
}
@Override
public int size() {
int j = 0;
for (Iterator> i = iterator(); i.hasNext(); i.next()) j++;
return j;
}
@Override
public boolean remove(Object o) {
processQueue();
if (!(o instanceof Map.Entry, ?>))
return false;
@SuppressWarnings("unchecked")
Map.Entry e = (Map.Entry) o;
Object ev = e.getValue();
WeakKey wk = WeakKeyCreate(e.getKey());
Object hv = hash.get(wk);
if ((hv == null) ? ((ev == null) && hash.containsKey(wk)) : hv.equals(ev)) {
hash.remove(wk);
return true;
}
return false;
}
@Override
public int hashCode() {
int h = 0;
for (Iterator> i = hashEntrySet.iterator(); i.hasNext(); ) {
Map.Entry ent = i.next();
WeakKey wk = ent.getKey();
Object v;
if (wk == null)
continue;
h += (wk.hashCode() ^ (((v = ent.getValue()) == null) ? 0 : v.hashCode()));
}
return h;
}
}
public Set> entrySet = null;
@Override
public Set> entrySet() {
if (entrySet == null)
entrySet = new EntrySet();
return entrySet;
}
public K findKey(Object key) {
processQueue();
K kkey = (K) key;
WeakKey wkey = WeakKeyCreate(kkey);
WeakKey found = hashMap_findKey(hash, wkey);
return found == null ? null : found.get();
}
}
static public class Pair implements Comparable> {
final public Pair setA(A a) {
return a(a);
}
public Pair a(A a) {
this.a = a;
return this;
}
final public A getA() {
return a();
}
public A a() {
return a;
}
public A a;
final public Pair setB(B b) {
return b(b);
}
public Pair b(B b) {
this.b = b;
return this;
}
final public B getB() {
return b();
}
public B b() {
return b;
}
public B b;
public Pair() {
}
public Pair(A a, B b) {
this.b = b;
this.a = a;
}
public int hashCode() {
return hashCodeFor(a) + 2 * hashCodeFor(b);
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Pair))
return false;
Pair t = (Pair) o;
return eq(a, t.a) && eq(b, t.b);
}
public String toString() {
return "<" + a + ", " + b + ">";
}
public int compareTo(Pair p) {
if (p == null)
return 1;
int i = ((Comparable ) a).compareTo(p.a);
if (i != 0)
return i;
return ((Comparable) b).compareTo(p.b);
}
}
static public class Fail extends RuntimeException implements IFieldsToList {
public Object[] objects;
public Fail() {
}
public Fail(Object... objects) {
this.objects = objects;
}
public Object[] _fieldsToList() {
return new Object[] { objects };
}
public Fail(Throwable cause, Object... objects) {
super(cause);
this.objects = objects;
}
public String toString() {
return joinNemptiesWithColon("Fail", getMessage());
}
public String getMessage() {
return commaCombine(getCause(), objects);
}
}
static public interface Swingable {
public JComponent visualize();
}
static abstract public class F0 {
abstract public A get();
}
static abstract public class F1 {
abstract public B get(A a);
}
static abstract public class IterableIterator implements Iterator , Iterable {
public Iterator iterator() {
return this;
}
public void remove() {
unsupportedOperation();
}
}
public static interface IF0 {
public A get();
}
static public interface Hasher {
public int hashCode(A a);
public boolean equals(A a, A b);
}
static public interface IFieldsToList {
public Object[] _fieldsToList();
}
static public interface IF1 {
public B get(A a);
}
static public class PersistableThrowable extends DynamicObject {
public String className;
public String msg;
public String stacktrace;
public PersistableThrowable() {
}
public PersistableThrowable(Throwable e) {
if (e == null)
className = "Crazy Null Error";
else {
className = getClassName(e).replace('/', '.');
msg = e.getMessage();
stacktrace = getStackTrace_noRecord(e);
}
}
public String toString() {
return nempty(msg) ? className + ": " + msg : className;
}
public RuntimeException asRuntimeException() {
return new Fail(this);
}
}
static public interface IVF1 {
public void get(A a);
}
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 G22VariablesPanel implements Swingable, IFieldsToList {
public G22VariablesPanel() {
}
public String toString() {
return shortClassName_dropNumberPrefix(this);
}
public Object[] _fieldsToList() {
return null;
}
final public G22VariablesPanel setG22utils(G22Utils g22utils) {
return g22utils(g22utils);
}
public G22VariablesPanel g22utils(G22Utils g22utils) {
this.g22utils = g22utils;
return this;
}
final public G22Utils getG22utils() {
return g22utils();
}
public G22Utils g22utils() {
return g22utils;
}
public G22Utils g22utils;
final public G22VariablesPanel setCompactView(boolean compactView) {
return compactView(compactView);
}
public G22VariablesPanel compactView(boolean compactView) {
this.compactView = compactView;
return this;
}
final public boolean getCompactView() {
return compactView();
}
public boolean compactView() {
return compactView;
}
public boolean compactView = false;
final public G22VariablesPanel setUpdateInterval(double updateInterval) {
return updateInterval(updateInterval);
}
public G22VariablesPanel updateInterval(double updateInterval) {
this.updateInterval = updateInterval;
return this;
}
final public double getUpdateInterval() {
return updateInterval();
}
public double updateInterval() {
return updateInterval;
}
public double updateInterval = 1.0;
transient public SimpleCRUD_v2 crud;
transient public SingleComponentPanel scpDetail;
transient public ReliableSingleThread rstUpdateDetail = rst(() -> _updateDetail());
public SimpleCRUD_v2 crud() {
if (crud == null) {
crud = new SimpleCRUD_v2<>(g22utils.concepts(), G22Variable.class);
crud.updateInterval(updateInterval);
}
return crud;
}
public transient JComponent visualize_cache;
public JComponent visualize() {
if (visualize_cache == null)
visualize_cache = visualize_load();
return visualize_cache;
}
public JComponent visualize_load() {
return markVisualizer(this, visualize_impl());
}
public JComponent visualize_impl() {
crud().iconButtons(true);
crud.entityName = () -> "Variable";
crud.renderValue = __1 -> strOrNull(__1);
var vis = jCenteredSection("Project Variables", crud.visualize());
if (compactView)
return vis;
crud.onSingleSelectionChanged(() -> {
print("Selection: " + crud.selected());
rstUpdateDetail.get();
});
scpDetail = scp();
return jvsplit(vis, scpDetail);
}
public void updateCount() {
crud().update();
}
public void setSelected(G22Variable var) {
crud().setSelected(var);
}
public void _updateDetail() {
var var = crud.selected();
if (var == null) {
scpDetail.clear();
return;
}
Object value = var.value();
var vis = new G22JavaObjectVisualizer(g22utils, value).visualize();
bindChangeListenerToComponent(vis, var.varValue(), () -> {
if (!eq(var.value(), value))
rstUpdateDetail.get();
});
scpDetail.set(jCenteredSection("Variable " + var.name, vis));
}
}
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 G22GalleryImage extends ConceptWithChangeListeners {
public transient FieldVar varPath_cache;
public FieldVar varPath() {
if (varPath_cache == null)
varPath_cache = varPath_load();
return varPath_cache;
}
public FieldVar varPath_load() {
return new FieldVar(this, "path", () -> path(), path -> path(path));
}
final public G22GalleryImage setPath(File path) {
return path(path);
}
public G22GalleryImage path(File path) {
if (!eq(this.path, path)) {
this.path = path;
change();
}
return this;
}
final public File getPath() {
return path();
}
public File path() {
return path;
}
public File path;
public String toString() {
return fileName(path);
}
public boolean imageExists() {
return fileExists(path);
}
final public BufferedImage image() {
return load();
}
final public BufferedImage getImage() {
return load();
}
public BufferedImage load() {
return loadImage2(path);
}
public File imageFile() {
return path;
}
}
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 defaultMaskSize historicalProjectDirs useFirefox";
final public String getProjectID() {
return projectID();
}
public String projectID() {
return projectID;
}
public String projectID = aGlobalID();
public File projectDir;
final public G22MaskSize getDefaultMaskSize() {
return defaultMaskSize();
}
public G22MaskSize defaultMaskSize() {
return defaultMaskSize;
}
public G22MaskSize defaultMaskSize = new G22MaskSize();
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 boolean openPathInProject(String path);
public void editProjectStory();
public void editScripts();
public void editScript(G22LeftArrowScript script);
public boolean openUIURL(String url);
public IVarWithNotify