import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import java.util.function.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
import static x30_pkg.x30_util.DynamicObject;
import java.text.*;
import java.text.NumberFormat;
import java.util.TimeZone;
import java.awt.geom.*;
class main {
static boolean preciseNuObject_debug = false;
static A preciseNuObject(Class c, Object... args) { try {
Constructor[] methods = getDeclaredConstructors_cached(c);
if (methods.length == 0)
throw fail(c + " doesn't define any constructors");
return preciseNuObject(methods, args);
} catch (Exception __e) { throw rethrow(__e); } }
static A preciseNuObject(Constructor[] methods, Object... args) { try {
Constructor best = null;
int bestScore = Integer.MAX_VALUE;
boolean widening = false;
if (preciseNuObject_debug)
printVars("preciseNuObject", "c" , first(methods).getDeclaringClass(), "methods" , l(methods));
for (var m : methods) {
int score = methodApplicabilityScore_withPrimitiveWidening(m, args);
if (score == 0)
return (A) m.newInstance(args);
if (preciseNuObject_debug)
print("Method score: " + m + " " + score);
if (abs(score) < bestScore) {
best = m;
bestScore = abs(score);
widening = score < 0;
}
}
if (best != null)
if (widening)
return (A) invokeConstructorWithWidening(best, args);
else
return (A) best.newInstance(args);
// try varargs - TODO: make this precise too
methodSearch: for (var m : methods) {
{ if (!(m.isVarArgs())) continue; }
Object[] newArgs = massageArgsForVarArgsCall(m, args);
if (newArgs != null)
return (A) m.newInstance(newArgs);
}
var c = first(methods).getDeclaringClass();
throw fail("No matching constructor found: " + formatFunctionCall(c, map(__14 -> _getClass(__14), args)));
} catch (Exception __e) { throw rethrow(__e); } }
// TODO: convert to regularly cleared normal map
static Map cache = newDangerousWeakHashMap();
static Constructor[] getDeclaredConstructors_cached(Class c) {
Constructor[] ctors;
synchronized(cache) {
ctors = cache.get(c);
if (ctors == null) {
cache.put(c, ctors = c.getDeclaredConstructors());
for (var ctor : ctors)
makeAccessible(ctor);
}
}
return ctors;
}
static RuntimeException fail() { throw new RuntimeException("fail"); }
static RuntimeException fail(Throwable e) { throw asRuntimeException(e); }
static RuntimeException fail(Object msg) { throw new RuntimeException(String.valueOf(msg)); }
static RuntimeException fail(Object... objects) { throw new Fail(objects); }
static RuntimeException fail(String msg) { throw new RuntimeException(msg == null ? "" : msg); }
static RuntimeException fail(String msg, Throwable innerException) { throw new RuntimeException(msg, innerException); }
static RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static RuntimeException rethrow(String msg, Throwable t) {
throw new RuntimeException(msg, t);
}
// Use like this: printVars(+x, +y);
// Or: printVars("bla", +x);
// Or: printVars bla(, +x);
static void printVars(Object... params) {
printVars_str(params);
}
static Object first(Object list) {
return first((Iterable) list);
}
static A first(List list) {
return empty(list) ? null : list.get(0);
}
static A first(A[] bla) {
return bla == null || bla.length == 0 ? null : bla[0];
}
static Pair first(Map map) {
return mapEntryToPair(first(entrySet(map)));
}
static Pair first(MultiMap mm) {
if (mm == null) return null;
var e = first(mm.data.entrySet());
if (e == null) return null;
return pair(e.getKey(), first(e.getValue()));
}
static A first(IterableIterator i) {
return first((Iterator) i);
}
static A first(Iterator i) {
return i == null || !i.hasNext() ? null : i.next();
}
static A first(Iterable i) {
if (i == null) return null;
Iterator it = i.iterator();
return it.hasNext() ? it.next() : null;
}
static Character first(String s) { return empty(s) ? null : s.charAt(0); }
static Character first(CharSequence s) { return empty(s) ? null : s.charAt(0); }
static A first(Pair p) {
return p == null ? null : p.a;
}
static Byte first(byte[] l) {
return empty(l) ? null : l[0];
}
static A first(A[] l, IF1 pred) {
return firstThat(l, pred);
}
static A first(Iterable l, IF1 pred) {
return firstThat(l, pred);
}
static A first(IF1 pred, Iterable l) {
return firstThat(pred, l);
}
static A first(AppendableChain a) {
return a == null ? null : a.element;
}
static int l(Object[] a) { return a == null ? 0 : a.length; }
static int l(boolean[] a) { return a == null ? 0 : a.length; }
static int l(byte[] a) { return a == null ? 0 : a.length; }
static int l(short[] a) { return a == null ? 0 : a.length; }
static int l(long[] a) { return a == null ? 0 : a.length; }
static int l(int[] a) { return a == null ? 0 : a.length; }
static int l(float[] a) { return a == null ? 0 : a.length; }
static int l(double[] a) { return a == null ? 0 : a.length; }
static int l(char[] a) { return a == null ? 0 : a.length; }
static int l(Collection c) { return c == null ? 0 : c.size(); }
static int l(Iterator i) { return iteratorCount_int_close(i); } // consumes the iterator && closes it if possible
static int l(Map m) { return m == null ? 0 : m.size(); }
static int l(CharSequence s) { return s == null ? 0 : s.length(); }
static long l(File f) { return f == null ? 0 : f.length(); }
static int l(IMultiMap mm) { return mm == null ? 0 : mm.size(); }
static int l(AppendableChain a) { return a == null ? 0 : a.size; }
// returns Int.MAX_VALUE if not applicable
// returns -score if conversions are needed
// or +score if no conversions are needed
// Lower score is better
static int methodApplicabilityScore_withPrimitiveWidening(Executable m, Object[] args) {
Class>[] types = m.getParameterTypes();
if (types.length != l(args)) return Integer.MAX_VALUE;
int score = 0;
boolean widenings = false;
for (int i = 0; i < types.length; i++) {
Object a = args[i];
Class c = types[i];
// null can be assigned to any non-primitive type
if (a == null) {
if (c.isPrimitive())
return Integer.MAX_VALUE;
} else {
Class t = a.getClass();
int s = typeConversionScoreWithUnboxing(t, c);
if (s == Integer.MAX_VALUE)
return Integer.MAX_VALUE;
if (s < 0) widenings = true;
score += abs(s);
}
}
return widenings ? -score : score;
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static boolean printAlsoToSystemOut = true;
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal