litlist(A... a) {
ArrayList l = new ArrayList(a.length);
for (A x : a) l.add(x);
return l;
}
public static List nlTok(String s) {
return javaTokPlusPeriod(s);
}
public static AutoCloseable tempActivity(Object r) {
return null;
}
public static boolean allPaused() {
return ping_pauseAll;
}
public static void cancelTimer(javax.swing.Timer timer) {
if (timer != null)
timer.stop();
}
public static void cancelTimer(java.util.Timer timer) {
if (timer != null)
timer.cancel();
}
public static void cancelTimer(Object o) {
if (o instanceof java.util.Timer)
cancelTimer((java.util.Timer) o);
else if (o instanceof javax.swing.Timer)
cancelTimer((javax.swing.Timer) o);
else if (o instanceof AutoCloseable) {
try {
((AutoCloseable) o).close();
} catch (Throwable __e) {
_handleException(__e);
}
}
}
public static void bindTimerToComponent(final Timer timer, JFrame f) {
bindTimerToComponent(timer, f.getRootPane());
}
public static void bindTimerToComponent(final Timer timer, JComponent c) {
if (c.isShowing())
timer.start();
c.addAncestorListener(new AncestorListener() {
public void ancestorAdded(AncestorEvent event) {
timer.start();
}
public void ancestorRemoved(AncestorEvent event) {
timer.stop();
}
public void ancestorMoved(AncestorEvent event) {
}
});
}
public static char lastChar(String s) {
return empty(s) ? '\0' : s.charAt(l(s) - 1);
}
public static boolean swic(String a, String b) {
return startsWithIgnoreCase(a, b);
}
public static boolean swic(String a, String b, Matches m) {
if (!swic(a, b))
return false;
m.m = new String[] { substring(a, l(b)) };
return true;
}
public static boolean ewic(String a, String b) {
return endsWithIgnoreCase(a, b);
}
public static boolean ewic(String a, String b, Matches m) {
return endsWithIgnoreCase(a, b, m);
}
public static boolean containsNewLines(String s) {
return containsNewLine(s);
}
public static String jlabel_textAsHTML_center(String text) {
return "" + replace(htmlencode(text), "\n", "
") + "
";
}
public static A vm_generalMap_get(Object key) {
return (A) vm_generalMap().get(key);
}
public static Object vm_generalMap_put(Object key, Object value) {
return mapPutOrRemove(vm_generalMap(), key, value);
}
public static Set newWeakHashSet() {
return synchroWeakHashSet();
}
public static boolean isLocalSnippetID(String snippetID) {
return isSnippetID(snippetID) && isLocalSnippetID(psI(snippetID));
}
public static boolean isLocalSnippetID(long snippetID) {
return snippetID >= 1000 && snippetID <= 9999;
}
public static String localSnippetTitle(String snippetID) {
if (!isLocalSnippetID(snippetID))
return null;
File f = localSnippetFile(snippetID);
if (!f.exists())
return null;
return or2(getFileInfoField(dropExtension(f), "Title"), "Unnamed");
}
public static boolean isImageServerSnippet(long id) {
return id >= 1100000 && id < 1200000;
}
public static String imageServerURL() {
return or2(trim(loadTextFile(javaxDataDir("image-server-url.txt"))), "http://botcompany.de/images/raw/");
}
public static String muricaCredentialsQuery() {
return htmlQuery(muricaCredentials());
}
public static boolean isGeneralFileServerSnippet(long id) {
return id >= 1400000 && id < 1500000;
}
public static String tb_mainServer_default = "http://tinybrain.de:8080";
public static Object tb_mainServer_override;
public static String tb_mainServer() {
if (tb_mainServer_override != null)
return (String) callF(tb_mainServer_override);
return trim(loadTextFile(tb_mainServer_file(), tb_mainServer_default));
}
public static File tb_mainServer_file() {
return getProgramFile("#1001638", "mainserver.txt");
}
public static boolean tb_mainServer_isDefault() {
return eq(tb_mainServer(), tb_mainServer_default);
}
public static String standardCredentials_noCookies() {
return standardCredentials() + "&noCookies=1";
}
public static boolean saveTextFileIfChanged(File f, String contents) {
return saveTextFileIfDifferent(f, contents);
}
public static File snippetTitle_cacheFile(String snippetID) {
return javaxCachesDir("Snippet Titles/" + psI(snippetID));
}
public static String fsI(String id) {
return formatSnippetID(id);
}
public static String fsI(long id) {
return formatSnippetID(id);
}
public static Rect rect(int x, int y, int w, int h) {
return new Rect(x, y, w, h);
}
public static boolean jInternalFrame_iconifiable = true;
public static JInternalFrame jInternalFrame() {
return jInternalFrame("");
}
public static JInternalFrame jInternalFrame(final String title) {
return swing(new F0() {
public JInternalFrame get() {
try {
JInternalFrame f = new JInternalFrame(title, true, true, true, jInternalFrame_iconifiable);
f.setVisible(true);
return f;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JInternalFrame f = new JInternalFrame(title, true, true, true, jInternalFrame...";
}
});
}
public static void setInternalFrameContents(final Component c, final Object contents) {
{
swing(new Runnable() {
public void run() {
try {
JInternalFrame frame = getInternalFrame(c);
if (frame == null)
return;
frame.getContentPane().removeAll();
frame.getContentPane().setLayout(new BorderLayout());
if (contents != null)
frame.getContentPane().add(wrap(contents));
revalidate(frame);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JInternalFrame frame = getInternalFrame(c);\r\n if (frame == null) return;\r\n...";
}
});
}
}
public static A setBounds(final int x, final int y, final int w, final int h, final A a) {
if (a != null) {
swing(new Runnable() {
public void run() {
try {
a.setBounds(x, y, w, h);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "a.setBounds(x, y, w, h);";
}
});
}
return a;
}
public static A setBounds(final A a, final Rect r) {
if (a != null) {
swing(new Runnable() {
public void run() {
try {
a.setBounds(toRectangle(r));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "a.setBounds(toRectangle(r));";
}
});
}
return a;
}
public static A setBounds(A a, int x, int y, int w, int h) {
return setBounds(x, y, w, h, a);
}
public static void internalFrameDefaultPosition(JInternalFrame f) {
f.setSize(500, 300);
centerInternalFrame(f);
}
public static int fixInternalFrame_borderTopLeft = 0;
public static int fixInternalFrame_borderBottomRight = 40;
public static JInternalFrame fixInternalFrame(final JInternalFrame f) {
return swing(new F0() {
public JInternalFrame get() {
try {
Container c = f.getParent();
if (c == null)
return f;
Rect r = toRect(f.getBounds());
int a = fixInternalFrame_borderTopLeft, b = fixInternalFrame_borderBottomRight;
Rect outer = new Rect(a, a, c.getWidth() - b, c.getHeight() - b);
if (!rectContains(outer, r))
f.setLocation(max(a, min(r.x, outer.x2())), max(a, min(r.y, outer.y2())));
if (r.w > c.getWidth() || r.h > c.getHeight())
f.setSize(c.getWidth() - a, c.getHeight() - a);
return f;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Container c = f.getParent();\r\n if (c == null) ret f;\r\n Rect r = toRect(...";
}
});
}
public static int getScreenWidth() {
return getScreenSize().width;
}
public static int getScreenHeight() {
return getScreenSize().height;
}
public static String makeFrame_defaultIcon;
public static boolean makeFrame_hideConsole;
public static ThreadLocal> makeFrame_post = new ThreadLocal();
public static JFrame makeFrame() {
return makeFrame((Component) null);
}
public static JFrame makeFrame(Object content) {
return makeFrame(programTitle(), content);
}
public static JFrame makeFrame(String title) {
return makeFrame(title, null);
}
public static JFrame makeFrame(String title, Object content) {
return makeFrame(title, content, true);
}
public static JFrame makeFrame(final String title, final Object content, final boolean showIt) {
final VF1 post = optParam(makeFrame_post);
return swing(new F0() {
public JFrame get() {
try {
if (getFrame(content) != null)
return getFrame(setFrameTitle((Component) content, title));
final JFrame frame = new JFrame(title);
if (makeFrame_defaultIcon != null)
setFrameIconLater(frame, makeFrame_defaultIcon);
_initFrame(frame);
Component wrapped = wrap(content);
if (wrapped != null)
frame.getContentPane().add(wrapped);
frame.setBounds(defaultNewFrameBounds());
callF(post, frame);
if (showIt)
frame.setVisible(true);
if (showIt && makeFrame_hideConsole) {
hideConsole();
makeFrame_hideConsole = false;
}
return frame;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (getFrame(content) != null)\r\n ret getFrame(setFrameTitle((Component) ...";
}
});
}
public static boolean frameTooSmall(JFrame frame) {
return frame.getWidth() < 100 || frame.getHeight() < 50;
}
public static void frameStandardSize(JFrame frame) {
frame.setBounds(300, 100, 500, 400);
}
public static void setFrameContents(final Component c, final Object contents) {
{
swing(new Runnable() {
public void run() {
try {
JFrame frame = getFrame(c);
frame.getContentPane().removeAll();
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(wrap(contents));
revalidate(frame);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JFrame frame = getFrame(c);\r\n frame.getContentPane().removeAll();\r\n fra...";
}
});
}
}
public static Method findMethod(Object o, String method, Object... args) {
try {
if (o == null)
return null;
if (o instanceof Class) {
Method m = findMethod_static((Class) o, method, args, false);
if (m == null)
return null;
m.setAccessible(true);
return m;
} else {
Method m = findMethod_instance(o, method, args, false);
if (m == null)
return null;
m.setAccessible(true);
return m;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Method findMethod_static(Class c, String method, Object[] args, boolean debug) {
Class _c = c;
while (c != null) {
for (Method m : c.getDeclaredMethods()) {
if (debug)
System.out.println("Checking method " + m.getName() + " with " + m.getParameterTypes().length + " parameters");
;
if (!m.getName().equals(method)) {
if (debug)
System.out.println("Method name mismatch: " + method);
continue;
}
if ((m.getModifiers() & Modifier.STATIC) == 0 || !findMethod_checkArgs(m, args, debug))
continue;
return m;
}
c = c.getSuperclass();
}
return null;
}
public static Method findMethod_instance(Object o, String method, Object[] args, boolean debug) {
Class c = o.getClass();
while (c != null) {
for (Method m : c.getDeclaredMethods()) {
if (debug)
System.out.println("Checking method " + m.getName() + " with " + m.getParameterTypes().length + " parameters");
;
if (m.getName().equals(method) && findMethod_checkArgs(m, args, debug))
return m;
}
c = c.getSuperclass();
}
return null;
}
public static boolean findMethod_checkArgs(Method m, Object[] args, boolean debug) {
Class>[] types = m.getParameterTypes();
if (types.length != args.length) {
if (debug)
System.out.println("Bad parameter length: " + args.length + " vs " + types.length);
return false;
}
for (int i = 0; i < types.length; i++) if (!(args[i] == null || isInstanceX(types[i], args[i]))) {
if (debug)
System.out.println("Bad parameter " + i + ": " + args[i] + " vs " + types[i]);
return false;
}
return true;
}
public static List buttonsInGroup(ButtonGroup g) {
if (g == null)
return ll();
return asList(g.getElements());
}
public static Object[] asObjectArray(List l) {
return toObjectArray(l);
}
public static boolean containsNulls(Collection c) {
return contains(c, null);
}
public static Map similarEmptyMap(Map m) {
if (m instanceof TreeMap)
return new TreeMap(((TreeMap) m).comparator());
if (m instanceof LinkedHashMap)
return new LinkedHashMap();
return new HashMap();
}
public static Set keys(Map map) {
return map == null ? new HashSet() : map.keySet();
}
public static Set keys(Object map) {
return keys((Map) map);
}
public static A liftLast(List l) {
if (l.isEmpty())
return null;
int i = l(l) - 1;
A a = l.get(i);
l.remove(i);
return a;
}
public static List synchroList() {
return Collections.synchronizedList(new ArrayList());
}
public static List synchroList(List l) {
return Collections.synchronizedList(l);
}
public static Throwable innerException(Throwable e) {
return getInnerException(e);
}
public static void addActionListener(JTextField tf, final Runnable action) {
onEnter(tf, action);
}
public static 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));";
}
});
}
}
public static 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));";
}
});
}
}
public static String selectedItem(JList l) {
return getSelectedItem(l);
}
public static String selectedItem(JComboBox cb) {
return getSelectedItem(cb);
}
public static Map synchroHashMap() {
return Collections.synchronizedMap(new HashMap());
}
public static Class> _getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
return null;
}
}
public static Class _getClass(Object o) {
return o == null ? null : o instanceof Class ? (Class) o : o.getClass();
}
public static Class _getClass(Object realm, String name) {
try {
return getClass(realm).getClassLoader().loadClass(classNameToVM(name));
} catch (ClassNotFoundException e) {
return null;
}
}
public static boolean isUpperCaseLetter(char c) {
return Character.isUpperCase(c);
}
public static File getProgramFile(String progID, String fileName) {
if (new File(fileName).isAbsolute())
return new File(fileName);
return new File(getProgramDir(progID), fileName);
}
public static File getProgramFile(String fileName) {
return getProgramFile(getProgramID(), fileName);
}
public static Lock appendToFile_lock = lock();
public static boolean appendToFile_keepOpen;
public static HashMap appendToFile_writers = new HashMap();
public static void appendToFile(String path, String s) {
try {
Lock __113 = appendToFile_lock;
lock(__113);
try {
mkdirsForFile(new File(path));
path = getCanonicalPath(path);
Writer writer = appendToFile_writers.get(path);
if (writer == null) {
writer = new BufferedWriter(new OutputStreamWriter(newFileOutputStream(path, true), "UTF-8"));
if (appendToFile_keepOpen)
appendToFile_writers.put(path, writer);
}
writer.write(s);
if (!appendToFile_keepOpen)
writer.close();
} finally {
unlock(__113);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static void appendToFile(File path, String s) {
if (path != null)
appendToFile(path.getPath(), s);
}
public static void cleanMeUp_appendToFile() {
AutoCloseable __115 = tempCleaningUp();
try {
Lock __114 = appendToFile_lock;
lock(__114);
try {
closeAllWriters(values(appendToFile_writers));
appendToFile_writers.clear();
} finally {
unlock(__114);
}
} finally {
_close(__115);
}
}
public static JTextArea jTextArea() {
return jTextArea("");
}
public static JTextArea jTextArea(final String text) {
return swingNu(JTextArea.class, text);
}
public static File mkdirsForFile(File file) {
File dir = file.getParentFile();
if (dir != null) {
dir.mkdirs();
if (!dir.isDirectory())
if (dir.isFile())
throw fail("Please delete the file " + f2s(dir) + " - it is supposed to be a directory!");
else
throw fail("Unknown IO exception during mkdirs of " + f2s(file));
}
return file;
}
public static String mkdirsForFile(String path) {
mkdirsForFile(new File(path));
return path;
}
public static String getStackTrace2(Throwable e) {
return hideCredentials(getStackTrace(unwrapTrivialExceptionWraps(e)) + replacePrefix("java.lang.RuntimeException: ", "FAIL: ", hideCredentials(str(innerException2(e)))) + "\n");
}
public static ArrayList cloneListSynchronizingOn(Collection l, Object mutex) {
if (l == null)
return new ArrayList();
synchronized (mutex) {
return new ArrayList(l);
}
}
public static String asString(Object o) {
return o == null ? null : o.toString();
}
public static boolean startsWithIgnoreCase(String a, String b) {
return regionMatchesIC(a, 0, b, 0, b.length());
}
public static boolean endsWithIgnoreCase(String a, String b) {
int la = l(a), lb = l(b);
return la >= lb && regionMatchesIC(a, la - lb, b, 0, lb);
}
public static boolean endsWithIgnoreCase(String a, String b, Matches m) {
if (!endsWithIgnoreCase(a, b))
return false;
m.m = new String[] { substring(a, 0, l(a) - l(b)) };
return true;
}
public static boolean containsNewLine(String s) {
return contains(s, '\n');
}
public static 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;
}
public static String replace(String s, String a, String b) {
return s == null ? null : a == null || b == null ? s : s.replace(a, b);
}
public static String replace(String s, char a, char b) {
return s == null ? null : s.replace(a, b);
}
public static String htmlencode(Object o) {
return htmlencode(str(o));
}
public static String htmlencode(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("").append((int) c).append(';');
else
out.append(c);
}
return out.toString();
}
public static Map vm_generalMap_map;
public static Map vm_generalMap() {
if (vm_generalMap_map == null)
vm_generalMap_map = (Map) get(javax(), "generalMap");
return vm_generalMap_map;
}
public static Set synchroWeakHashSet() {
return Collections.newSetFromMap((Map) newWeakHashMap());
}
public static long psI(String snippetID) {
return parseSnippetID(snippetID);
}
public static File localSnippetFile(long snippetID) {
return localSnippetsDir(snippetID + ".text");
}
public static File localSnippetFile(String snippetID) {
return localSnippetFile(parseSnippetID(snippetID));
}
public static String getFileInfoField(File f, String field) {
return getOneLineFileInfoField(f, field);
}
public static File dropExtension(File f) {
return f == null ? null : fileInSameDir(f, dropExtension(f.getName()));
}
public static String dropExtension(String s) {
return takeFirst(s, smartLastIndexOf(s, '.'));
}
public static String htmlQuery(Map params) {
return params.isEmpty() ? "" : "?" + makePostData(params);
}
public static String htmlQuery(Object... data) {
return htmlQuery(litmap(data));
}
public static Object[] muricaCredentials() {
String pass = muricaPassword();
return nempty(pass) ? new Object[] { "_pass", pass } : new Object[0];
}
public static String standardCredentials() {
String user = standardCredentialsUser();
String pass = standardCredentialsPass();
if (nempty(user) && nempty(pass))
return "&_user=" + urlencode(user) + "&_pass=" + urlencode(pass);
return "";
}
public static boolean saveTextFileIfDifferent(File f, String contents) {
if (eq(loadTextFile(f), contents))
return false;
{
saveTextFile(f, contents);
return true;
}
}
public static File javaxCachesDir_dir;
public static File javaxCachesDir() {
return javaxCachesDir_dir != null ? javaxCachesDir_dir : new File(userHome(), "JavaX-Caches");
}
public static File javaxCachesDir(String sub) {
return newFile(javaxCachesDir(), sub);
}
public static Rectangle toRectangle(Rect r) {
return r == null ? null : r.getRectangle();
}
public static 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;
}
public static boolean rectContains(Rect a, Rect b) {
return b.x >= a.x && b.y >= a.y && b.x2() <= a.x2() && b.y2() <= a.y2();
}
public static String programTitle() {
return getProgramName();
}
public static A setFrameTitle(A c, final String title) {
final Frame f = getAWTFrame(c);
if (f != null) {
swing(new Runnable() {
public void run() {
try {
f.setTitle(title);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "f.setTitle(title);";
}
});
}
return c;
}
public static A setFrameTitle(String title, A c) {
return setFrameTitle(c, title);
}
public static JFrame setFrameTitle(String title) {
Object f = getOpt(mc(), "frame");
if (f instanceof JFrame)
return setFrameTitle((JFrame) f, title);
return null;
}
public static JFrame setFrameIconLater(Component c, final String imageID) {
final JFrame frame = getFrame(c);
if (frame != null)
startThread("Loading Icon", new Runnable() {
public void run() {
try {
final Image i = imageIcon(or2(imageID, "#1005557")).getImage();
swingLater(new Runnable() {
public void run() {
try {
frame.setIconImage(i);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "frame.setIconImage(i);";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "final Image i = imageIcon(or2(imageID, \"#1005557\")).getImage();\r\n swingL...";
}
});
return frame;
}
public static void _initFrame(JFrame f) {
myFrames_list.put(f, Boolean.TRUE);
standardTitlePopupMenu(f);
}
public static Rectangle defaultNewFrameBounds_r = new Rectangle(300, 100, 500, 400);
public static Rectangle defaultNewFrameBounds() {
return swing(new F0() {
public Rectangle get() {
try {
defaultNewFrameBounds_r.translate(60, 20);
if (!screenRectangle().contains(defaultNewFrameBounds_r))
defaultNewFrameBounds_r.setLocation(30 + random(30), 20 + random(20));
return new Rectangle(defaultNewFrameBounds_r);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "defaultNewFrameBounds_r.translate(60, 20);\r\n if (!screenRectangle().contai...";
}
});
}
public static void hideConsole() {
final JFrame frame = consoleFrame();
if (frame != null) {
autoVMExit();
swingLater(new Runnable() {
public void run() {
try {
frame.setVisible(false);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "frame.setVisible(false);";
}
});
}
}
public static Class> getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
return null;
}
}
public static Class getClass(Object o) {
return o instanceof Class ? (Class) o : o.getClass();
}
public static Class getClass(Object realm, String name) {
try {
try {
return getClass(realm).getClassLoader().loadClass(classNameToVM(name));
} catch (ClassNotFoundException e) {
return null;
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static String classNameToVM(String name) {
return name.replace(".", "$");
}
public static File getProgramDir() {
return programDir();
}
public static File getProgramDir(String snippetID) {
return programDir(snippetID);
}
public static String getCanonicalPath(String path) {
try {
return new File(path).getCanonicalPath();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static FileOutputStream newFileOutputStream(File path) throws IOException {
return newFileOutputStream(path.getPath());
}
public static FileOutputStream newFileOutputStream(String path) throws IOException {
return newFileOutputStream(path, false);
}
public static FileOutputStream newFileOutputStream(File path, boolean append) throws IOException {
return newFileOutputStream(path.getPath(), append);
}
public static FileOutputStream newFileOutputStream(String path, boolean append) throws IOException {
mkdirsForFile(path);
FileOutputStream f = new FileOutputStream(path, append);
_registerIO(f, path, true);
return f;
}
public static AutoCloseable tempCleaningUp() {
return tempSetTL(ping_isCleanUpThread, true);
}
public static void closeAllWriters(Collection extends Writer> l) {
for (Writer w : unnull(l)) {
try {
w.close();
} catch (Throwable __e) {
_handleException(__e);
}
}
}
public static Collection values(Map map) {
return map == null ? emptyList() : map.values();
}
public static String f2s(File f) {
return f == null ? null : f.getAbsolutePath();
}
public static String f2s(java.nio.file.Path p) {
return p == null ? null : f2s(p.toFile());
}
public static Throwable unwrapTrivialExceptionWraps(Throwable e) {
if (e == null)
return e;
while (e.getClass() == RuntimeException.class && e.getCause() != null && eq(e.getMessage(), str(e.getCause()))) e = e.getCause();
return e;
}
public static String replacePrefix(String prefix, String replacement, String s) {
if (!startsWith(s, prefix))
return s;
return replacement + substring(s, l(prefix));
}
public static boolean regionMatchesIC(String a, int offsetA, String b, int offsetB, int len) {
return a != null && a.regionMatches(true, offsetA, b, offsetB, len);
}
public static File localSnippetsDir() {
return javaxDataDir("Personal Programs");
}
public static File localSnippetsDir(String sub) {
return newFile(localSnippetsDir(), sub);
}
public static String getOneLineFileInfoField(File f, String field) {
File infoFile = associatedInfosFile(f);
List lines = lines(loadTextFile(infoFile));
return firstStartingWithIC_drop(lines, field + ": ");
}
public static File fileInSameDir(File f, String newName) {
return newFile(parentFile(f), newName);
}
public static List takeFirst(List l, int n) {
return l(l) <= n ? l : newSubListOrSame(l, 0, n);
}
public static List takeFirst(int n, List l) {
return takeFirst(l, n);
}
public static String takeFirst(int n, String s) {
return substring(s, 0, n);
}
public static String takeFirst(String s, int n) {
return substring(s, 0, n);
}
public static List takeFirst(int n, Iterable i) {
List l = new ArrayList();
Iterator it = i.iterator();
for (int _repeat_1572 = 0; _repeat_1572 < n; _repeat_1572++) {
if (it.hasNext())
l.add(it.next());
else
break;
}
return l;
}
public static int smartLastIndexOf(String s, char c) {
if (s == null)
return 0;
int i = s.lastIndexOf(c);
return i >= 0 ? i : l(s);
}
public static String makePostData(Map