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 javax.net.ssl.*;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.text.*;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import java.text.NumberFormat;
import java.awt.datatransfer.StringSelection;
class main {
public static void main(final String[] args) throws Exception { pExperiment();
loadFunctions_preferDiskCache();
assertFalseVerbose(new ExpectANumberOfLines(2).check(5));
assertFalseVerbose(new ExpectANumberOfLines(2).check("one line"));
assertFalseVerbose(new ExpectANumberOfLines(2).check("one line\n"));
assertTrueVerbose(new ExpectANumberOfLines(2).check("one line\ntwo lines"));
assertTrueVerbose(new ExpectANumberOfLines(2).check("one line\ntwo lines\n"));
assertTrueVerbose(new ExpectContainsOnce_string(".").check("a.b"));
assertFalseVerbose(new ExpectContainsOnce_string(".").check("a..b"));
assertFalseVerbose(new ExpectContainsOnce_string(".").check("a"));
assertTrueVerbose(new ExpectForEachLine(new ExpectContainsOnce_string(".")).check("a.b\nc.d"));
assertFalseVerbose(new ExpectForEachLine(new ExpectContainsOnce_string(".")).check("a.b\nc,d"));
assertTrueVerbose(new ExpectInteger().check("1"));
assertTrueVerbose(new ExpectInteger().check("-1"));
assertFalseVerbose(new ExpectInteger().check("x"));
assertTrueVerbose(new ExpectInteger().check(1));
assertTrueVerbose(new ExpectAfterSF("trim", new ExpectInteger()).check(" 1 "));
assertFalseVerbose(new ExpectAfterSF("trim", new ExpectInteger()).check(" x "));
assertTrueVerbose(new ExpectElementAtIndex(0, "bla").check(ll("bla", "blubb")));
assertFalseVerbose(new ExpectElementAtIndex(1, "bla").check(ll("bla", "blubb")));
assertTrueVerbose(new ExpectElementAtIndex(1, "blubb").check(ll("bla", "blubb")));
assertFalseVerbose(new ExpectElementAtIndex(0, "blubb").check(ll("bla", "blubb")));
assertTrueVerbose(new ExpectAnd(new ExpectInteger(), new ExpectEquals("5")).check("5"));
assertFalseVerbose(new ExpectAnd(new ExpectInteger(), new ExpectEquals("x")).check("x"));
assertFalseVerbose(new ExpectAnd(new ExpectInteger(), new ExpectEquals("x")).check("5"));
assertTrueVerbose(new ExpectNumberedLines().check("1. bla\n2. blubb"));
assertFalseVerbose(new ExpectNumberedLines().check("1. bla\n3. blubb"));
assertFalseVerbose(new ExpectNumberedLines().check("bla"));
assertTrueVerbose(new ExpectLength(2).check(ll("a", "b")));
assertFalseVerbose(new ExpectLength(3).check(ll("a", "b")));
}
static void pExperiment() {
if (!isMain()) return;
//substance();
autoRestart(5);
experimentIcon();
centerHigherConsole();
tt();
}
static void loadFunctions_preferDiskCache() {
loadFunctions_preferDiskCache = true;
}
static void assertFalseVerbose(Object o) {
assertEqualsVerbose(false, o);
}
static void assertTrueVerbose(Object o) {
assertEqualsVerbose(true, o);
}
static List ll(A... a) {
ArrayList l = new ArrayList(a.length);
for (A x : a) l.add(x);
return l;
}
static HashMap, Class> loadFunctions_cache = new HashMap();
static Lock loadFunctions_cached_lock = lock();
static boolean loadFunctions_preferDiskCache; // Note: This may use outdated versions of standard functions
static Class loadFunctions_cached(String... functions) {
return loadFunctions_cached(asList(functions));
}
static Class loadFunctions_cached(Collection functions) {
TreeSet functionSet = new TreeSet(functions);
Lock __14 = loadFunctions_cached_lock; lock(__14); try {
Class c = loadFunctions_cache.get(functionSet);
if (c != null) return c;
String transpilation = loadFunctions_preferDiskCache ? getTranspiledStandardFunctionsIfCached(functionSet) : null;
if (transpilation != null) {
// TODO: LIBS
print("Loading " + joinWithPlus(functionSet));
c = veryQuickJava_finish(transpilation, emptyList());
}
if (c == null) c = loadFunctions(functionSet);
loadFunctions_cache.put(functionSet, c);
assertNotNull(loadFunctions_cache.get(functionSet));
return c;
} finally { unlock(__14); } }
static boolean isMain() {
return isMainProgram();
}
static double autoRestart_interval = 10;
static boolean autoRestart_on, autoRestart_debug, autoRestart_simulate;
static java.util.Timer autoRestart_timer;
static void autoRestart(double interval) {
autoRestart_interval = interval;
autoRestart();
}
static void autoRestart() {
if (!isMain() || autoRestart_on) return;
autoRestart_on = true;
autoRestart_schedule();
preloadProgramTitle();
}
static void autoRestart_off() {
if (!autoRestart_on) return;
stopTimer(autoRestart_timer);
autoRestart_timer = null;
}
static void autoRestart_schedule() {
autoRestart_timer = doLater_daemon(toMS(autoRestart_interval), "autoRestart_check");
}
static void autoRestart_check() {
try {
String newMD5;
try {
newMD5 = serverAutoRestartMD5(programID());
} catch (Throwable e) {
return;
}
if (!isMD5(newMD5)) { if (autoRestart_debug) print("autoRestart: no server transpilation"); return; }
if (autoRestart_localMD5 == null)
autoRestart_localMD5 = md5(loadCachedTranspilation(programID()));
String localMD5 = autoRestart_localMD5();
if (neq(localMD5, newMD5)) {
if (autoRestart_simulate)
print("Would upgrade now. " + localMD5 + " -> " + newMD5);
else {
infoBox("Upgrading " + programTitle());
restartWithDelay(500);
sleep();
}
}
} finally {
if (autoRestart_debug) print("autoRestart: Done");
autoRestart_schedule();
}
}
static void experimentIcon() {
consoleAndDefaultFrameIcon("#1101173" /*#1101171*/);
}
static void centerHigherConsole() {
if (headless()) return;
setConsoleHeight(600);
centerConsole();
}
static void tt() {
typeWriterConsole();
}
static String tt(Object contents, Object... params) {
return tag("tt", contents, params);
}
static A assertEqualsVerbose(Object x, A y) {
assertEqualsVerbose((String) null, x, y);
return y;
}
static A assertEqualsVerbose(String msg, Object x, A y) {
if (!eq(x, y)) {
throw fail((msg != null ? msg + ": " : "") + /*sfu*/(y) + " != " + /*sfu*/(x));
} else
print("OK: " + /*sfu*/(x));
return y;
}
static void lock(Lock lock) { try {
ping();
if (lock == null) return;
try {
lock.lockInterruptibly();
} catch (InterruptedException e) {
print("Locking interrupted! I probably deadlocked, oops.");
printStackTrace(e);
rethrow(e);
}
ping();
} catch (Exception __e) { throw rethrow(__e); } }
static void lock(Lock lock, String msg) {
print("Locking: " + msg);
lock(lock);
}
static void lock(Lock lock, String msg, long timeout) {
print("Locking: " + msg);
lockOrFail(lock, timeout);
}
static ReentrantLock lock() {
return fairLock();
}
static ArrayList asList(A[] a) {
return a == null ? new ArrayList() : new ArrayList(Arrays.asList(a));
}
static ArrayList asList(int[] a) {
ArrayList l = new ArrayList();
for (int i : a) l.add(i);
return l;
}
static 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 ArrayList asList(Enumeration e) {
ArrayList l = new ArrayList();
if (e != null)
while (e.hasMoreElements())
l.add(e.nextElement());
return l;
}
static String getTranspiledStandardFunctionsIfCached(TreeSet functionSet) { try {
File f = transpiledStandardFunctions_file(functionSet);
//printFileStatus(f);
return loadTextFile(f);
} catch (Throwable __e) { return null; } }
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
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 int print_maxLineLength = 0; // 0 = unset
static boolean print_silent; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal