x = new ArrayList();
for (String s : strings) x.add(s.toLowerCase());
return x;
}
static public String[] toLowerCase(String[] strings) {
String[] x = new String[l(strings)];
for (int i = 0; i < l(strings); i++) x[i] = strings[i].toLowerCase();
return x;
}
static public String toLowerCase(String s) {
return s == null ? "" : s.toLowerCase();
}
static public String firstWord2(String s) {
s = xltrim(s);
if (empty(s))
return "";
if (isLetterOrDigit(first(s)))
return takeCharsWhile(__49 -> isLetterOrDigit(__49), s);
else
return "" + first(s);
}
static public TimeZone getTimeZone(String name) {
return TimeZone.getTimeZone(name);
}
static public String standardTimeZone_name = "Europe/Berlin";
static public String standardTimeZone() {
return standardTimeZone_name;
}
static public A popLast(List l) {
return liftLast(l);
}
static public List popLast(int n, List l) {
return liftLast(n, l);
}
static public Map synchroHashMap() {
return synchronizedMap(new HashMap());
}
static public boolean swic(String a, String b) {
return startsWithIgnoreCase(a, b);
}
static public boolean swic(String a, String b, Matches m) {
if (!swic(a, b))
return false;
m.m = new String[] { substring(a, l(b)) };
return true;
}
static public boolean containsNewLines(String s) {
return containsNewLine(s);
}
static public String jlabel_textAsHTML_center(String text) {
return "" + replace(htmlencode2(text), "\n", " ") + "
";
}
static public boolean charactersEqualIC(char c1, char c2) {
if (c1 == c2)
return true;
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2)
return true;
return Character.toLowerCase(u1) == Character.toLowerCase(u2);
}
static public String xltrim(String s) {
int i = 0, n = l(s);
while (i < n && contains(" \t\r\n", s.charAt(i))) ++i;
return substr(s, i);
}
static public boolean isLetterOrDigit(char c) {
return Character.isLetterOrDigit(c);
}
static public String takeCharsWhile(String s, Object pred) {
int i = 0;
while (i < l(s) && isTrue(callF(pred, s.charAt(i)))) ++i;
return substring(s, 0, i);
}
static public String takeCharsWhile(IF1 f, String s) {
return takeCharsWhile(s, f);
}
static public A liftLast(List l) {
if (empty(l))
return null;
int i = l(l) - 1;
A a = l.get(i);
l.remove(i);
return a;
}
static public List liftLast(int n, List l) {
int i = l(l) - n;
List part = cloneSubList(l, i);
removeSubList(l, i);
return part;
}
static public Map synchronizedMap() {
return synchroMap();
}
static public Map synchronizedMap(Map map) {
return synchroMap(map);
}
static public boolean startsWithIgnoreCase(String a, String b) {
return regionMatchesIC(a, 0, b, 0, b.length());
}
static public boolean containsNewLine(String s) {
return contains(s, '\n');
}
static public List replace(List l, A a, A b) {
for (int i = 0; i < l(l); i++) if (eq(l.get(i), a))
l.set(i, b);
return l;
}
static public List replace(A a, A b, List l) {
return replace(l, a, b);
}
static public String replace(String s, String a, String b) {
return s == null ? null : a == null || b == null ? s : s.replace(a, b);
}
static public String replace(String s, char a, char b) {
return s == null ? null : s.replace(a, b);
}
static public String htmlencode2(String s) {
return htmlencode_noQuotes(s);
}
static public boolean contains(Collection c, Object o) {
return c != null && c.contains(o);
}
static public boolean contains(Iterable it, Object a) {
if (it != null)
for (Object o : it) if (eq(a, o))
return true;
return false;
}
static public boolean contains(Object[] x, Object o) {
if (x != null)
for (Object a : x) if (eq(a, o))
return true;
return false;
}
static public boolean contains(String s, char c) {
return s != null && s.indexOf(c) >= 0;
}
static public boolean contains(String s, String b) {
return s != null && s.indexOf(b) >= 0;
}
static public boolean contains(BitSet bs, int i) {
return bs != null && bs.get(i);
}
static public boolean contains(Rect r, Pt p) {
return rectContains(r, p);
}
static public String substr(String s, int x) {
return substring(s, x);
}
static public String substr(String s, int x, int y) {
return substring(s, x, y);
}
static public Map synchroMap() {
return synchroHashMap();
}
static public Map synchroMap(Map map) {
return Collections.synchronizedMap(map);
}
static public String htmlencode_noQuotes(String s) {
if (s == null)
return "";
int n = s.length();
StringBuilder out = null;
for (int i = 0; i < n; i++) {
char c = s.charAt(i);
if (c == '<') {
if (out == null)
out = new StringBuilder(Math.max(16, n)).append(takeFirst(i, s));
out.append("<");
} else if (c == '>') {
if (out == null)
out = new StringBuilder(Math.max(16, n)).append(takeFirst(i, s));
out.append(">");
} else if (c > 127 || c == '&') {
int cp = s.codePointAt(i);
if (out == null)
out = new StringBuilder(Math.max(16, n)).append(takeFirst(i, s));
out.append("");
out.append(intToHex_flexLength(cp));
out.append(';');
i += Character.charCount(cp) - 1;
} else {
if (out != null)
out.append(c);
}
}
return out == null ? s : out.toString();
}
static public boolean rectContains(int x1, int y1, int w, int h, Pt p) {
return p.x >= x1 && p.y >= y1 && p.x < x1 + w && p.y < y1 + h;
}
static public boolean rectContains(Rect a, Rect b) {
return b.x >= a.x && b.y >= a.y && b.x2() <= a.x2() && b.y2() <= a.y2();
}
static public boolean rectContains(Rect a, Rectangle b) {
return rectContains(a, toRect(b));
}
static public boolean rectContains(Rect a, int x, int y) {
return a != null && a.contains(x, y);
}
static public boolean rectContains(Rect a, Pt p) {
return a != null && p != null && a.contains(p);
}
static public List takeFirst(List l, int n) {
return l(l) <= n ? l : newSubListOrSame(l, 0, n);
}
static public List takeFirst(int n, List l) {
return takeFirst(l, n);
}
static public String takeFirst(int n, String s) {
return substring(s, 0, n);
}
static public String takeFirst(String s, int n) {
return substring(s, 0, n);
}
static public CharSequence takeFirst(int n, CharSequence s) {
return subCharSequence(s, 0, n);
}
static public List takeFirst(int n, Iterator it) {
if (it == null)
return null;
List l = new ArrayList();
for (int _repeat_0 = 0; _repeat_0 < n; _repeat_0++) {
if (it.hasNext())
l.add(it.next());
else
break;
}
return l;
}
static public List takeFirst(int n, Iterable i) {
if (i == null)
return null;
return i == null ? null : takeFirst(n, i.iterator());
}
static public List takeFirst(int n, IterableIterator i) {
return takeFirst(n, (Iterator ) i);
}
static public int[] takeFirst(int n, int[] a) {
return takeFirstOfIntArray(n, a);
}
static public short[] takeFirst(int n, short[] a) {
return takeFirstOfShortArray(n, a);
}
static public byte[] takeFirst(int n, byte[] a) {
return takeFirstOfByteArray(n, a);
}
static public byte[] takeFirst(byte[] a, int n) {
return takeFirstOfByteArray(n, a);
}
static public double[] takeFirst(int n, double[] a) {
return takeFirstOfDoubleArray(n, a);
}
static public double[] takeFirst(double[] a, int n) {
return takeFirstOfDoubleArray(n, a);
}
static public String intToHex_flexLength(int i) {
return Integer.toHexString(i);
}
static public Rect toRect(Rectangle r) {
return r == null ? null : new Rect(r);
}
static public Rect toRect(RectangularShape r) {
return r == null ? null : toRect(r.getBounds());
}
static public Rect toRect(Rect r) {
return r;
}
static public List newSubListOrSame(List l, int startIndex) {
return newSubListOrSame(l, startIndex, l(l));
}
static public List newSubListOrSame(List l, int startIndex, int endIndex) {
if (l == null)
return null;
int n = l(l);
startIndex = max(0, startIndex);
endIndex = min(n, endIndex);
if (startIndex >= endIndex)
return ll();
if (startIndex == 0 && endIndex == n)
return l;
return cloneList(l.subList(startIndex, endIndex));
}
static public int[] takeFirstOfIntArray(int[] b, int n) {
return subIntArray(b, 0, n);
}
static public int[] takeFirstOfIntArray(int n, int[] b) {
return takeFirstOfIntArray(b, n);
}
static public short[] takeFirstOfShortArray(short[] b, int n) {
return subShortArray(b, 0, n);
}
static public short[] takeFirstOfShortArray(int n, short[] b) {
return takeFirstOfShortArray(b, n);
}
static public byte[] takeFirstOfByteArray(byte[] b, int n) {
return subByteArray(b, 0, n);
}
static public byte[] takeFirstOfByteArray(int n, byte[] b) {
return takeFirstOfByteArray(b, n);
}
static public double[] takeFirstOfDoubleArray(double[] b, int n) {
return subDoubleArray(b, 0, n);
}
static public double[] takeFirstOfDoubleArray(int n, double[] b) {
return takeFirstOfDoubleArray(b, n);
}
static public int iround(double d) {
return (int) Math.round(d);
}
static public int iround(Number n) {
return iround(toDouble(n));
}
static public int[] subIntArray(int[] b, int start) {
return subIntArray(b, start, l(b));
}
static public int[] subIntArray(int[] b, int start, int end) {
start = max(start, 0);
end = min(end, l(b));
if (start == 0 && end == l(b))
return b;
if (start >= end)
return new int[0];
int[] x = new int[end - start];
System.arraycopy(b, start, x, 0, end - start);
return x;
}
static public short[] subShortArray(short[] b, int start, int end) {
start = max(start, 0);
end = min(end, l(b));
if (start == 0 && end == l(b))
return b;
if (start >= end)
return new short[0];
short[] x = new short[end - start];
System.arraycopy(b, start, x, 0, end - start);
return x;
}
static public byte[] subByteArray(byte[] b, int start) {
return subByteArray(b, start, l(b));
}
static public byte[] subByteArray(byte[] b, int start, int end) {
start = max(start, 0);
end = min(end, l(b));
if (start == 0 && end == l(b))
return b;
if (start >= end)
return new byte[0];
byte[] x = new byte[end - start];
System.arraycopy(b, start, x, 0, end - start);
return x;
}
static public double[] subDoubleArray(double[] b, int start) {
return subDoubleArray(b, start, l(b));
}
static public double[] subDoubleArray(double[] b, int start, int end) {
start = max(start, 0);
end = min(end, l(b));
if (start == 0 && end == l(b))
return b;
if (start >= end)
return new double[0];
double[] x = new double[end - start];
System.arraycopy(b, start, x, 0, end - start);
return x;
}
static public double toDouble(Object o) {
if (o instanceof Number)
return ((Number) o).doubleValue();
if (o instanceof BigInteger)
return ((BigInteger) o).doubleValue();
if (o instanceof String)
return parseDouble((String) o);
if (o == null)
return 0.0;
throw fail(o);
}
static public double parseDouble(String s) {
return empty(s) ? 0.0 : Double.parseDouble(s);
}
static public class Chain implements Iterable {
public A element;
public Chain next;
public int size;
public Chain() {
}
public Chain(A element) {
this.element = element;
size = 1;
}
public Chain(A element, Chain next) {
this.next = next;
this.element = element;
size = next != null ? next.size + 1 : 1;
}
public String toString() {
return str(toList());
}
public ArrayList toList() {
ArrayList l = emptyList(size);
Chain c = this;
while (c != null) {
l.add(c.element);
c = c.next;
}
return l;
}
public Iterator iterator() {
return toList().iterator();
}
}
static public class BetterThreadLocal {
public Map map = newWeakHashMap();
public BetterThreadLocal() {
}
public BetterThreadLocal(A value) {
set(value);
}
public boolean isSet() {
return map.containsKey(currentThread());
}
public A get() {
if (map.containsKey(currentThread()))
return map.get(currentThread());
A value = initialValue();
set(value);
return value;
}
public A get(Thread thread) {
return thread == null ? null : map.get(thread);
}
public void set(A a) {
map.put(currentThread(), a);
}
public A initialValue() {
return null;
}
}
static public class ReverseChain implements Iterable {
public A element;
public ReverseChain prev;
public int size;
public ReverseChain() {
}
public ReverseChain(ReverseChain prev, A element) {
this.element = element;
this.prev = prev;
if (prev == null)
size = 1;
else {
prev.check();
size = prev.size + 1;
}
}
public void check() {
if (size < 1)
throw fail("You called the ReverseChain default constructor. Don't do that");
}
public String toString() {
return str(toList());
}
public ArrayList toList() {
check();
ArrayList l = emptyList(size);
for (int i = 0; i < size; i++) l.add(null);
int i = size;
ReverseChain c = this;
while (c != null) {
l.set(--i, c.element);
c = c.prev;
}
return l;
}
public Iterator iterator() {
return toList().iterator();
}
}
static public class BetterThread extends Thread {
public Runnable target;
public BetterThread(Runnable target) {
this.target = target;
_created();
}
public BetterThread(Runnable target, String name) {
super(name);
this.target = target;
_created();
}
public void _created() {
vmBus_send("threadCreated", this);
}
public void run() {
try {
try {
vmBus_send("threadStarted", this);
if (target != null)
target.run();
} finally {
vmBus_send("threadEnded", this);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public Runnable getTarget() {
return target;
}
}
static public class CompactLinkedHashSet extends AbstractSet {
public UnsynchronizedCompactHashSet> entries = new UnsynchronizedCompactHashSet();
public Entry head, tail;
static public class Entry {
public A value;
public Entry prev, next;
public int hashCode() {
return _hashCode(value);
}
public boolean equals(Object o) {
return o == this || eq(value, o);
}
}
public boolean add(A a) {
if (entries.contains(a))
return false;
Entry n = new Entry();
n.value = a;
n.prev = tail;
if (tail != null)
tail.next = n;
tail = n;
if (head == null)
head = n;
entries.add(n);
return true;
}
public boolean remove(Object a) {
return remove(entries.find(a));
}
public boolean remove(Entry node) {
if (node == null)
return false;
if (node.next != null)
node.next.prev = node.prev;
else
tail = node.prev;
if (node.prev != null)
node.prev.next = node.next;
else
head = node.next;
entries.remove(node);
return true;
}
public int size() {
return entries.size();
}
public IterableIterator iterator() {
return new IterableIterator () {
public Entry entry = head, prev = null;
public boolean hasNext() {
return entry != null;
}
public A next() {
A a = entry.value;
prev = entry;
entry = entry.next;
return a;
}
public void remove() {
if (prev == null)
throw new IllegalStateException();
CompactLinkedHashSet.this.remove(prev);
prev = null;
}
};
}
public void clear() {
entries.clear();
head = tail = null;
}
public boolean contains(Object a) {
return entries.contains(a);
}
public A find(Object o) {
Entry e = entries.find(o);
return e == null ? null : e.value;
}
public A prevElement(A a) {
Entry e = entries.find(a);
if (e == null || e.prev == null)
return null;
return e.prev.value;
}
public A nextElement(A a) {
Entry e = entries.find(a);
if (e == null || e.next == null)
return null;
return e.next.value;
}
public A first() {
return head == null ? null : head.value;
}
public A last() {
return tail == null ? null : tail.value;
}
public boolean removeIfSame(Object o) {
A value = find(o);
if (value == o) {
remove(value);
return true;
}
return false;
}
}
static public class Dyn_FieldWatcher implements AutoCloseable {
public DynModule module;
public String field;
public Object value;
public Runnable action;
public Runnable changeListener = new Runnable() {
public void run() {
try {
check();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "check();";
}
};
public VF1 fieldChangeListener = new VF1() {
public void get(String f) {
try {
if (eq(f, field))
check();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (eq(f, field))\r\n check();";
}
};
transient public IF1 cloneValue;
public Object cloneValue(Object o) {
return cloneValue != null ? cloneValue.get(o) : cloneValue_base(o);
}
final public Object cloneValue_fallback(IF1 _f, Object o) {
return _f != null ? _f.get(o) : cloneValue_base(o);
}
public Object cloneValue_base(Object o) {
return o;
}
public Dyn_FieldWatcher(DynModule module, String field, Runnable action) {
this(module, field, action, null);
}
public Dyn_FieldWatcher(DynModule module, String field, Runnable action, IF1 cloneValue) {
this.cloneValue = cloneValue;
this.action = action;
this.field = field;
this.module = module;
value = cloneValue(get(module, field));
module.onChange(changeListener);
module.onFieldChange(fieldChangeListener);
}
public void check() {
Object newValue = cloneValue(get(module, field));
if (eq(value, newValue))
return;
value = newValue;
dm_q(module, action);
}
public void close() {
try {
module.removeChangeListener(changeListener);
module.removeFieldChangeListener(fieldChangeListener);
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
static public class ChangeTrigger implements Runnable, IFieldsToList {
public ChangeTriggerable target;
public ChangeTrigger() {
}
public ChangeTrigger(ChangeTriggerable target) {
this.target = target;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + target + ")";
}
public boolean equals(Object o) {
if (!(o instanceof ChangeTrigger))
return false;
ChangeTrigger __1 = (ChangeTrigger) o;
return eq(target, __1.target);
}
public int hashCode() {
int h = -1239972920;
h = boostHashCombine(h, _hashCode(target));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { target };
}
public void run() {
try {
{
if (target != null)
target.change();
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
public interface ChangeTriggerable {
public void change();
}
static public class UnsynchronizedCompactHashSet extends java.util.AbstractSet {
final static public int INITIAL_SIZE = 3;
public final static double LOAD_FACTOR = 0.75;
final static public Object nullObject = new Object();
final static public Object deletedObject = new Object();
public int elements;
public int freecells;
public A[] objects;
public int modCount;
public UnsynchronizedCompactHashSet() {
this(INITIAL_SIZE);
}
public UnsynchronizedCompactHashSet(int size) {
objects = (A[]) new Object[(size == 0 ? 1 : size)];
elements = 0;
freecells = objects.length;
modCount = 0;
}
public UnsynchronizedCompactHashSet(Collection c) {
this(c.size());
addAll(c);
}
@Override
public Iterator iterator() {
return new CompactHashIterator ();
}
@Override
public int size() {
return elements;
}
@Override
public boolean isEmpty() {
return elements == 0;
}
@Override
public boolean contains(Object o) {
return find(o) != null;
}
public A find(Object o) {
if (o == null)
o = nullObject;
int hash = o.hashCode();
int index = (hash & 0x7FFFFFFF) % objects.length;
int offset = 1;
while (objects[index] != null && !(objects[index].hashCode() == hash && objects[index].equals(o))) {
index = ((index + offset) & 0x7FFFFFFF) % objects.length;
offset = offset * 2 + 1;
if (offset == -1)
offset = 2;
}
return objects[index];
}
public boolean removeIfSame(Object o) {
A value = find(o);
if (value == o) {
remove(value);
return true;
}
return false;
}
@Override
public boolean add(Object o) {
if (o == null)
o = nullObject;
int hash = o.hashCode();
int index = (hash & 0x7FFFFFFF) % objects.length;
int offset = 1;
int deletedix = -1;
while (objects[index] != null && !(objects[index].hashCode() == hash && objects[index].equals(o))) {
if (objects[index] == deletedObject)
deletedix = index;
index = ((index + offset) & 0x7FFFFFFF) % objects.length;
offset = offset * 2 + 1;
if (offset == -1)
offset = 2;
}
if (objects[index] == null) {
if (deletedix != -1)
index = deletedix;
else
freecells--;
modCount++;
elements++;
objects[index] = (A) o;
if (1 - (freecells / (double) objects.length) > LOAD_FACTOR)
rehash();
return true;
} else
return false;
}
@Override
public boolean remove(Object o) {
if (o == null)
o = nullObject;
int hash = o.hashCode();
int index = (hash & 0x7FFFFFFF) % objects.length;
int offset = 1;
while (objects[index] != null && !(objects[index].hashCode() == hash && objects[index].equals(o))) {
index = ((index + offset) & 0x7FFFFFFF) % objects.length;
offset = offset * 2 + 1;
if (offset == -1)
offset = 2;
}
if (objects[index] != null) {
objects[index] = (A) deletedObject;
modCount++;
elements--;
return true;
} else
return false;
}
@Override
public void clear() {
elements = 0;
for (int ix = 0; ix < objects.length; ix++) objects[ix] = null;
freecells = objects.length;
modCount++;
}
@Override
public Object[] toArray() {
Object[] result = new Object[elements];
Object[] objects = this.objects;
int pos = 0;
for (int i = 0; i < objects.length; i++) if (objects[i] != null && objects[i] != deletedObject) {
if (objects[i] == nullObject)
result[pos++] = null;
else
result[pos++] = objects[i];
}
return result;
}
@Override
public T[] toArray(T[] a) {
int size = elements;
if (a.length < size)
a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size);
A[] objects = this.objects;
int pos = 0;
for (int i = 0; i < objects.length; i++) if (objects[i] != null && objects[i] != deletedObject) {
if (objects[i] == nullObject)
a[pos++] = null;
else
a[pos++] = (T) objects[i];
}
return a;
}
public void rehash() {
int garbagecells = objects.length - (elements + freecells);
if (garbagecells / (double) objects.length > 0.05)
rehash(objects.length);
else
rehash(objects.length * 2 + 1);
}
public void rehash(int newCapacity) {
int oldCapacity = objects.length;
@SuppressWarnings("unchecked")
A[] newObjects = (A[]) new Object[newCapacity];
for (int ix = 0; ix < oldCapacity; ix++) {
Object o = objects[ix];
if (o == null || o == deletedObject)
continue;
int hash = o.hashCode();
int index = (hash & 0x7FFFFFFF) % newCapacity;
int offset = 1;
while (newObjects[index] != null) {
index = ((index + offset) & 0x7FFFFFFF) % newCapacity;
offset = offset * 2 + 1;
if (offset == -1)
offset = 2;
}
newObjects[index] = (A) o;
}
objects = newObjects;
freecells = objects.length - elements;
}
public class CompactHashIterator implements Iterator {
public int index;
public int lastReturned = -1;
public int expectedModCount;
@SuppressWarnings("empty-statement")
public CompactHashIterator() {
for (index = 0; index < objects.length && (objects[index] == null || objects[index] == deletedObject); index++) ;
expectedModCount = modCount;
}
@Override
public boolean hasNext() {
return index < objects.length;
}
@SuppressWarnings("empty-statement")
@Override
public T next() {
int length = objects.length;
if (index >= length) {
lastReturned = -2;
throw new NoSuchElementException();
}
lastReturned = index;
for (index += 1; index < length && (objects[index] == null || objects[index] == deletedObject); index++) ;
if (objects[lastReturned] == nullObject)
return null;
else
return (T) objects[lastReturned];
}
@Override
public void remove() {
if (modCount != expectedModCount)
throw new ConcurrentModificationException();
if (lastReturned == -1 || lastReturned == -2)
throw new IllegalStateException();
if (objects[lastReturned] != null && objects[lastReturned] != deletedObject) {
objects[lastReturned] = (A) deletedObject;
elements--;
modCount++;
expectedModCount = modCount;
}
}
}
public int capacity() {
return objects.length;
}
public boolean shrinkToFactor(double factor) {
if (factor > LOAD_FACTOR)
throw fail("Shrink factor must be equal to or smaller than load factor: " + factor + " / " + LOAD_FACTOR);
int newCapacity = max(INITIAL_SIZE, iround(size() / factor));
if (newCapacity >= capacity())
return false;
rehash(newCapacity);
return true;
}
}
static public String find(String pattern, String text) {
Matcher matcher = Pattern.compile(pattern).matcher(text);
if (matcher.find())
return matcher.group(1);
return null;
}
static public A find(Collection c, Object... data) {
for (A x : c) if (checkFields(x, data))
return x;
return null;
}
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_q(IF0 f) {
return dm_evalInQ(if0ToF0(f));
}
static public boolean checkFields(Object x, Object... data) {
for (int i = 0; i < l(data); i += 2) if (neq(getOpt(x, (String) data[i]), data[i + 1]))
return false;
return true;
}
static public void dm_inQ(Runnable r) {
dm_q().add(r);
}
static public void dm_inQ(DynModule mod, Runnable r) {
dm_q(mod, r);
}
static public A dm_evalInQ(F0 f) {
return dm_evalInQ(dm_current_mandatory(), f);
}
static public A dm_evalInQ(IF0 f) {
return dm_evalInQ(dm_current_mandatory(), if0ToF0(f));
}
static public A dm_evalInQ(DynModule module, F0 f) {
return evalInQ(module.q(), f);
}
static public F0 if0ToF0(IF0 f) {
return f == null ? null : new F0 () {
public A get() {
try {
return f.get();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "return f.get();";
}
};
}
static public A evalInQ(Q q, final F0 f) {
if (isInQ(q))
return callF(f);
final Var> var = new Var();
q.add(new Runnable() {
public void run() {
try {
try {
var.set(eitherA(callF(f)));
} catch (Throwable e) {
var.set(eitherB(e));
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "try {\r\n var.set(eitherA(callF(f)));\r\n } catch (Throwable e) {\r\n ...";
}
});
return returnOrThrow_either(waitForVarToBeNotNull(var));
}
static public boolean isInQ(Q q) {
return q != null && isCurrentThread(q.rst.thread);
}
static public Either eitherA(A a) {
return new Either(1, a);
}
static public Either eitherB(B b) {
return new Either(2, b);
}
static public A returnOrThrow_either(Either e) {
if (isEitherB(e))
throw rethrow(e.b());
return eitherAOpt(e);
}
static public A waitForVarToBeNotNull(Var v) {
try {
synchronized (v) {
while (!v.has()) v.wait();
return v.get();
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public boolean isCurrentThread(Thread t) {
return t != null && t == currentThread();
}
static public boolean isEitherB(Either e) {
return eitherIsB(e);
}
static public A eitherAOpt(Either e) {
return e != null && e.isA() ? e.a() : null;
}
static public boolean eitherIsB(Either e) {
return e != null && e.isB();
}
static public class Either {
public byte which;
public Object value;
public Either() {
}
public Either(int which, Object value) {
this.which = (byte) which;
this.value = value;
}
public boolean isA() {
return which == 1;
}
public boolean isB() {
return which == 2;
}
public A a() {
if (which != 1)
_failMe();
return (A) value;
}
public B b() {
if (which != 2)
_failMe();
return (B) value;
}
public A aOpt() {
return which != 1 ? null : (A) value;
}
public B bOpt() {
return which != 2 ? null : (B) value;
}
public void _failMe() {
throw fail("Either object is of wrong type: " + shortClassName(value));
}
public String toString() {
return "Either" + (isA() ? "A" : "B") + "(" + value + ")";
}
}
static public String b(Object contents, Object... params) {
return tag("b", contents, params);
}
static public boolean isA(Either e) {
return eitherIsA(e);
}
static public String tag(String tag) {
return htag(tag);
}
static public String tag(String tag, Object contents, Object... params) {
return htag(tag, str(contents), params);
}
static public String tag(String tag, StringBuilder contents, Object... params) {
return htag(tag, contents, params);
}
static public String tag(String tag, StringBuffer contents, Object... params) {
return htag(tag, contents, params);
}
static public boolean eitherIsA(Either e) {
return e != null && e.isA();
}
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 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);
params = unrollParams(params);
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 (eqOneOf(val, html_valueLessParam(), true))
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 Object[] mapToParams(Map map) {
return mapToObjectArray(map);
}
static public Object[] unrollParams(Object[] params) {
if (l(params) == 1 && params[0] instanceof Map)
return mapToParams((Map) params[0]);
return params;
}
static public Object html_valueLessParam_cache;
static public Object html_valueLessParam() {
if (html_valueLessParam_cache == null)
html_valueLessParam_cache = html_valueLessParam_load();
return html_valueLessParam_cache;
}
static public Object html_valueLessParam_load() {
return new Object();
}
static public String htmlQuote(String s) {
return "\"" + htmlencode_forParams(s) + "\"";
}
static public Object[] mapToObjectArray(Map map) {
List l = new ArrayList();
for (Object o : keys(map)) {
l.add(o);
l.add(map.get(o));
}
return toObjectArray(l);
}
static public Object[] mapToObjectArray(Object f, Collection l) {
int n = l(l);
Object[] array = new Object[n];
if (n != 0) {
Iterator it = iterator(l);
for (int i = 0; i < n; i++) array[i] = callF(f, it.next());
}
return array;
}
static public Object[] mapToObjectArray(Object f, Object[] l) {
int n = l(l);
Object[] array = new Object[n];
for (int i = 0; i < n; i++) array[i] = callF(f, l[i]);
return array;
}
static public Object[] mapToObjectArray(Collection l, IF1 f) {
return mapToObjectArray(f, l);
}
static public Object[] mapToObjectArray(A[] l, IF1 f) {
return mapToObjectArray(f, l);
}
static public Object[] mapToObjectArray(IF1 f, A[] l) {
int n = l(l);
Object[] array = new Object[n];
for (int i = 0; i < n; i++) array[i] = f.get(l[i]);
return array;
}
static public Object[] mapToObjectArray(IF1 f, Collection l) {
int n = l(l);
Object[] array = new Object[n];
if (n != 0) {
Iterator it = iterator(l);
for (int i = 0; i < n; i++) array[i] = callF(f, it.next());
}
return array;
}
static public ThreadLocal htmlencode_forParams_useV2 = new ThreadLocal();
static public String htmlencode_forParams(String s) {
if (s == null)
return "";
if (isTrue(htmlencode_forParams_useV2.get()))
return htmlencode_forParams_v2(s);
StringBuilder out = new StringBuilder(Math.max(16, s.length()));
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c > 127 || c == '"' || c == '<' || c == '>') {
out.append("");
out.append((int) c);
out.append(';');
} else
out.append(c);
}
return out.toString();
}
static public Object[] toObjectArray(Collection c) {
return toObjectArray((Iterable) c);
}
static public Object[] toObjectArray(Iterable c) {
List l = asList(c);
return l.toArray(new Object[l.size()]);
}
static public String htmlencode_forParams_v2(String s) {
if (s == null)
return "";
StringBuilder out = new StringBuilder(Math.max(16, s.length()));
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&') {
out.append("");
out.append((int) c);
out.append(';');
} else
out.append(c);
}
return out.toString();
}
}