Warning : session_start(): open(/var/lib/php/sessions/sess_1bqngf2nnnqs0q8o6ve6al170t, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning : session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
import x30_pkg.x30_util;
import static x30_pkg.x30_util.VF1;
import static x30_pkg.x30_util.l;
import static x30_pkg.x30_util.fail;
import static x30_pkg.x30_util.indexOf;
import static x30_pkg.x30_util.getOpt;
import static x30_pkg.x30_util.setOpt;
import static x30_pkg.x30_util.callOpt;
import static x30_pkg.x30_util.newWeakHashMap;
import static x30_pkg.x30_util.newDangerousWeakHashMap;
import static x30_pkg.x30_util.get;
import static x30_pkg.x30_util.get_raw;
import static x30_pkg.x30_util.assertTrue;
import static x30_pkg.x30_util.isHeadless;
import static x30_pkg.x30_util.isAndroid;
import static x30_pkg.x30_util.isTrue;
import x30_pkg.x30_util.DynamicObject;
import loadableUtils.utils;
import static loadableUtils.utils._threadInfo;
import static loadableUtils.utils._threadInheritInfo;
import static loadableUtils.utils._threadInfo_addMakerAndRetriever;
import static loadableUtils.utils.dm_currentModule;
import static loadableUtils.utils.dm_current_mandatory;
import static loadableUtils.utils.match;
import static loadableUtils.utils.getOpt_raw;
import static loadableUtils.utils.setOpt_raw;
import static loadableUtils.utils.getField;
import static loadableUtils.utils.fieldType;
import static loadableUtils.utils.format3;
import static loadableUtils.utils.vm_generalIdentityHashSet;
import static loadableUtils.utils.vm_generalHashMap;
import static loadableUtils.utils.vm_generalWeakSubMap;
import static loadableUtils.utils.bindToComponent;
import static loadableUtils.utils.struct;
import static loadableUtils.utils.structure;
import static loadableUtils.utils.loadPage;
import static loadableUtils.utils.loadPage_utf8;
import static loadableUtils.utils.loadPageSilentlyWithTimeout;
import static loadableUtils.utils.loadPageSilently;
import static loadableUtils.utils.loadSnippet;
import static loadableUtils.utils.loadSnippetQuietly;
import static loadableUtils.utils.sendToLocalBot;
import static loadableUtils.utils.componentPopupMenu;
import static loadableUtils.utils.componentPopupMenu_top;
import static loadableUtils.utils.componentPopupMenu_initForComponent;
import static loadableUtils.utils.componentPopupMenu_getEvent;
import static loadableUtils.utils.listPopupMenu;
import static loadableUtils.utils.tablePopupMenu;
import static loadableUtils.utils.tablePopupMenuFirst;
import static loadableUtils.utils.rowSorter_setComparators;
import static loadableUtils.utils.sexyTableWithoutDrag;
import static loadableUtils.utils.dm_current_generic;
import static loadableUtils.utils.dm_current_mandatory_generic;
import static loadableUtils.utils.cset;
import static loadableUtils.utils.DynamicObject_loading;
import static loadableUtils.utils.concepts_unlisted;
import static loadableUtils.utils.makePopupMenuConditional;
import static loadableUtils.utils.makeConceptsTable_idWidth;
import static loadableUtils.utils.showConceptsTable_afterUpdate;
import static loadableUtils.utils.dynamicObjectIsLoading;
import loadableUtils.utils.F0;
import loadableUtils.utils.F1;
import loadableUtils.utils.IF1;
import loadableUtils.utils.Matches;
import loadableUtils.utils.BetterLabel;
import loadableUtils.utils.SingleComponentPanel;
import loadableUtils.utils.Snippet;
import loadableUtils.utils.Q;
import loadableUtils.utils.ImageSurface;
import loadableUtils.utils.structure_Data;
import loadableUtils.utils.structure_ClassInfo;
import loadableUtils.utils.RGBImage;
import loadableUtils.utils.RGB;
import loadableUtils.utils.BWImage;
import loadableUtils.utils.MakesBufferedImage;
import loadableUtils.utils.MultiSet;
import loadableUtils.utils.Concept;
import loadableUtils.utils.Concepts;
import loadableUtils.utils.IConceptIndex;
import loadableUtils.utils.IFieldIndex;
import loadableUtils.utils.Derefable;
import loadableUtils.utils.ImageSurfaceSelector;
import loadableUtils.utils.SimpleCRUD;
import loadableUtils.utils.PersistableThrowable;
import loadableUtils.utils.DynModule;
import loadableUtils.utils.DynPrintLog;
import loadableUtils.utils.DynObjectTable;
import loadableUtils.utils.DynImageSurface;
import loadableUtils.utils.DynCalculatedList;
import loadableUtils.utils.Rect;
import loadableUtils.utils.Pt;
import javax.swing.border.TitledBorder;
import javax.swing.tree.*;
import javax.swing.border.*;
import java.text.NumberFormat;
import javax.swing.undo.UndoManager;
import java.awt.datatransfer.StringSelection;
class main {
static public class TopDownParsing extends DynModule {
static public boolean _switchableField_input = true;
public String input = "Bob paid for Charlie 's college education";
static public boolean _switchableField_escapeBrackets = true;
public boolean escapeBrackets = false;
public TryPatterns root;
transient public JTree tree;
transient public String selectedGrouped;
transient public SingleComponentPanel scp;
transient public ReliableSingleThread rstProcessInput = dm_rstWithPreDelay(this, 500, new Runnable() {
public void run() {
try {
processInput();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "processInput();";
}
});
static public class Config implements IFieldsToList {
public List patternsToTry;
public Config() {
}
public Config(List patternsToTry) {
this.patternsToTry = patternsToTry;
}
public String toString() {
return shortClassName(this) + "(" + patternsToTry + ")";
}
public boolean equals(Object o) {
if (!(o instanceof Config))
return false;
Config x = (Config) o;
return eq(patternsToTry, x.patternsToTry);
}
public int hashCode() {
int h = 2024042338;
h = boostHashCombine(h, _hashCode(patternsToTry));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { patternsToTry };
}
}
abstract public class Base {
public Config config;
public List children;
public List children() {
return children;
}
abstract public String grouped();
abstract public List allGroupings();
abstract public List>> allGroupingsWithUsedPatterns();
}
public class AppliedPattern extends Base {
public String pattern;
public List arguments;
public List children() {
if (children == null)
children = map(arguments, a -> new TryPatterns(config, a));
return children;
}
public String toString() {
return shortName(this) + "(" + quote(pattern) + ")" + (empty(arguments) ? "" : " with " + join(" + ", quoteAll(arguments)));
}
public String grouped() {
return format3_round(pattern, toStringArray(arguments));
}
public List allGroupings() {
List> childGroupings = map(children(), a -> a.allGroupings());
print(quote(grouped()) + " got child groupings: " + childGroupings);
IterableIterator> combinations = allCombinations(childGroupings);
return map(combinations, c -> format3_round(pattern, c));
}
public List>> allGroupingsWithUsedPatterns() {
List>>> childGroupings = map(children(), a -> a.allGroupingsWithUsedPatterns());
IterableIterator>>> combinations = allCombinations(childGroupings);
return map(combinations, c -> pair(format3_round(pattern, pairsA(c)), concatListsAsCISet(itemPlusList(litciset(pattern), pairsB(c)))));
}
}
public class TryPatterns extends Base {
public String input;
public TryPatterns() {
}
public TryPatterns(Config config, String input) {
this.input = tok_deRoundOrCurlyBracket(input);
this.config = config;
}
public List children() {
if (children == null) {
children = new ArrayList();
for (String pat : config.patternsToTry) for (List arguments : matchesToStringLists(flexMatchIC_withBrackets_all_autoPunctuation(pat, input))) children.add(setAll(new AppliedPattern(), "config", config, "pattern", pat, "arguments", arguments));
}
return children;
}
public String toString() {
return shortName(this) + "(" + quote(input) + ")" + (empty(children) ? "" : " [" + nMatches(children()) + "]");
}
public String grouped() {
return empty(children()) ? input : first(children).grouped();
}
public List allGroupings() {
return uniquifyCI(listPlusItem(concatMap(children(), a -> a.allGroupings()), input));
}
public List>> allGroupingsWithUsedPatterns() {
return uniquifyByFieldCI("a", listPlusItem(concatMap(children(), a -> a.allGroupingsWithUsedPatterns()), pair(input, emptySet())));
}
}
public void start() {
try {
super.start();
dm_watchFieldsAndNow(ll("input", "escapeBrackets"), rstProcessInput);
dm_vmBus_onMessage("unclearListChanged", (mod, name) -> {
if (eqic((String) name, "Patterns"))
rstProcessInput.trigger();
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public JComponent visualize() {
return northCenterAndSouthWithMargins(jCenteredSection("Input", centerAndEastWithMargins(dm_centeredTextField("input"), jPopDownButton_noText(dm_boolFieldPopupMenuItem("escapeBrackets")))), scp = singleComponentPanel(makeTree()), jCenteredSection("Grouped", dm_label("selectedGrouped")));
}
public JTree makeTree() {
tree = jDynamicTree(root, x -> x.children());
onTreeSelectionChanged(tree, new Runnable() {
public void run() {
try {
Base base = (Base) (jtree_selectedUserObject(tree));
setField("selectedGrouped", base == null ? null : base.grouped());
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Base base = (Base) (jtree_selectedUserObject(tree));\r\n setField(selecte...";
}
});
return tree;
}
public List defaultPatterns() {
return dm_getUnclearList("patterns");
}
public Config defaultConfig() {
return new Config(defaultPatterns());
}
public Config makeConfig(List patternsToTry) {
return new Config(patternsToTry);
}
public void processInput() {
setField("root", parse(escapeBrackets ? ai_escapeBrackets(input) : input));
setSCPComponent(scp, makeTree());
}
public TryPatterns parse(String s, Object... __) {
Config config = (Config) (optPar("config", __));
Collection patterns = (Collection) (optPar("patterns", __));
if (config == null)
config = patterns != null ? new Config(asList(patterns)) : defaultConfig();
return new TryPatterns(config, s);
}
public Collection parseToGroupings(String s, Object... __) {
return parse(s, __).allGroupings();
}
public Collection>> parseToGroupingsWithUsedPatterns(String s, Object... __) {
return parse(s, __).allGroupingsWithUsedPatterns();
}
public TryPatterns root() {
return root;
}
public List allGroupings() {
return root().allGroupings();
}
public List>> allGroupingsWithUsedPatterns() {
return root().allGroupingsWithUsedPatterns();
}
}
static public boolean _moduleClass_TopDownParsing = true;
static public void _onLoad_initUtils() {
utils.__javax = javax();
}
static public void _onLoad_defaultClassFinder() {
setDefaultClassFinder(new F1() {
public Class get(String name) {
try {
Class c = findClass_fullName(name);
if (c != null)
return c;
if (startsWith(name, "main$"))
return loadableUtils.utils.findClass_fullName("loadableUtils.utils" + substring(name, 4));
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Class c = findClass_fullName(name);\r\n if (c != null) ret c;\r\n if (start...";
}
});
}
static public Object callF(Object f, Object... args) {
try {
if (f instanceof String)
return callMC((String) f, args);
return x30_util.callF(f, args);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public A callF(F0 f) {
return f == null ? null : f.get();
}
static public A callF(IF0 f) {
return f == null ? null : f.get();
}
static public B callF(F1 f, A a) {
return f == null ? null : f.get(a);
}
static public B callF(IF1 f, A a) {
return f == null ? null : f.get(a);
}
static public void callF(VF1 f, A a) {
if (f != null)
f.get(a);
}
static public Object callMC(String method, Object... args) {
return call(mc(), method, args);
}
static public Object call(Object o) {
return callF(o);
}
static public Object call(Object o, String method, Object... args) {
return call_withVarargs(o, method, args);
}
static public String programID() {
return getProgramID();
}
static public String programID(Object o) {
return getProgramID(o);
}
static volatile public StringBuffer local_log = new StringBuffer();
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((endsWithLetterOrDigit(s) ? s + ": " : s) + o);
return o;
}
static public A print(A o) {
ping_okInCleanUp();
if (print_silent)
return o;
String s = String.valueOf(o) + "\n";
print_noNewLine(s);
return o;
}
static public void print_noNewLine(String s) {
Object f = getThreadLocal(print_byThread_dontCreate());
if (f == null)
f = print_allThreads;
if (f != null)
if (isFalse(f instanceof F1 ? ((F1) f).get(s) : callF(f, s)))
return;
print_raw(s);
}
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);
System.out.print(s);
}
static public void print_autoRotate() {
}
static public AutoCloseable tempInterceptPrintIfNotIntercepted(F1 f) {
return print_byThread().get() == null ? tempInterceptPrint(f) : null;
}
static public ReliableSingleThread dm_rstWithPreDelay(int delay, Runnable r) {
return dm_rstWithDelay(delay, r);
}
static public ReliableSingleThread dm_rstWithPreDelay(double delay, Runnable r) {
return dm_rstWithDelay(delay, r);
}
static public ReliableSingleThread dm_rstWithPreDelay(DynModule m, int delay, Runnable r) {
return dm_rstWithDelay(m, delay, r);
}
static public ReliableSingleThread dm_rstWithPreDelay(DynModule m, double seconds, Runnable r) {
return dm_rstWithDelay(m, seconds, r);
}
static public ReliableSingleThread dm_rstWithPreDelay(DynModule m, Runnable r, double seconds) {
return dm_rstWithDelay(m, r, seconds);
}
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 String shortClassName(Object o) {
if (o == null)
return null;
Class c = o instanceof Class ? (Class) o : o.getClass();
String name = c.getName();
return shortenClassName(name);
}
static public boolean eq(Object a, Object b) {
return a == b || (a == null ? b == null : b != null && a.equals(b));
}
static public int boostHashCombine(int a, int b) {
return a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2));
}
static public int _hashCode(Object a) {
return a == null ? 0 : a.hashCode();
}
static public List map(Iterable l, Object f) {
return map(f, l);
}
static public List map(Object f, Iterable l) {
List x = emptyList(l);
if (l != null)
for (Object o : l) x.add(callF(f, o));
return x;
}
static public List map(Iterable l, F1 f) {
return map(f, l);
}
static public List map(F1 f, Iterable l) {
List x = emptyList(l);
if (l != null)
for (A o : l) x.add(callF(f, o));
return x;
}
static public List map(IF1 f, Iterable l) {
return map(l, f);
}
static public List map(Iterable l, IF1 f) {
List x = emptyList(l);
if (l != null)
for (A o : l) x.add(f.get(o));
return x;
}
static public List map(IF1 f, A[] l) {
return map(l, f);
}
static public List map(A[] l, IF1 f) {
List x = emptyList(l);
if (l != null)
for (A o : l) x.add(f.get(o));
return x;
}
static public List map(Object f, Object[] l) {
return map(f, asList(l));
}
static public List map(Object[] l, Object f) {
return map(f, l);
}
static public List map(Object f, Map map) {
return map(map, f);
}
static public List map(Map map, Object f) {
List x = new ArrayList();
if (map != null)
for (Object _e : map.entrySet()) {
Map.Entry e = (Map.Entry) _e;
x.add(callF(f, e.getKey(), e.getValue()));
}
return x;
}
static public List map(Map map, IF2 f) {
return map(map, (Object) f);
}
static public String shortName(Object o) {
return shortClassName(o);
}
static public String quote(Object o) {
if (o == null)
return "null";
return quote(str(o));
}
static public String quote(String s) {
if (s == null)
return "null";
StringBuilder out = new StringBuilder((int) (l(s) * 1.5 + 2));
quote_impl(s, out);
return out.toString();
}
static public void quote_impl(String s, StringBuilder out) {
out.append('"');
int l = s.length();
for (int i = 0; i < l; i++) {
char c = s.charAt(i);
if (c == '\\' || c == '"')
out.append('\\').append(c);
else if (c == '\r')
out.append("\\r");
else if (c == '\n')
out.append("\\n");
else if (c == '\0')
out.append("\\0");
else
out.append(c);
}
out.append('"');
}
static public boolean empty(Collection c) {
return c == null || c.isEmpty();
}
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(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(File f) {
return getFileSize(f) == 0;
}
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));
}
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 quoteAll(Collection l) {
List x = new ArrayList();
for (String s : l) x.add(quote(s));
return x;
}
static public String format3_round(String pat, String... args) {
if (empty(args))
return pat;
List tok = javaTok(pat);
int argidx = 0;
for (int i = 1; i < tok.size(); i += 2) if (tok.get(i).equals("*"))
tok.set(i, roundOpt(argidx < args.length ? args[argidx++] : "null"));
return join(tok);
}
static public String format3_round(String pat, List args) {
return format3_round(pat, asStringArray(args));
}
static public String[] toStringArray(Collection c) {
String[] a = new String[l(c)];
Iterator it = c.iterator();
for (int i = 0; i < l(a); i++) a[i] = it.next();
return a;
}
static public String[] toStringArray(Object o) {
if (o instanceof String[])
return (String[]) o;
else if (o instanceof Collection)
return toStringArray((Collection) o);
else
throw fail("Not a collection or array: " + getClassName(o));
}
static public IterableIterator> allCombinations(final List> base) {
if (anyListEmpty(base))
return emptyItIt();
return iteratorFromFunction(new F0>() {
final public int n = l(base);
public List l = rep((Integer) 0, n);
public List get() {
if (l == null)
return null;
List out = makeList();
int i = 0;
while (i < n) {
int n = l.get(i);
if (n + 1 < l(base.get(i))) {
l.set(i, n + 1);
break;
}
l.set(i++, 0);
}
if (i >= n)
l = null;
return out;
}
public List makeList() {
List list = emptyList(n);
for (int i = 0; i < n; i++) list.add(base.get(i).get(l.get(i)));
return list;
}
});
}
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 List pairsA(Collection> l) {
return firstOfPairs(l);
}
static public Set concatListsAsCISet(Collection extends Collection> lists) {
return concatListsToCISet(lists);
}
static public List itemPlusList(A a, Collection l) {
return concatLists(ll(a), l);
}
static public TreeSet litciset(String... items) {
TreeSet set = caseInsensitiveSet();
for (String a : items) set.add(a);
return set;
}
static public List pairsB(Collection> l) {
return secondOfPairs(l);
}
static public String tok_deRoundOrCurlyBracket(String s) {
return isCurlyBraced(s) || tok_isRoundBracketed(s) ? join(dropFirstThreeAndLastThree(javaTok(s))) : s;
}
static public List> matchesToStringLists(Iterable l) {
return lambdaMap(__26 -> matchesToStringList(__26), l);
}
static public List flexMatchIC_withBrackets_all_autoPunctuation(String pat, String input, Object... __) {
return starPatternHasPunctuation(pat) ? flexMatchIC_withBrackets_all_honorPunctuation(pat, input, __) : flexMatchIC_withBrackets_all(pat, input, __);
}
static public A setAll(A o, Map fields) {
if (fields == null)
return o;
for (String field : keys(fields)) set(o, field, fields.get(field));
return o;
}
static public A setAll(A o, Object... values) {
failIfOddCount(values);
for (int i = 0; i + 1 < l(values); i += 2) {
String field = (String) values[i];
Object value = values[i + 1];
set(o, field, value);
}
return o;
}
static public String nMatches(long n) {
return n2(n, "match", "matches");
}
static public String nMatches(Collection l) {
return nMatches(l(l));
}
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 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 A first(Pair p) {
return p == null ? null : p.a;
}
static public Byte first(byte[] l) {
return empty(l) ? null : l[0];
}
static public List uniquifyCI(Collection l) {
TreeSet set = ciSet();
List out = new ArrayList();
for (String a : unnull(l)) if (set.add(a))
out.add(a);
return out;
}
static public List listPlusItem(Collection l, A a) {
return listPlus(l, a);
}
static public List concatMap(Object f, Iterable l) {
return concatLists(map(f, l));
}
static public List concatMap(Iterable l, Object f) {
return concatMap(f, l);
}
static public List concatMap(Object f, Object[] l) {
return concatLists(map(f, l));
}
static public List concatMap(Object[] l, Object f) {
return concatMap(f, l);
}
static public > List concatMap(Iterable l, IF1 f) {
return concatMap(l, (Object) f);
}
static public List uniquifyByFieldCI(Iterable c, String field) {
return valuesList(indexByFieldCI(c, field));
}
static public List uniquifyByFieldCI(String field, Iterable c) {
return uniquifyByFieldCI(c, field);
}
static public String a(String noun) {
if (eq(noun, ""))
return "?";
return ("aeiou".indexOf(noun.charAt(0)) >= 0 ? "an " : "a ") + noun;
}
static public String a(String contents, Object... params) {
return htag("a", contents, params);
}
static public Set emptySet() {
return new HashSet();
}
static public void dm_watchFieldsAndNow(Collection fields, Runnable onChange) {
for (String field : unnull(fields)) dm_watchField(field, onChange);
dm_q(onChange);
}
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 AutoCloseable dm_vmBus_onMessage(final String msg, final VF1 onMessage) {
return dm_ownResource(vmBus_onMessage(msg, onMessage));
}
static public AutoCloseable dm_vmBus_onMessage(final String msg, final IVF1 onMessage) {
return dm_ownResource(vmBus_onMessage(msg, ivf1ToVF1(onMessage)));
}
static public AutoCloseable dm_vmBus_onMessage(final String msg, final IVF2 onMessage) {
return dm_ownResource(vmBus_onMessage(msg, ivf2ToVF2(onMessage)));
}
static public AutoCloseable dm_vmBus_onMessage(String msg, final VF2 onMessage) {
return dm_ownResource(vmBus_onMessage(msg, onMessage));
}
static public AutoCloseable dm_vmBus_onMessage(String msg, Runnable onMessage) {
return dm_ownResource(vmBus_onMessage(msg, onMessage));
}
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(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 JPanel northCenterAndSouthWithMargins(Component n, Component c, Component s) {
return applyDefaultMargin(northCenterAndSouth(withBottomMargin(n), c, withTopMargin(s)));
}
static public JPanel jCenteredSection(Component c) {
return jCenteredSection("", c);
}
static public JPanel jCenteredSection(final String title, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel p = jSection(title, c);
((TitledBorder) p.getBorder()).setTitleJustification(TitledBorder.CENTER);
return p;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel p = jSection(title, c);\r\n ((TitledBorder) p.getBorder()).setTitleJu...";
}
});
}
static public JPanel jCenteredSection(String title) {
return jCenteredSection(title, jpanel());
}
static public JPanel centerAndEastWithMargins(Component c, Component e) {
return applyDefaultMargin(centerAndEast(c, withLeftMargin(e)));
}
static public JTextField dm_centeredTextField(String field) {
return centerTextField(dm_textField(field));
}
static public JButton jPopDownButton_noText(final Object... menuParams) {
return toolTip("Additional commands", jPopDownButton("", menuParams));
}
static public IVF1 dm_boolFieldPopupMenuItem(String field, Object... __) {
final DynModule m = dm_current_mandatory();
String humanized = humanizeFormLabel(field);
return menu -> menu.add(jCheckBoxMenuItem(humanized, (boolean) _get(m, field), new VF1() {
public void get(Boolean b) {
try {
m.setField(field, b);
callF(optPar(__, "onSet"));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "m.setField(field, b);\r\n callF(optPar(_, 'onSet));";
}
}));
}
static public SingleComponentPanel singleComponentPanel() {
return singleComponentPanel(null);
}
static public SingleComponentPanel singleComponentPanel(final Component c) {
return swing(new F0() {
public SingleComponentPanel get() {
try {
return new SingleComponentPanel(c);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret new SingleComponentPanel(c);";
}
});
}
static public JLabel dm_label(String fieldName) {
return dm_fieldLabel(fieldName);
}
static public > JTree jDynamicTree(A root, IF1 makeChildren, Object... __) {
return jDynamicTree(root, toF1(makeChildren), __);
}
static public > JTree jDynamicTree(final A root, final F1 makeChildren, final Object... __) {
return swing(new F0() {
public JTree get() {
try {
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(root);
rootNode.add(new DefaultMutableTreeNode(jDynamicTree_dummy()));
final JTree tree = new JTree(rootNode);
tree.setShowsRootHandles(true);
tree.collapseRow(0);
final boolean keepChildrenOnCollapse = optParam(__, "keepChildrenOnCollapse", false);
boolean makeChildrenIsFast = boolParam("makeChildrenIsFast", __) || makeChildren == null;
boolean debug = boolPar("debug", __);
class jDynamicTree_Listener implements TreeWillExpandListener {
public void treeWillCollapse(TreeExpansionEvent e) {
}
public void treeWillExpand(TreeExpansionEvent e) {
try {
if (debug)
print("treeWillExpand");
DefaultMutableTreeNode node = (DefaultMutableTreeNode) (e.getPath().getLastPathComponent());
if (!keepChildrenOnCollapse || jDynamicTree_isInDummyState(node)) {
List l = asList(callF(makeChildren, (A) node.getUserObject()));
if (makeChildrenIsFast ? replaceTreeNodeChildren_withDummyChild2(node, l, jDynamicTree_dummy(), makeChildren) : replaceTreeNodeChildren_withDummyChild(node, l, jDynamicTree_dummy()))
((DefaultTreeModel) tree.getModel()).nodeStructureChanged(node);
}
} catch (Throwable __e) {
_handleException(__e);
}
}
}
tree.addTreeWillExpandListener(new jDynamicTree_Listener());
return tree;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "DefaultMutableTreeNode rootNode = new(root);\r\n rootNode.add(new DefaultMut...";
}
});
}
static public void onTreeSelectionChanged(final JTree tree, final Runnable r) {
if (tree != null && r != null) {
swing(new Runnable() {
public void run() {
try {
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
pcallF(r);
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "tree.addTreeSelectionListener(new TreeSelectionListener {\r\n public void ...";
}
});
}
}
static public Object jtree_selectedUserObject(JTree tree) {
Object node = getSelectedTreeNode(tree);
if (node instanceof DefaultMutableTreeNode)
return ((DefaultMutableTreeNode) node).getUserObject();
return null;
}
static public List dm_getUnclearList(String type) {
return collect("name", (List) dm_call(dm_findUnclearListModule(type), "list"));
}
static public String ai_escapeBrackets(String s) {
return simpleSpaces_trim(replace_multi(s, "(", " opening_bracket ", ")", " closing_bracket "));
}
static public void setSCPComponent(SingleComponentPanel scp, Component c) {
if (scp != null)
scp.setComponent(c);
}
static public A optPar(ThreadLocal tl, A defaultValue) {
A a = tl.get();
if (a != null) {
tl.set(null);
return a;
}
return defaultValue;
}
static public A optPar(ThreadLocal tl) {
return optPar(tl, null);
}
static public Object optPar(Object[] params, String name) {
return optParam(params, name);
}
static public Object optPar(String name, Object[] params) {
return optParam(params, name);
}
static public Object optPar(String name, Map params) {
return optParam(name, params);
}
static public A optPar(Object[] params, String name, A defaultValue) {
return optParam(params, name, defaultValue);
}
static public A optPar(String name, Object[] params, A defaultValue) {
return optParam(params, name, defaultValue);
}
static public ArrayList asList(A[] a) {
return a == null ? new ArrayList () : new ArrayList (Arrays.asList(a));
}
static public ArrayList asList(int[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (int i : a) l.add(i);
return l;
}
static public ArrayList asList(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(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(Enumeration e) {
ArrayList l = new ArrayList();
if (e != null)
while (e.hasMoreElements()) l.add(e.nextElement());
return l;
}
static public Class javax() {
return getJavaX();
}
static public void setDefaultClassFinder(Object cf) {
_defaultClassFinder_value = cf;
}
static public HashMap findClass_fullName_cache = new HashMap();
static public Class findClass_fullName(String name) {
synchronized (findClass_fullName_cache) {
if (findClass_fullName_cache.containsKey(name))
return findClass_fullName_cache.get(name);
Class c;
try {
c = Class.forName(name);
} catch (ClassNotFoundException e) {
c = null;
}
findClass_fullName_cache.put(name, c);
return c;
}
}
static public boolean startsWith(String a, String b) {
return a != null && a.startsWith(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;
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 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;
if (x >= s.length())
return "";
if (y < x)
y = x;
if (y > s.length())
y = s.length();
return s.substring(x, y);
}
static public String substring(String s, CharSequence l) {
return substring(s, l(l));
}
static public Class mc() {
return main.class;
}
static public Object call_withVarargs(Object o, String method, Object... args) {
try {
if (o == null)
return null;
if (o instanceof Class) {
Class c = (Class) o;
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findStaticMethod(method, args);
if (me != null)
return invokeMethod(me, null, args);
List methods = cache.cache.get(method);
if (methods != null)
methodSearch: for (Method m : methods) {
{
if (!(m.isVarArgs()))
continue;
}
{
if (!(isStaticMethod(m)))
continue;
}
Object[] newArgs = massageArgsForVarArgsCall(m, args);
if (newArgs != null)
return invokeMethod(m, null, newArgs);
}
throw fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not found");
} else {
Class c = o.getClass();
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(method, args);
if (me != null)
return invokeMethod(me, o, args);
List methods = cache.cache.get(method);
if (methods != null)
methodSearch: for (Method m : methods) {
{
if (!(m.isVarArgs()))
continue;
}
Object[] newArgs = massageArgsForVarArgsCall(m, args);
if (newArgs != null)
return invokeMethod(m, o, newArgs);
}
throw fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not found");
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Object _defaultClassFinder_value = defaultDefaultClassFinder();
static public Object _defaultClassFinder() {
return _defaultClassFinder_value;
}
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 boolean endsWithLetterOrDigit(String s) {
return s != null && s.length() > 0 && Character.isLetterOrDigit(s.charAt(s.length() - 1));
}
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 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 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 ReliableSingleThread dm_rstWithDelay(int delay, Runnable r) {
return dm_rst(dm_current_mandatory(), rstWithPostDelay(delay, r));
}
static public ReliableSingleThread dm_rstWithDelay(double delay, Runnable r) {
return dm_rst(dm_current_mandatory(), rstWithPostDelay(delay, r));
}
static public ReliableSingleThread dm_rstWithDelay(DynModule m, int delay, Runnable r) {
return dm_rst(m, rstWithDelay(delay, r));
}
static public ReliableSingleThread dm_rstWithDelay(DynModule m, double seconds, Runnable r) {
return dm_rst(m, rstWithDelay(seconds, r));
}
static public ReliableSingleThread dm_rstWithDelay(DynModule m, Runnable r, double seconds) {
return dm_rstWithDelay(m, seconds, r);
}
static public void _handleError(Error e) {
call(javax(), "_handleError", e);
}
static public String shortenClassName(String name) {
if (name == null)
return null;
int i = lastIndexOf(name, "$");
if (i < 0)
i = lastIndexOf(name, ".");
return i < 0 ? name : substring(name, i + 1);
}
static public String str(Object o) {
return o == null ? "null" : o.toString();
}
static public String str(char[] c) {
return new String(c);
}
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 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 int javaTok_n, javaTok_elements;
static public boolean javaTok_opt = false;
static public List javaTok(String s) {
++javaTok_n;
ArrayList tok = new ArrayList();
int l = s == null ? 0 : s.length();
int i = 0, n = 0;
while (i < l) {
int j = i;
char c, d;
while (j < l) {
c = s.charAt(j);
d = j + 1 >= l ? '\0' : s.charAt(j + 1);
if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
++j;
else if (c == '/' && d == '*') {
do ++j; while (j < l && !s.substring(j, Math.min(j + 2, l)).equals("*/"));
j = Math.min(j + 2, l);
} else if (c == '/' && d == '/') {
do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0);
} else
break;
}
tok.add(javaTok_substringN(s, i, j));
++n;
i = j;
if (i >= l)
break;
c = s.charAt(i);
d = i + 1 >= l ? '\0' : s.charAt(i + 1);
if (c == '\'' && Character.isJavaIdentifierStart(d) && i + 2 < l && "'\\".indexOf(s.charAt(i + 2)) < 0) {
j += 2;
while (j < l && Character.isJavaIdentifierPart(s.charAt(j))) ++j;
} else if (c == '\'' || c == '"') {
char opener = c;
++j;
while (j < l) {
int c2 = s.charAt(j);
if (c2 == opener || c2 == '\n' && opener == '\'') {
++j;
break;
} else if (c2 == '\\' && j + 1 < l)
j += 2;
else
++j;
}
} else if (Character.isJavaIdentifierStart(c))
do ++j; while (j < l && (Character.isJavaIdentifierPart(s.charAt(j)) || s.charAt(j) == '\''));
else if (Character.isDigit(c)) {
do ++j; while (j < l && Character.isDigit(s.charAt(j)));
if (j < l && s.charAt(j) == 'L')
++j;
} else if (c == '[' && d == '[') {
do ++j; while (j + 1 < l && !s.substring(j, j + 2).equals("]]"));
j = Math.min(j + 2, l);
} else if (c == '[' && d == '=' && i + 2 < l && s.charAt(i + 2) == '[') {
do ++j; while (j + 2 < l && !s.substring(j, j + 3).equals("]=]"));
j = Math.min(j + 3, l);
} else
++j;
tok.add(javaTok_substringC(s, i, j));
++n;
i = j;
}
if ((tok.size() % 2) == 0)
tok.add("");
javaTok_elements += tok.size();
return tok;
}
static public List javaTok(List tok) {
return javaTokWithExisting(join(tok), tok);
}
static public String roundOpt(String s) {
return roundBracketIfMoreThanOneToken(s);
}
static public String[] asStringArray(Collection c) {
return toStringArray(c);
}
static public String[] asStringArray(Object o) {
return toStringArray(o);
}
static public String getClassName(Object o) {
return o == null ? "null" : o instanceof Class ? ((Class) o).getName() : o.getClass().getName();
}
static public boolean anyListEmpty(Iterable extends Collection> l) {
if (l != null)
for (Collection c : l) if (empty(c))
return true;
return false;
}
static public IterableIterator emptyItIt() {
return emptyIterableIterator();
}
static public IterableIterator iteratorFromFunction(final Object f) {
class IFF extends IterableIterator {
public A a;
public boolean done = false;
public boolean hasNext() {
getNext();
return !done;
}
public A next() {
getNext();
if (done)
throw fail();
A _a = a;
a = null;
return _a;
}
public void getNext() {
if (done || a != null)
return;
a = (A) callF(f);
done = a == null;
}
}
;
return new IFF();
}
static public IterableIterator iteratorFromFunction(final F0 f) {
return iteratorFromFunction_f0(f);
}
static public String rep(int n, char c) {
return repeat(c, n);
}
static public String rep(char c, int n) {
return repeat(c, n);
}
static public List rep(A a, int n) {
return repeat(a, n);
}
static public List rep(int n, A a) {
return repeat(n, a);
}
static public JList makeList(String... strings) {
JList list = new JList();
fillListWithStrings(list, strings);
return list;
}
static public List firstOfPairs(Collection> l) {
List out = new ArrayList();
for (Pair p : unnull(l)) out.add(firstOfPair(p));
return out;
}
static public Set concatListsToCISet(Collection extends Collection> lists) {
Set l = ciSet();
for (Collection list : lists) if (list != null)
l.addAll(list);
return l;
}
static public List concatLists(Collection ... lists) {
List l = new ArrayList();
if (lists != null)
for (Collection list : lists) if (list != null)
l.addAll(list);
return l;
}
static public List concatLists(Collection extends Collection > lists) {
List l = new ArrayList();
if (lists != null)
for (Collection list : lists) if (list != null)
l.addAll(list);
return l;
}
static public TreeSet caseInsensitiveSet() {
return caseInsensitiveSet_treeSet();
}
static public TreeSet caseInsensitiveSet(Collection c) {
return caseInsensitiveSet_treeSet(c);
}
static public TreeSet treeSet() {
return new TreeSet();
}
static public List secondOfPairs(Collection> l) {
return map("secondOfPair", l);
}
static public boolean isCurlyBraced(String s) {
List tok = tok_combineCurlyBrackets_keep(javaTok(s));
return l(tok) == 3 && startsWithAndEndsWith(tok.get(1), "{", "}");
}
static public boolean tok_isRoundBracketed(String s) {
List tok = tok_combineRoundBrackets_keep(javaTok(s));
return l(tok) == 3 && startsWithAndEndsWith(tok.get(1), "(", ")");
}
static public List dropFirstThreeAndLastThree(List l) {
return dropFirstAndLast(3, l);
}
static public List lambdaMap(IF1 f, Iterable l) {
return map(l, f);
}
static public List matchesToStringList(Matches m) {
return m == null ? null : toList(m.m);
}
static public boolean starPatternHasPunctuation(String s) {
for (String t : javaTokC_cached(s)) if (l(t) == 1 && !startsWithLetterOrDigit(t) && !eqOneOf(t, "*", "<", ">", "(", ")", "{", "}"))
return true;
return false;
}
static public List flexMatchIC_withBrackets_all_honorPunctuation(String pat, String input, Object... __) {
return flexMatchIC_withBrackets_all(pat, javaTokWithBrackets(pat), javaTokWithBrackets(input), __);
}
static public List flexMatchIC_withBrackets_all(String pat, String input, Object... __) {
List out = new ArrayList();
flexMatchIC_withBrackets_iterate(pat, input, vfAddToCollection(out), __);
return out;
}
static public List flexMatchIC_withBrackets_all(String pat, List tokPat, List tokInput, Object... __) {
List out = new ArrayList();
flexMatchIC_iterate(pat, tokPat, tokInput, vfAddToCollection(out), __);
return out;
}
static public Set keys(Map map) {
return map == null ? new HashSet() : map.keySet();
}
static public Set keys(Object map) {
return keys((Map) map);
}
static public Set keys(MultiSet ms) {
return ms.keySet();
}
static public A set(A o, String field, Object value) {
if (o == null)
return null;
if (o instanceof Class)
set((Class) o, field, value);
else
try {
Field f = set_findField(o.getClass(), field);
makeAccessible(f);
smartSet(f, o, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
return o;
}
static public void set(Class c, String field, Object value) {
if (c == null)
return;
try {
Field f = set_findStaticField(c, field);
makeAccessible(f);
smartSet(f, null, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static public Field set_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Static field '" + field + "' not found in " + c.getName());
}
static public Field set_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Field '" + field + "' not found in " + c.getName());
}
static public void failIfOddCount(Object... list) {
if (odd(l(list)))
throw fail("Odd list size: " + list);
}
static public String n2(long l) {
return formatWithThousands(l);
}
static public String n2(Collection l) {
return n2(l(l));
}
static public String n2(double l, String singular) {
return n2(l, singular, singular + "s");
}
static public String n2(double l, String singular, String plural) {
if (fraction(l) == 0)
return n2((long) l, singular, plural);
else
return l + " " + plural;
}
static public String n2(long l, String singular, String plural) {
return n_fancy2(l, singular, plural);
}
static public String n2(long l, String singular) {
return n_fancy2(l, singular, singular + "s");
}
static public String n2(Collection l, String singular) {
return n2(l(l), singular);
}
static public String n2(Collection l, String singular, String plural) {
return n_fancy2(l, singular, plural);
}
static public String n2(Map m, String singular, String plural) {
return n_fancy2(m, singular, plural);
}
static public String n2(Map m, String singular) {
return n2(l(m), singular);
}
static public String n2(Object[] a, String singular) {
return n2(l(a), singular);
}
static public String n2(Object[] a, String singular, String plural) {
return n_fancy2(a, singular, plural);
}
static public String n2(MultiSet ms, String singular, String plural) {
return n_fancy2(ms, singular, plural);
}
static public TreeSet ciSet() {
return caseInsensitiveSet();
}
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 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[]) new Object[0] : 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 Pair unnull(Pair p) {
return p != null ? p : new Pair(null, null);
}
static public List listPlus(Collection l, A... more) {
return concatLists(l, asList(more));
}
static public List valuesList(Map map) {
return cloneListSynchronizingOn(values(map), map);
}
static public Map indexByFieldCI(Iterable c, String field) {
Map map = ciMap();
for (A a : c) {
String val = getString(a, field);
if (val != null)
map.put(val, a);
}
return map;
}
static public Map indexByFieldCI(String field, Iterable c) {
return indexByFieldCI(c, field);
}
static public String htag(String tag) {
return htag(tag, "");
}
static public String htag(String tag, Object contents, Object... params) {
String openingTag = hopeningTag(tag, params);
String s = str(contents);
if (empty(s) && neqic(tag, "script"))
return dropLast(openingTag) + "/>";
return openingTag + s + "" + tag + ">";
}
static public void dm_watchField(String field, Runnable onChange) {
new Dyn_FieldWatcher(dm_current_mandatory(), field, onChange);
}
static public Q dm_q() {
return dm_current_mandatory().q();
}
static public void dm_q(Runnable r) {
dm_inQ(r);
}
static public void dm_q(DynModule module, Runnable r) {
module.q().add(r);
}
static public A dm_ownResource(A resource) {
dm_currentModuleMandatory().ownResource(resource);
return resource;
}
static public AutoCloseable vmBus_onMessage(final String msg, final VF1 onMessage) {
Map map = vm_busListenersByMessage_live();
synchronized (map) {
Set listeners = map.get(msg);
if (listeners == null)
map.put(msg, listeners = syncIdentityHashSet());
return tempAdd(listeners, new VF2() {
public void get(String _msg, Object arg) {
try {
callF(onMessage, arg);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, arg)";
}
});
}
}
static public AutoCloseable vmBus_onMessage(String msg, final VF2 onMessage) {
return vmBus_onMessage(msg, new VF1() {
public void get(Object[] o) {
try {
callF(onMessage, first(o), second(o));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, first(o), second(o));";
}
});
}
static public AutoCloseable vmBus_onMessage(String msg, final IVF2 onMessage) {
return vmBus_onMessage(msg, new VF1() {
public void get(Object[] o) {
try {
callF(onMessage, first(o), second(o));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, first(o), second(o));";
}
});
}
static public AutoCloseable vmBus_onMessage(String msg, Runnable onMessage) {
return vmBus_onMessage(msg, runnableToVF1(onMessage));
}
static public VF1 ivf1ToVF1(IVF1 f) {
return f == null ? null : new VF1 () {
public void get(A a) {
try {
f.get(a);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "f.get(a)";
}
};
}
static public VF2 ivf2ToVF2(IVF2 f) {
return f == null ? null : new VF2 () {
public void get(A a, B b) {
try {
f.get(a, b);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "f.get(a, b)";
}
};
}
static public String asString(Object o) {
return o == null ? null : o.toString();
}
static public A applyDefaultMargin(final A c) {
if (c != null) {
swing(new Runnable() {
public void run() {
try {
c.setBorder(BorderFactory.createEmptyBorder(withMargin_defaultWidth, withMargin_defaultWidth, withMargin_defaultWidth, withMargin_defaultWidth));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "c.setBorder(BorderFactory.createEmptyBorder(withMargin_defaultWidth, withMarg...";
}
});
}
return c;
}
static public JPanel northCenterAndSouth(Component n, Component c, Component s) {
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.NORTH, wrap(n));
panel.add(BorderLayout.CENTER, wrap(c));
panel.add(BorderLayout.SOUTH, wrap(s));
return panel;
}
static public int withBottomMargin_defaultWidth = 6;
static public JPanel withBottomMargin(Component c) {
return withBottomMargin(withBottomMargin_defaultWidth, c);
}
static public JPanel withBottomMargin(final int w, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createEmptyBorder(0, 0, w, 0));
p.add(c);
return p;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel p = new JPanel(new BorderLayout);\r\n p.setBorder(BorderFactory.creat...";
}
});
}
static public int withTopMargin_defaultWidth = 6;
static public JPanel withTopMargin(Component c) {
return withTopMargin(withTopMargin_defaultWidth, c);
}
static public JPanel withTopMargin(final int w, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createEmptyBorder(w, 0, 0, 0));
p.add(c);
return p;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel p = new JPanel(new BorderLayout);\r\n p.setBorder(BorderFactory.creat...";
}
});
}
static public Object swing(Object f) {
return swingAndWait(f);
}
static public A swing(F0 f) {
return (A) swingAndWait(f);
}
static public A swing(IF0 f) {
return (A) swingAndWait(f);
}
static public JPanel jSection(Component c) {
return jSection("", c);
}
static public JPanel jSection(final String title, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
Border border = BorderFactory.createBevelBorder(BevelBorder.LOWERED);
border = BorderFactory.createTitledBorder(border, title);
JSection panel = new JSection(c);
panel.setBorder(border);
return panel;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Border border = BorderFactory.createBevelBorder(BevelBorder.LOWERED);\r\n bo...";
}
});
}
static public JPanel jSection(String title) {
return jSection(title, jpanel());
}
static public JPanel jpanel(LayoutManager layout) {
return swingNu(JPanel.class, layout);
}
static public JPanel jpanel() {
return swingNu(JPanel.class);
}
static public JPanel centerAndEast(final Component c, final Component e) {
return swing(new F0() {
public JPanel get() {
try {
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.CENTER, wrap(c));
panel.add(BorderLayout.EAST, wrap(e));
return panel;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel panel = new JPanel(new BorderLayout);\r\n panel.add(BorderLayout.CENT...";
}
});
}
static public int withLeftMargin_defaultWidth = 6;
static public JPanel withLeftMargin(Component c) {
return withLeftMargin(withLeftMargin_defaultWidth, c);
}
static public JPanel withLeftMargin(final int margin, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createEmptyBorder(0, margin, 0, 0));
p.add(c);
return p;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel p = new JPanel(new BorderLayout);\r\n p.setBorder(BorderFactory.creat...";
}
});
}
static public A centerTextField(A tf) {
tf.setHorizontalAlignment(JTextField.CENTER);
return tf;
}
static public JTextField dm_textField(String field) {
return dm_fieldTextField(field);
}
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 JButton jPopDownButton(String text, final Object... menuParams) {
return jbutton((empty(text) ? "" : text + " ") + unicode_downPointingTriangle(), new Runnable() {
public void run() {
try {
JPopupMenu menu = new JPopupMenu();
int emptyCount = menu.getComponentCount();
String position = (String) (optPar_ignoreOddLength("position", menuParams));
fillJPopupMenu(menu, paramsWithout(menuParams, "position"));
if (menu.getComponentCount() != emptyCount) {
JButton btn = heldInstance(JButton.class);
int x = 0;
if (eq(position, "center"))
x = (btn.getWidth() - getPreferredWidth(menu)) / 2;
else if (eq(position, "right"))
x = btn.getWidth() - getPreferredWidth(menu);
menu.show(btn, x, btn.getHeight());
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "new JPopupMenu menu;\r\n int emptyCount = menu.getComponentCount();\r\n Str...";
}
});
}
static public Map humanizeFormLabel_replacements = litmap("id", "ID", "md5", "MD5");
static public String humanizeFormLabel(String s) {
if (containsSpace(s))
return s;
return firstToUpper(joinWithSpace(replaceElementsUsingMap(splitCamelCase(s), humanizeFormLabel_replacements)).replace("I D", "ID"));
}
static public JCheckBoxMenuItem jCheckBoxMenuItem(String text, boolean checked, final Object r) {
final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(text, checked);
addActionListener(mi, new Runnable() {
public void run() {
try {
callF(r, isChecked(mi));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(r, isChecked(mi))";
}
});
return mi;
}
static public A _get(List l, int idx) {
return l != null && idx >= 0 && idx < l(l) ? l.get(idx) : null;
}
static public Object _get(Object o, String field) {
return get(o, field);
}
static public Object _get(String field, Object o) {
return get(o, field);
}
static public A _get(A[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : null;
}
static public JLabel dm_fieldLabel(String fieldName) {
return jLiveValueLabel(dm_fieldLiveValue(fieldName));
}
static public F1 toF1(final Object f) {
return functionToF1(f);
}
static public String jDynamicTree_dummy_value = new String("");
static public String jDynamicTree_dummy() {
return jDynamicTree_dummy_value;
}
static public A optParam(ThreadLocal tl, A defaultValue) {
return optPar(tl, defaultValue);
}
static public A optParam(ThreadLocal tl) {
return optPar(tl);
}
static public Object optParam(String name, Map params) {
return mapGet(params, name);
}
static public A optParam(Object[] opt, String name, A defaultValue) {
int n = l(opt);
if (n == 1 && opt[0] instanceof Map) {
Map map = (Map) (opt[0]);
return map.containsKey(name) ? (A) map.get(name) : defaultValue;
}
if (!even(l(opt)))
throw fail("Odd parameter length");
for (int i = 0; i < l(opt); i += 2) if (eq(opt[i], name))
return (A) opt[i + 1];
return defaultValue;
}
static public Object optParam(Object[] opt, String name) {
return optParam(opt, name, null);
}
static public Object optParam(String name, Object[] params) {
return optParam(params, name);
}
static public boolean boolParam(ThreadLocal tl) {
return boolOptParam(tl);
}
static public boolean boolParam(Object[] __, String name) {
return boolOptParam(__, name);
}
static public boolean boolParam(String name, Object[] __) {
return boolOptParam(name, __);
}
static public boolean boolPar(ThreadLocal tl) {
return boolOptParam(tl);
}
static public boolean boolPar(Object[] __, String name) {
return boolOptParam(__, name);
}
static public boolean boolPar(String name, Object[] __) {
return boolOptParam(__, name);
}
static public boolean boolPar(String name, Map __) {
return boolOptParam(name, __);
}
static public boolean boolPar(String name, Object[] params, boolean defaultValue) {
return optParam(params, name, defaultValue);
}
static public boolean jDynamicTree_isInDummyState(DefaultMutableTreeNode node) {
return node.getChildCount() == 1 && ((DefaultMutableTreeNode) node.getChildAt(0)).getUserObject() == jDynamicTree_dummy();
}
static public boolean replaceTreeNodeChildren_withDummyChild2(final DefaultMutableTreeNode node, final List children, final Object dummyChild, final F1 > makeChildren) {
if (node == null)
return false;
return swing(new F0() {
public Boolean get() {
try {
List oldChildren = mapMethod("getUserObject", node.children());
if (eq(oldChildren, children))
return false;
node.removeAllChildren();
for (A c : unnull(children)) {
DefaultMutableTreeNode node2 = new DefaultMutableTreeNode(c);
if (!empty(callF(makeChildren, c)))
node2.add(new DefaultMutableTreeNode(dummyChild));
node.add(node2);
}
return true;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "L oldChildren = mapMethod getUserObject(node.children());\r\n if (eq(oldChil...";
}
});
}
static public boolean replaceTreeNodeChildren_withDummyChild(final DefaultMutableTreeNode node, final List children, final Object dummyChild) {
if (node == null)
return false;
return swing(new F0() {
public Boolean get() {
try {
List oldChildren = mapMethod("getUserObject", node.children());
if (eq(oldChildren, children))
return false;
node.removeAllChildren();
for (Object c : unnull(children)) {
DefaultMutableTreeNode node2 = new DefaultMutableTreeNode(c);
node2.add(new DefaultMutableTreeNode(dummyChild));
node.add(node2);
}
return true;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "L oldChildren = mapMethod('getUserObject, node.children());\r\n if (eq(oldCh...";
}
});
}
static volatile public PersistableThrowable _handleException_lastException;
static public List _handleException_onException = synchroList(ll("printStackTrace2"));
static public void _handleException(Throwable e) {
_handleException_lastException = persistableThrowable(e);
Throwable e2 = innerException(e);
if (e2.getClass() == RuntimeException.class && eq(e2.getMessage(), "Thread cancelled.") || e2 instanceof InterruptedException)
return;
for (Object f : cloneList(_handleException_onException)) try {
callF(f, e);
} catch (Throwable e3) {
printStackTrace2(e3);
}
}
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) {
return null;
}
}
static public B pcallF(F1 f, A a) {
try {
return f == null ? null : f.get(a);
} catch (Throwable __e) {
return null;
}
}
static public void pcallF(VF1 f, A a) {
try {
if (f != null)
f.get(a);
} catch (Throwable __e) {
_handleException(__e);
}
}
static public Object getSelectedTreeNode(JTree tree) {
return tree == null ? null : swingCall(tree, "getLastSelectedPathComponent");
}
static public List collect(Iterable c, String field) {
return collectField(c, field);
}
static public List collect(String field, Iterable c) {
return collectField(c, field);
}
static public Object dm_call(Object moduleOrID, String method, Object... args) {
Object mod = dm_getModule(moduleOrID);
if (mod == null)
return null;
AutoCloseable __1 = dm_enter(mod);
try {
return call_withVarargs(mod, method, args);
} finally {
_close(__1);
}
}
static public String dm_findUnclearListModule(String type) {
return (String) vmBus_query("unclearListModuleOf", type);
}
static public String simpleSpaces_trim(String s) {
return trim(simpleSpaces(s));
}
static public String replace_multi(String s, Collection a, String b) {
if (s == null || empty(a) || b == null)
return s;
for (String aa : a) s = s.replace(aa, b);
return s;
}
static public String replace_multi(String s, String... replacements) {
if (empty(s) || empty(replacements))
return s;
for (int i = 0; i + 1 < l(replacements); i += 2) s = s.replace(replacements[i], replacements[i + 1]);
return s;
}
static public Class __javax;
static public Class getJavaX() {
try {
return __javax;
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public boolean nemptyString(String s) {
return s != null && s.length() > 0;
}
static public int strL(String s) {
return s == null ? 0 : s.length();
}
static public int listL(Collection l) {
return l == null ? 0 : l.size();
}
static public boolean neq(Object a, Object b) {
return !eq(a, b);
}
static 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) {
synchronized (callOpt_cache) {
_MethodCache cache = callOpt_cache.get(c);
if (cache == null)
callOpt_cache.put(c, cache = new _MethodCache(c));
return cache;
}
}
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 isStaticMethod(Method m) {
return methodIsStatic(m);
}
static public Object[] massageArgsForVarArgsCall(Method m, Object[] args) {
Class>[] types = m.getParameterTypes();
int n = types.length - 1, nArgs = args.length;
if (nArgs < n)
return null;
for (int i = 0; i < n; i++) if (!argumentCompatibleWithType(args[i], types[i]))
return null;
Class varArgType = types[n].getComponentType();
for (int i = n; i < nArgs; i++) if (!argumentCompatibleWithType(args[i], varArgType))
return null;
Object[] newArgs = new Object[n + 1];
arraycopy(args, 0, newArgs, 0, n);
Object[] varArgs = arrayOfType(varArgType, nArgs - n);
arraycopy(args, n, varArgs, 0, nArgs - n);
newArgs[n] = varArgs;
return newArgs;
}
static public String joinWithComma(Collection c) {
return join(", ", c);
}
static public String joinWithComma(String... c) {
return join(", ", c);
}
static public String joinWithComma(Pair p) {
return p == null ? "" : joinWithComma(str(p.a), str(p.b));
}
static public List classNames(Collection l) {
return getClassNames(l);
}
static public List classNames(Object[] l) {
return getClassNames(Arrays.asList(l));
}
static public B secondOfPair(Pair p) {
return p == null ? null : p.b;
}
static public int withMargin_defaultWidth = 6;
static public JPanel withMargin(Component c) {
return withMargin(withMargin_defaultWidth, c);
}
static public JPanel withMargin(int w, Component c) {
return withMargin(w, w, c);
}
static public JPanel withMargin(int w, int h, Component c) {
return withMargin(w, h, w, h, c);
}
static public JPanel withMargin(final int top, final int left, final int bottom, final int right, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createEmptyBorder(top, left, bottom, right));
p.add(c);
return p;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel p = new JPanel(new BorderLayout);\r\n p.setBorder(BorderFactory.creat...";
}
});
}
static public Throwable printStackTrace2(Throwable e) {
print(getStackTrace2(e));
return e;
}
static public void printStackTrace2() {
printStackTrace2(new Throwable());
}
static public void printStackTrace2(String msg) {
printStackTrace2(new Throwable(msg));
}
static public Object defaultDefaultClassFinder() {
return new F1() {
public Class get(String name) {
Class c = findClass_fullName(name);
if (c != null)
return c;
if (name.startsWith("loadableUtils.utils$"))
return findClass_fullName("main" + name.substring(19));
return null;
}
};
}
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(Map m) {
return !empty(m);
}
static public boolean nempty(Iterator i) {
return i != null && i.hasNext();
}
static public boolean nempty(Object o) {
return !empty(o);
}
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;
return (o instanceof Class ? (Class) o : o.getClass()).getClassLoader().loadClass("main");
} catch (Exception __e) {
throw rethrow(__e);
}
}
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() {
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 A or(A a, A b) {
return a != null ? a : b;
}
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 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 ReliableSingleThread dm_rst(Runnable r) {
return dm_rst(dm_current_mandatory(), r);
}
static public ReliableSingleThread dm_rst(DynModule mod, Runnable r) {
return dm_rst(mod, new ReliableSingleThread(r));
}
static public ReliableSingleThread dm_rst(DynModule mod, ReliableSingleThread rst) {
rst.enter = dm_rEnter(mod);
return rst;
}
static public ReliableSingleThread rstWithPostDelay(final int delay, final Runnable r) {
return new ReliableSingleThread(new Runnable() {
public void run() {
try {
pcallF(r);
sleep(delay);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "pcallF(r);\r\n sleep(delay);";
}
});
}
static public ReliableSingleThread rstWithPostDelay(double seconds, Runnable r) {
return rstWithPostDelay(toMS_int(seconds), r);
}
static public ReliableSingleThread rstWithDelay(final int delay, final Runnable r) {
return new ReliableSingleThread(new Runnable() {
public void run() {
try {
sleep(delay);
callF(r);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "sleep(delay);\r\n callF(r);";
}
});
}
static public ReliableSingleThread rstWithDelay(double seconds, Runnable r) {
return rstWithDelay(toMS_int(seconds), r);
}
static public int lastIndexOf(String a, String b) {
return a == null || b == null ? -1 : a.lastIndexOf(b);
}
static public int lastIndexOf(String a, char b) {
return a == null ? -1 : a.lastIndexOf(b);
}
static public int max(int a, int b) {
return Math.max(a, b);
}
static public int max(int a, int b, int c) {
return max(max(a, b), c);
}
static public long max(int a, long b) {
return Math.max((long) a, b);
}
static public long max(long a, long b) {
return Math.max(a, b);
}
static public double max(int a, double b) {
return Math.max((double) a, b);
}
static public float max(float a, float b) {
return Math.max(a, b);
}
static public double max(double a, double b) {
return Math.max(a, b);
}
static public int max(Collection c) {
int x = Integer.MIN_VALUE;
for (int i : c) x = max(x, i);
return x;
}
static public double max(double[] c) {
if (c.length == 0)
return Double.MIN_VALUE;
double x = c[0];
for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]);
return x;
}
static public float max(float[] c) {
if (c.length == 0)
return Float.MAX_VALUE;
float x = c[0];
for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]);
return x;
}
static public byte max(byte[] c) {
byte x = -128;
for (byte d : c) if (d > x)
x = d;
return x;
}
static public short max(short[] c) {
short x = -0x8000;
for (short d : c) if (d > x)
x = d;
return x;
}
static public int max(int[] c) {
int x = Integer.MIN_VALUE;
for (int d : c) if (d > x)
x = d;
return x;
}
static public String javaTok_substringN(String s, int i, int j) {
if (i == j)
return "";
if (j == i + 1 && s.charAt(i) == ' ')
return " ";
return s.substring(i, j);
}
static public String javaTok_substringC(String s, int i, int j) {
return s.substring(i, j);
}
static public List javaTokWithExisting(String s, List existing) {
++javaTok_n;
int nExisting = javaTok_opt && existing != null ? existing.size() : 0;
ArrayList tok = existing != null ? new ArrayList(nExisting) : new ArrayList();
int l = s.length();
int i = 0, n = 0;
while (i < l) {
int j = i;
char c, d;
while (j < l) {
c = s.charAt(j);
d = j + 1 >= l ? '\0' : s.charAt(j + 1);
if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
++j;
else if (c == '/' && d == '*') {
do ++j; while (j < l && !s.substring(j, Math.min(j + 2, l)).equals("*/"));
j = Math.min(j + 2, l);
} else if (c == '/' && d == '/') {
do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0);
} else
break;
}
if (n < nExisting && javaTokWithExisting_isCopyable(existing.get(n), s, i, j))
tok.add(existing.get(n));
else
tok.add(javaTok_substringN(s, i, j));
++n;
i = j;
if (i >= l)
break;
c = s.charAt(i);
d = i + 1 >= l ? '\0' : s.charAt(i + 1);
if (c == '\'' && Character.isJavaIdentifierStart(d) && i + 2 < l && "'\\".indexOf(s.charAt(i + 2)) < 0) {
j += 2;
while (j < l && Character.isJavaIdentifierPart(s.charAt(j))) ++j;
} else if (c == '\'' || c == '"') {
char opener = c;
++j;
while (j < l) {
if (s.charAt(j) == opener) {
++j;
break;
} else if (s.charAt(j) == '\\' && j + 1 < l)
j += 2;
else
++j;
}
} else if (Character.isJavaIdentifierStart(c))
do ++j; while (j < l && (Character.isJavaIdentifierPart(s.charAt(j)) || "'".indexOf(s.charAt(j)) >= 0));
else if (Character.isDigit(c)) {
do ++j; while (j < l && Character.isDigit(s.charAt(j)));
if (j < l && s.charAt(j) == 'L')
++j;
} else if (c == '[' && d == '[') {
do ++j; while (j + 1 < l && !s.substring(j, j + 2).equals("]]"));
j = Math.min(j + 2, l);
} else if (c == '[' && d == '=' && i + 2 < l && s.charAt(i + 2) == '[') {
do ++j; while (j + 2 < l && !s.substring(j, j + 3).equals("]=]"));
j = Math.min(j + 3, l);
} else
++j;
if (n < nExisting && javaTokWithExisting_isCopyable(existing.get(n), s, i, j))
tok.add(existing.get(n));
else
tok.add(javaTok_substringC(s, i, j));
++n;
i = j;
}
if ((tok.size() % 2) == 0)
tok.add("");
javaTok_elements += tok.size();
return tok;
}
static public boolean javaTokWithExisting_isCopyable(String t, String s, int i, int j) {
return t.length() == j - i && s.regionMatches(i, t, 0, j - i);
}
static public String roundBracketIfMoreThanOneToken(String s) {
return !tok_isRoundBracketed(s) && numberOfJavaTokens(s) > 1 ? roundBracket(s) : s;
}
static public IterableIterator emptyIterableIterator_instance = new IterableIterator() {
public Object next() {
throw fail();
}
public boolean hasNext() {
return false;
}
};
static public IterableIterator emptyIterableIterator() {
return emptyIterableIterator_instance;
}
static public IterableIterator iteratorFromFunction_f0(final F0 f) {
class IFF2 extends IterableIterator {
public A a;
public boolean done = false;
public boolean hasNext() {
getNext();
return !done;
}
public A next() {
getNext();
if (done)
throw fail();
A _a = a;
a = null;
return _a;
}
public void getNext() {
if (done || a != null)
return;
a = f.get();
done = a == null;
}
}
;
return new IFF2();
}
static public String repeat(char c, int n) {
n = Math.max(n, 0);
char[] chars = new char[n];
for (int i = 0; i < n; i++) chars[i] = c;
return new String(chars);
}
static public List repeat(A a, int n) {
n = Math.max(n, 0);
List l = new ArrayList(n);
for (int i = 0; i < n; i++) l.add(a);
return l;
}
static public List repeat(int n, A a) {
return repeat(a, n);
}
static public void fillListWithStrings(final JList list, List contents) {
if (list == null)
return;
final DefaultListModel model = new DefaultListModel();
if (contents != null)
for (String s : contents) model.addElement(empty(s) ? " " : s);
{
swing(new Runnable() {
public void run() {
try {
list.setModel(model);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "list.setModel(model);";
}
});
}
}
static public void fillListWithStrings(final JList list, String[] contents) {
fillListWithStrings(list, asList(contents));
}
static public A firstOfPair(Pair p) {
return p == null ? null : p.a;
}
static public TreeSet caseInsensitiveSet_treeSet() {
return new TreeSet(caseInsensitiveComparator());
}
static public TreeSet caseInsensitiveSet_treeSet(Collection c) {
return toCaseInsensitiveSet_treeSet(c);
}
static public List tok_combineCurlyBrackets_keep(List tok) {
List l = new ArrayList();
for (int i = 0; i < l(tok); i++) {
String t = tok.get(i);
if (odd(i) && eq(t, "{")) {
int j = findEndOfCurlyBracketPart(tok, i);
l.add(joinSubList(tok, i, j));
i = j - 1;
} else
l.add(t);
}
return l;
}
static public boolean startsWithAndEndsWith(String s, String prefix, String suffix) {
return startsWith(s, prefix) && endsWith(s, suffix);
}
static public List tok_combineRoundBrackets_keep(List tok) {
List l = new ArrayList();
for (int i = 0; i < l(tok); i++) {
String t = tok.get(i);
if (odd(i) && eq(t, "(")) {
int j = findEndOfBracketPart(tok, i);
l.add(joinSubList(tok, i, j));
i = j - 1;
} else
l.add(t);
}
return l;
}
static public List dropFirstAndLast(int n, List l) {
return cloneSubList(l, n, l(l) - n);
}
static public List dropFirstAndLast(int m, int n, List l) {
return cloneSubList(l, m, l(l) - n);
}
static public List dropFirstAndLast(List l) {
return dropFirstAndLast(1, l);
}
static public String dropFirstAndLast(String s) {
return substring(s, 1, l(s) - 1);
}
static public ArrayList toList(A[] a) {
return asList(a);
}
static public ArrayList toList(int[] a) {
return asList(a);
}
static public ArrayList toList(Set s) {
return asList(s);
}
static public ArrayList toList(Iterable s) {
return asList(s);
}
static public Map> javaTokC_cached_cache = synchronizedMRUCache(defaultTokenizerCacheSize());
static public List javaTokC_cached(String s) {
List tok = javaTokC_cached_cache.get(s);
if (tok == null)
javaTokC_cached_cache.put(s, tok = javaTokC(s));
return tok;
}
static public boolean startsWithLetterOrDigit(String s) {
return nempty(s) && Character.isLetterOrDigit(s.charAt(0));
}
static public boolean eqOneOf(Object o, Object... l) {
for (Object x : l) if (eq(o, x))
return true;
return false;
}
static public List javaTokWithBrackets(String s) {
return javaTokPlusBrackets(s);
}
static public void flexMatchIC_withBrackets_iterate(String pat, String input, VF1 onMatch, Object... __) {
flexMatchIC_iterate(pat, javaTokNPunctuation_plusAsterisk(pat), javaTokNPunctuationWithBrackets_plusAsterisk_cached(input), onMatch, __);
}
static public VF1 vfAddToCollection(final Collection l) {
return l == null ? null : new VF1 () {
public void get(A a) {
try {
l.add(a);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "l.add(a)";
}
};
}
static public boolean flexMatchIC_iterate_debug = false;
static public boolean flexMatchIC_iterate_useTokenization = true;
static public void flexMatchIC_iterate(String pat, String input, VF1 onMatch, Object... __) {
if (flexMatchIC_iterate_debug)
print("flexMatchIC_iterate " + pat + " / " + input);
IF1> tokenizer = optPar("tokenizer", __, __1 -> javaTokNPunctuation_plusAsterisk(__1));
flexMatchIC_iterate(pat, callTokenizer(tokenizer, pat), callTokenizer(tokenizer, input), onMatch, __);
}
static public void flexMatchIC_iterate(String pat, List tokPat, List tokInput, VF1 onMatch, Object... __) {
List varIndices = flexMatchIC_getVarIndices(tokPat, tokInput);
if (varIndices == null)
return;
if (flexMatchIC_iterate_debug)
printStructs("varIndices", varIndices, "tokPat", tokPat, "tokInput", tokInput);
List> spreadInputs = ai_spreadCertainIndices_2(tokPat, tokInput, varIndices);
for (List tok : spreadInputs) {
if (flexMatchIC_iterate_debug)
print("Testing spread " + sfu(codeTokens(tokPat)) + " with input: " + sfu(codeTokens(tok)));
Matches m = new Matches();
if (flexMatchIC_iterate_useTokenization ? match3(tokPat, tok, m) : match(pat, tok, m)) {
if (flexMatchIC_iterate_debug)
print("Got match: " + m);
callF(onMatch, m);
}
}
}
static public Field makeAccessible(Field f) {
try {
f.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, f);
}
return f;
}
static public Method makeAccessible(Method m) {
try {
m.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, m);
}
return m;
}
static public Constructor makeAccessible(Constructor c) {
try {
c.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, c);
}
return c;
}
static public void smartSet(Field f, Object o, Object value) throws Exception {
try {
f.set(o, value);
} catch (Exception e) {
Class type = f.getType();
if (type == int.class && value instanceof Long)
value = ((Long) value).intValue();
if (type == LinkedHashMap.class && value instanceof Map) {
f.set(o, asLinkedHashMap((Map) value));
return;
}
try {
if (f.getType() == Concept.Ref.class) {
f.set(o, ((Concept) o).new Ref((Concept) value));
return;
}
if (o instanceof Concept.Ref) {
f.set(o, ((Concept.Ref) o).get());
return;
}
} catch (Throwable _e) {
}
throw e;
}
}
static public boolean odd(int i) {
return (i & 1) != 0;
}
static public boolean odd(long i) {
return (i & 1) != 0;
}
static public boolean odd(BigInteger i) {
return odd(toInt(i));
}
static public String formatWithThousands(long l) {
return formatWithThousandsSeparator(l);
}
static public double fraction(double d) {
return d % 1;
}
static public String n_fancy2(long l, String singular, String plural) {
return formatWithThousandsSeparator(l) + " " + trim(l == 1 ? singular : plural);
}
static public String n_fancy2(Collection l, String singular, String plural) {
return n_fancy2(l(l), singular, plural);
}
static public String n_fancy2(Map m, String singular, String plural) {
return n_fancy2(l(m), singular, plural);
}
static public String n_fancy2(Object[] a, String singular, String plural) {
return n_fancy2(l(a), singular, plural);
}
static public String n_fancy2(MultiSet ms, String singular, String plural) {
return n_fancy2(l(ms), singular, plural);
}
static public Map emptyMap() {
return new HashMap();
}
static public ArrayList cloneListSynchronizingOn(Collection l, Object mutex) {
if (l == null)
return new ArrayList();
synchronized (mutex) {
return new ArrayList (l);
}
}
static public Collection values(Map map) {
return map == null ? emptyList() : map.values();
}
static public TreeMap ciMap() {
return caseInsensitiveMap();
}
static public String getString(Map map, Object key) {
return map == null ? null : (String) map.get(key);
}
static public String getString(List l, int idx) {
return (String) get(l, idx);
}
static public String getString(Object o, Object key) {
if (o instanceof Map)
return getString((Map) o, key);
if (key instanceof String)
return (String) getOpt(o, (String) key);
throw fail("Not a string key: " + getClassName(key));
}
static public String getString(String key, Object o) {
return getString(o, (Object) key);
}
static public String hopeningTag(String tag, Map params) {
return hopeningTag(tag, mapToParams(params));
}
static public String hopeningTag(String tag, Object... params) {
StringBuilder buf = new StringBuilder();
buf.append("<" + tag);
for (int i = 0; i < l(params); i += 2) {
String name = (String) get(params, i);
Object val = get(params, i + 1);
if (nempty(name) && val != null) {
if (val == html_valueLessParam())
buf.append(" " + name);
else {
String s = str(val);
if (!empty(s))
buf.append(" " + name + "=" + htmlQuote(s));
}
}
}
buf.append(">");
return str(buf);
}
static public boolean neqic(String a, String b) {
return !eqic(a, b);
}
static public boolean neqic(char a, char b) {
return !eqic(a, b);
}
static public String[] dropLast(String[] a, int n) {
n = Math.min(n, a.length);
String[] b = new String[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 void dm_inQ(Runnable r) {
dm_q().add(r);
}
static public DynModule dm_currentModuleMandatory() {
return dm_current_mandatory();
}
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 Set syncIdentityHashSet() {
return (Set) synchronizedSet(identityHashSet());
}
static public AutoCloseable tempAdd(final Collection l, final A a) {
if (l == null || l.contains(a))
return null;
l.add(a);
return new AutoCloseable() {
public String toString() {
return "l.remove(a);";
}
public void close() throws Exception {
l.remove(a);
}
};
}
static public A second(List l) {
return get(l, 1);
}
static public A second(Iterable l) {
if (l == null)
return null;
Iterator it = iterator(l);
if (!it.hasNext())
return null;
it.next();
return it.hasNext() ? it.next() : null;
}
static public A second(A[] bla) {
return bla == null || bla.length <= 1 ? null : bla[1];
}
static public B second(Pair p) {
return p == null ? null : p.b;
}
static public char second(String s) {
return charAt(s, 1);
}
static public A third(List l) {
return _get(l, 2);
}
static public A third(Iterable l) {
if (l == null)
return null;
Iterator it = iterator(l);
for (int _repeat_0 = 0; _repeat_0 < 2; _repeat_0++) {
if (!it.hasNext())
return null;
it.next();
}
return it.hasNext() ? it.next() : null;
}
static public A third(A[] bla) {
return bla == null || bla.length <= 2 ? null : bla[2];
}
static public A last(List l) {
return empty(l) ? null : l.get(l.size() - 1);
}
static public char last(String s) {
return empty(s) ? '#' : s.charAt(l(s) - 1);
}
static public int last(int[] a) {
return l(a) != 0 ? a[l(a) - 1] : 0;
}
static public double last(double[] a) {
return l(a) != 0 ? a[l(a) - 1] : 0;
}
static public A last(A[] a) {
return l(a) != 0 ? a[l(a) - 1] : null;
}
static public A last(Iterator it) {
A a = null;
while (it.hasNext()) {
ping();
a = it.next();
}
return a;
}
static public A last(Collection l) {
if (l == null)
return null;
Iterator it = iterator(l);
A a = null;
while (it.hasNext()) {
ping();
a = it.next();
}
return a;
}
static public A last(SortedSet l) {
return l == null ? null : l.last();
}
static public VF1 runnableToVF1(final Runnable r) {
return r == null ? null : new VF1 () {
public void get(A a) {
try {
r.run();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "r.run()";
}
};
}
static public JComponent wrap(Object swingable) {
return _recordNewSwingComponent(wrap_2(swingable));
}
static public JComponent wrap_2(Object swingable) {
if (swingable == null)
return null;
JComponent c;
if (swingable instanceof Component)
c = componentToJComponent(((Component) swingable));
else
c = componentToJComponent((Component) callOpt(swingable, "swing"));
if (c instanceof JTable || c instanceof JList || c instanceof JTextArea || c instanceof JEditorPane || c instanceof JTextPane || c instanceof JTree)
return jscroll(c);
return c == null ? jlabel(str(swingable)) : c;
}
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 A swingNu(final Class c, final Object... args) {
return swingConstruct(c, args);
}
static public JTextField dm_fieldTextField(String field) {
return jLiveValueTextField_bothWays(dm_fieldLiveValue(field));
}
static public A setToolTipText(final A c, final Object toolTip) {
if (c == null)
return null;
{
swing(new Runnable() {
public void run() {
try {
String s = nullIfEmpty(str(toolTip));
if (neq(s, c.getToolTipText()))
c.setToolTipText(s);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "String s = nullIfEmpty(str(toolTip));\r\n if (neq(s, c.getToolTipText()))\r\n ...";
}
});
}
return c;
}
static public A setToolTipText(Object toolTip, A c) {
return setToolTipText(c, toolTip);
}
static public JButton jbutton(String text, Object action) {
return newButton(text, action);
}
static public JButton jbutton(String text) {
return newButton(text, null);
}
static public JButton jbutton(Action action) {
return swingNu(JButton.class, action);
}
static public String unicode_downPointingTriangle() {
return charToString(0x25BC);
}
static public A optPar_ignoreOddLength(Object[] opt, String name, A defaultValue) {
int n = l(opt);
if (n == 1 && opt[0] instanceof Map) {
Map map = (Map) (opt[0]);
return map.containsKey(name) ? (A) map.get(name) : defaultValue;
}
for (int i = 0; i + 1 < l(opt); i += 2) if (eq(opt[i], name))
return (A) opt[i + 1];
return defaultValue;
}
static public Object optPar_ignoreOddLength(Object[] opt, String name) {
return optPar_ignoreOddLength(opt, name, null);
}
static public Object optPar_ignoreOddLength(String name, Object[] params) {
return optPar_ignoreOddLength(params, name);
}
static public void fillJPopupMenu(JPopupMenu m, Object... x) {
if (x == null)
return;
for (int i = 0; i < l(x); i++) {
Object o = x[i], y = get(x, i + 1);
print("fillJPopupMenu: " + x);
if (o instanceof IVF1)
callF(o, m);
else if (o instanceof List)
fillJPopupMenu(m, asArray((List) o));
else if (isMenuSeparatorIndicator(o))
m.addSeparator();
else if (o instanceof LiveValue && ((LiveValue) o).getType() == String.class && isRunnableX(y)) {
final LiveValue lv = (LiveValue) o;
final JMenuItem mi = jmenuItem("", y);
bindLiveValueListenerToComponent(mi, lv, new Runnable() {
public void run() {
try {
String s = lv.get();
if (isCurlyBracketed(s)) {
setEnabled(mi, false);
s = unCurlyBracket(s);
} else
setEnabled(mi, true);
setText(mi, s);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "String s = lv.get();\r\n if (isCurlyBracketed(s)) {\r\n setEnable...";
}
});
m.add(mi);
} else if (o instanceof String && isRunnableX(y)) {
m.add(jmenuItem((String) o, y));
++i;
} else if (o instanceof JMenuItem)
m.add((JMenuItem) o);
else if (o instanceof String || o instanceof Action || o instanceof Component)
call(m, "add", o);
else if (o != null)
print("Unknown menu item: " + o);
}
}
static public Object[] paramsWithout(Object[] a1, Object... keys) {
if (l(a1) == 1 && a1[0] instanceof Map)
return new Object[] { mapMinus((Map) a1[0], keys) };
Set set = lithashset(keys);
List l = new ArrayList();
int n = l(a1);
for (int i = 0; i < n; i += 2) if (i == n - 1)
l.add(a1[i]);
else if (!set.contains(a1[i])) {
l.add(a1[i]);
l.add(a1[i + 1]);
}
return toObjectArray(l);
}
static public A heldInstance(Class c) {
List l = holdInstance_l.get();
for (int i = l(l) - 1; i >= 0; i--) {
Object o = l.get(i);
if (isInstanceOf(o, c))
return (A) o;
}
throw fail("No instance of " + className(c) + " held");
}
static public int getPreferredWidth(Component c) {
return preferredWidth(c);
}
static public HashMap litmap(Object... x) {
HashMap map = new HashMap();
litmap_impl(map, x);
return map;
}
static public void litmap_impl(Map map, Object... x) {
if (x != null)
for (int i = 0; i < x.length - 1; i += 2) if (x[i + 1] != null)
map.put(x[i], x[i + 1]);
}
static public boolean containsSpace(String s) {
return containsSpaces(s);
}
static public String firstToUpper(String s) {
if (empty(s))
return s;
return Character.toUpperCase(s.charAt(0)) + s.substring(1);
}
static public String joinWithSpace(Collection c) {
return join(" ", c);
}
static public String joinWithSpace(String... c) {
return join(" ", c);
}
static public List replaceElementsUsingMap(Iterable l, final Map map) {
return map(l, new F1 () {
public A get(A a) {
try {
return getOrKeep(map, a);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "getOrKeep(map, a)";
}
});
}
static public List splitCamelCase(String s) {
return ai_splitCamelCase(s);
}
static public void addActionListener(JTextField tf, final Runnable action) {
onEnter(tf, action);
}
static public void addActionListener(final JComboBox cb, final Runnable action) {
if (cb != null) {
swing(new Runnable() {
public void run() {
try {
cb.addActionListener(actionListener(action));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "cb.addActionListener(actionListener(action));";
}
});
}
}
static public void addActionListener(final AbstractButton b, final Runnable action) {
if (b != null) {
swing(new Runnable() {
public void run() {
try {
b.addActionListener(actionListener(action));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "b.addActionListener(actionListener(action));";
}
});
}
}
static public boolean isChecked(final JCheckBox checkBox) {
return checkBox != null && (boolean) swing(new F0() {
public Boolean get() {
try {
return checkBox.isSelected();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret checkBox.isSelected();";
}
});
}
static public boolean isChecked(final JCheckBoxMenuItem mi) {
return mi != null && (boolean) swing(new F0() {
public Boolean get() {
try {
return mi.isSelected();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret mi.isSelected();";
}
});
}
static public JLabel jLiveValueLabel(final LiveValue lv) {
return bindJLabelToLiveValue(jlabel(), lv);
}
static public SimpleLiveValue dm_fieldLiveValue(String fieldName) {
return dm_fieldLiveValue(dm_current_mandatory(), fieldName);
}
static public SimpleLiveValue dm_fieldLiveValue(final DynModule module, final String fieldName) {
Lock __0 = module.lock;
lock(__0);
try {
AutoCloseable __2 = module.enter();
try {
Class type = getFieldType(module, fieldName);
final SimpleLiveValue value = new SimpleLiveValue(type, get(module, fieldName));
dm_watchField(fieldName, new Runnable() {
public void run() {
try {
Object o = get(module, fieldName);
value.set(o);
;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ifdef dm_fieldLiveValue_debug\r\n print(\"dm_fieldLiveValue: setting \" + fi...";
}
});
value.onChange(new Runnable() {
public void run() {
try {
module.setField(fieldName, value.get());
;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ifdef dm_fieldLiveValue_debug\r\n print(\"dm_fieldLiveValue: setting 2 \" + ...";
}
});
return value;
} finally {
_close(__2);
}
} finally {
unlock(__0);
}
}
static public F1 functionToF1(final Object f) {
if (isString(f))
return mainFunctionToF1((String) f);
if (f instanceof F1)
return (F1) f;
return new F1() {
public Object get(Object a) {
try {
return callF(f, a);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret callF(f, a);";
}
};
}
static public B mapGet(Map map, A a) {
return map == null || a == null ? null : map.get(a);
}
static public B mapGet(A a, Map map) {
return map == null || a == null ? null : map.get(a);
}
static public boolean even(int i) {
return (i & 1) == 0;
}
static public boolean even(long i) {
return (i & 1) == 0;
}
static public boolean boolOptParam(ThreadLocal tl) {
return isTrue(optPar(tl));
}
static public boolean boolOptParam(Object[] __, String name) {
return isTrue(optParam(__, name));
}
static public boolean boolOptParam(String name, Object[] __) {
return boolOptParam(__, name);
}
static public boolean boolOptParam(String name, Map __) {
return isTrue(optPar(name, __));
}
static public List mapMethod(Object[] l, final String methodName) {
return map(l, new F1() {
public Object get(Object o) {
try {
return callOpt(o, methodName);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callOpt(o, methodName)";
}
});
}
static public List mapMethod(Iterable c, final String methodName) {
return map(c, new F1() {
public Object get(Object o) {
try {
return callOpt(o, methodName);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callOpt(o, methodName)";
}
});
}
static public List mapMethod(String methodName, Iterable c) {
return mapMethod(c, methodName);
}
static public List mapMethod(String methodName, Enumeration c) {
return mapMethod(methodName, enumerationToIterator(c));
}
static public List synchroList() {
return Collections.synchronizedList(new ArrayList ());
}
static public List synchroList(List l) {
return Collections.synchronizedList(l);
}
static public PersistableThrowable persistableThrowable(Throwable e) {
return e == null ? null : new PersistableThrowable(e);
}
static public Throwable innerException(Throwable e) {
return getInnerException(e);
}
static public ArrayList cloneList(Iterable l) {
return l instanceof Collection ? cloneList((Collection) l) : asList(l);
}
static public ArrayList cloneList(Collection l) {
if (l == null)
return new ArrayList();
synchronized (collectionMutex(l)) {
return new ArrayList (l);
}
}
static public Object pcallFunction(Object f, Object... args) {
try {
return callFunction(f, args);
} catch (Throwable __e) {
_handleException(__e);
}
return null;
}
static public Object swingCall(final Object o, final String method, final Object... args) {
return swing(new F0() {
public Object get() {
try {
return call(o, method, args);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret call(o, method, args);";
}
});
}
static public List collectField(Iterable c, String field) {
List l = new ArrayList();
if (c != null)
for (Object a : c) l.add(getOpt(a, field));
return l;
}
static public List collectField(String field, Iterable c) {
return collectField(c, field);
}
static public Object dm_getModule(Object moduleOrID) {
if (moduleOrID == null || eq(moduleOrID, ""))
return null;
if (isString(moduleOrID) && isIdentifier(((String) moduleOrID)))
return dm_getService(((String) moduleOrID));
if (isStringOrIntOrLong(moduleOrID))
return dm_callOS("getDynModuleByID", str(moduleOrID));
return dm_resolveModule(moduleOrID);
}
static public AutoCloseable dm_enter(Object mod) {
return (AutoCloseable) callOpt(dm_getModule(mod), "enter");
}
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 Object vmBus_query(String msg, Object... args) {
Object arg = vmBus_wrapArgs(args);
{
Object __1 = pcallFAll_returnFirstNotNull(vm_busListeners_live(), msg, arg);
if (__1 != null)
return __1;
}
return pcallFAll_returnFirstNotNull(vm_busListenersByMessage_live().get(msg), msg, arg);
}
static public Object vmBus_query(String msg) {
return vmBus_query(msg, (Object) null);
}
static public String trim(String s) {
return s == null ? null : s.trim();
}
static public String trim(StringBuilder buf) {
return buf.toString().trim();
}
static public String trim(StringBuffer buf) {
return buf.toString().trim();
}
static public List simpleSpaces(List tok) {
tok = cloneList(tok);
for (int i = 0; i < l(tok); i += 2) tok.set(i, tok.get(i).equals("") ? "" : " ");
return tok;
}
static public String simpleSpaces(String s) {
return join(simpleSpaces(nlTok(s)));
}
static public Throwable getExceptionCause(Throwable e) {
Throwable c = e.getCause();
return c != null ? c : e;
}
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, min(a.length, b.length));
}
static public void arraycopy(Object src, int srcPos, Object dest, int destPos, int n) {
if (n != 0)
System.arraycopy(src, srcPos, dest, destPos, n);
}
static public A[] arrayOfType(Class type, int n) {
return makeArray(type, n);
}
static public A[] arrayOfType(int n, Class type) {
return arrayOfType(type, n);
}
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 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 String getStackTrace2(Throwable e) {
return hideCredentials(getStackTrace(unwrapTrivialExceptionWraps(e)) + replacePrefix("java.lang.RuntimeException: ", "FAIL: ", hideCredentials(str(innerException2(e)))) + "\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 boolean isAWTThread() {
if (isAndroid())
return false;
if (isHeadless())
return false;
return isAWTThread_awt();
}
static public boolean isAWTThread_awt() {
return SwingUtilities.isEventDispatchThread();
}
static public void failIfUnlicensed() {
assertTrue("license off", licensed());
}
static public Thread currentThread() {
return Thread.currentThread();
}
static public A setThreadLocal(ThreadLocal tl, A value) {
if (tl == null)
return null;
A old = tl.get();
tl.set(value);
return old;
}
static public F0 dm_rEnter(final DynModule mod) {
return mod == null ? null : new F0() {
public AutoCloseable get() {
try {
return mod.enter();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret mod.enter();";
}
};
}
static volatile public boolean sleep_noSleep = false;
static public void sleep(long ms) {
ping();
if (ms < 0)
return;
if (isAWTThread() && ms > 100)
throw fail("Should not sleep on AWT thread");
try {
Thread.sleep(ms);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static public void sleep() {
try {
if (sleep_noSleep)
throw fail("nosleep");
print("Sleeping.");
sleepQuietly();
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public int toMS_int(double seconds) {
return toInt_checked((long) (seconds * 1000));
}
static public int numberOfJavaTokens(String s) {
return l(javaTokC(s));
}
static public String roundBracket(String s) {
return "(" + s + ")";
}
static public Comparator caseInsensitiveComparator() {
return betterCIComparator();
}
static public TreeSet toCaseInsensitiveSet_treeSet(Iterable c) {
if (isCISet(c))
return (TreeSet) c;
TreeSet set = caseInsensitiveSet_treeSet();
addAll(set, c);
return set;
}
static public TreeSet toCaseInsensitiveSet_treeSet(String... x) {
TreeSet