Warning : session_start(): open(/var/lib/php/sessions/sess_2m788dr28fn79d8r0j43o7uj31, 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 net.dv8tion.jda.api.events.Event;
import net.dv8tion.jda.api.events.user.update.*;
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.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.dm_currentModule;
import static loadableUtils.utils.dm_current_mandatory;
import static loadableUtils.utils.match;
import static loadableUtils.utils.fieldType;
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.loadPageSilently;
import static loadableUtils.utils.loadSnippet;
import static loadableUtils.utils.componentPopupMenu;
import static loadableUtils.utils.componentPopupMenu_initForComponent;
import static loadableUtils.utils.dm_current_generic;
import static loadableUtils.utils.dm_current_mandatory_generic;
import static loadableUtils.utils.DynamicObject_loading;
import static loadableUtils.utils.rethrow;
import loadableUtils.utils.F0;
import loadableUtils.utils.F1;
import loadableUtils.utils.IF0;
import loadableUtils.utils.IF1;
import loadableUtils.utils.IVF1;
import loadableUtils.utils.IVF2;
import loadableUtils.utils.Matches;
import loadableUtils.utils.BetterLabel;
import loadableUtils.utils.SingleComponentPanel;
import loadableUtils.utils.Q;
import loadableUtils.utils.structure_Data;
import loadableUtils.utils.structure_ClassInfo;
import loadableUtils.utils.RGBImage;
import loadableUtils.utils.RGB;
import loadableUtils.utils.MultiSet;
import loadableUtils.utils.Concept;
import loadableUtils.utils.Concepts;
import loadableUtils.utils.RC;
import loadableUtils.utils.IterableIterator;
import loadableUtils.utils.PersistableThrowable;
import loadableUtils.utils.DynModule;
import loadableUtils.utils.DynPrintLog;
import loadableUtils.utils.Rect;
import loadableUtils.utils.Pt;
import java.text.*;
import java.text.SimpleDateFormat;
import java.nio.charset.Charset;
import java.text.NumberFormat;
import java.util.TimeZone;
import net.dv8tion.jda.api.events.guild.member.*;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.requests.restaction.MessageAction;
import net.dv8tion.jda.api.requests.RestAction;
import java.util.function.Consumer;
import javax.swing.undo.UndoManager;
import java.awt.datatransfer.StringSelection;
import java.awt.geom.*;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import net.dv8tion.jda.api.*;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.hooks.*;
import net.dv8tion.jda.api.events.message.*;
import net.dv8tion.jda.api.events.message.react.*;
import static net.dv8tion.jda.api.requests.GatewayIntent.*;
import javax.swing.border.*;
class main {
abstract static public class DynTalkBot2 extends DynServerAwareDiscordBot {
static public boolean _switchableField_myName = true;
public String myName = "Anonymous bot";
transient public boolean useAGIBlueForDropPunctuation = true;
transient public boolean preprocessAtSelfToMyName = true;
transient public boolean dropPunctuation = true;
transient public boolean ngbCommands = true;
public List authorizedUsers = ll(547706854680297473L);
static public class ISaid implements IFieldsToList {
public long channelID;
public long date;
public String text;
public ISaid() {
}
public ISaid(long channelID, long date, String text) {
this.text = text;
this.date = date;
this.channelID = channelID;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + channelID + ", " + date + ", " + text + ")";
}
public boolean equals(Object o) {
if (!(o instanceof ISaid))
return false;
ISaid __10 = (ISaid) o;
return channelID == __10.channelID && date == __10.date && eq(text, __10.text);
}
public int hashCode() {
int h = 69986258;
h = boostHashCombine(h, _hashCode(channelID));
h = boostHashCombine(h, _hashCode(date));
h = boostHashCombine(h, _hashCode(text));
return h;
}
public Object[] _fieldsToList() {
return new Object[] { channelID, date, text };
}
}
public void init() {
super.init();
onPostedInChannel.add((channel, msg) -> {
if (channel instanceof GuildChannel) {
Guild guild = ((GuildChannel) channel).getGuild();
if (guild == null)
return;
ByServer bs = getByServer(guild);
long channelID = ((GuildChannel) channel).getIdLong();
mapPut(bs.lastSaidInChannel, channelID, nu(ISaid.class, "channelID", channelID, "text", msg));
change();
}
});
dm_vmBus_onMessage_q("discordGuildJoin", new VF1() {
public void get(Map map) {
try {
{
if (!(map.get("module") == module()))
return;
}
print("Got join");
getByServer(getLong("guildID", map), true).onUserJoin(getLong("userID", map), map);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret unless map.get('module) == module();\r\n print(\"Got join\");\r\n get...";
}
});
onDiscordEvent(e -> {
if (e instanceof UserUpdateOnlineStatusEvent)
getByServer(((UserUpdateOnlineStatusEvent) e).getGuild()).onOnlineStatusChange((UserUpdateOnlineStatusEvent) e);
});
}
public class ByServer extends DynServerAwareDiscordBot.ByServer {
transient public Lock lock;
public List guildAuthorizedUsers = synchroList();
public Map lastSaidInChannel = synchroMap();
public long preferredChannelInGuild;
public DynTalkBot2 m2() {
return DynTalkBot2.this;
}
public void onUserJoin(long userID, Object... __) {
}
public void onOnlineStatusChange(UserUpdateOnlineStatusEvent e) {
}
public String myName() {
return myName;
}
@Override
public String answer(String input, Map map) {
if (preferredChannelInGuild == 0) {
long channelID = longPar("channelID", map);
if (channelID != 0) {
preferredChannelInGuild = channelID;
change();
}
}
String answer = processLine(input, map);
{
String __3 = super.answer(input, map);
if (!empty(__3))
return __3;
}
return answer;
}
public String dropMyPrefixOpt(String s) {
return or(dropMyPrefixOrNull(s), s);
}
public String dropMyPrefixOrNull(String s) {
String sOld = s;
s = dropPrefixICTrim_orNull(myPrefix(), s);
if (s == null)
print("no got prefix: " + quote(myPrefix()) + " / " + quote(sOld));
return s;
}
public String processLine(String s, Object... __) {
s = preprocess(s, __);
return processSimplifiedLine(s, __);
}
public String preprocess(String s, Object... __) {
print("Preprocessing: " + quote(s));
if (preprocessAtSelfToMyName && discordBotID != 0) {
List l = ll(atSelf(), atExclamSelf());
print("Replacing " + sfu(l));
s = replace_multi(s, l, " " + myName + " ");
print("Got " + quote(s));
}
if (dropPunctuation)
s = dropPunctuation3_withAGIBlue(useAGIBlueForDropPunctuation, s);
s = trim(simpleSpaces_noTok(s));
print("simplified >> " + quote(s));
return s;
}
public String myPrefix() {
return preprocessAtSelfToMyName ? (endsWithLetterOrDigit(myName()) ? myName() + " " : myName()) : (dropPunctuation ? replace(atSelf(), "@", "") : atSelf()) + " ";
}
synchronized public Lock myLock() {
if (lock == null)
lock = lock();
return lock;
}
public String processSimplifiedLine(String input, Object... __) {
Lock __1 = myLock();
lock(__1);
try {
Matches m = new Matches();
input = dropMyPrefixOrNull(input);
if (input == null)
return null;
if (ngbCommands) {
if (eqicOneOf(input, "support channel", "support server", "support"))
return "Get support for me here: " + nextGenBotsDiscordInvite();
if (eqicOneOf(input, "source", "sources", "source code"))
return snippetLink(programID());
}
if (swic_trim(input, "add master ", m)) {
String __4 = checkAuth(__);
if (!empty(__4))
return __4;
setAdd(authorizedUsers, parseFirstLong(m.rest()));
change();
return "Okidoki. Have " + n2(l(authorizedUsers), "master");
}
if (eqic(input, "masters"))
return linesLL("General: " + renderMasters(), "For this guild: " + renderGuildMasters());
if (eqic(input, "guild masters"))
return renderGuildMasters();
if (swic_trim(input, "delete master ", m)) {
String __5 = checkAuth(__);
if (!empty(__5))
return __5;
remove(authorizedUsers, parseFirstLong(m.rest()));
change();
return "Okidoki. Have " + n2(l(authorizedUsers), "master");
}
if (swic_trim(input, "add guild master ", m)) {
String __6 = checkPerGuildAuth(__);
if (!empty(__6))
return __6;
setAdd(guildAuthorizedUsers, parseFirstLong(m.rest()));
change();
return "Okidoki. " + renderGuildMasters();
}
if (swic_trim(input, "delete guild master ", m)) {
String __7 = checkPerGuildAuth(__);
if (!empty(__7))
return __7;
remove(guildAuthorizedUsers, parseFirstLong(m.rest()));
change();
return "Okidoki. " + renderGuildMasters();
}
if (eqic(input, "guild count")) {
String __8 = checkAuth(__);
if (!empty(__8))
return __8;
return renderGuildCount();
}
if (eqic(input, "guild names")) {
String __9 = checkAuth(__);
if (!empty(__9))
return __9;
return renderGuildNames();
}
return null;
} finally {
unlock(__1);
}
}
public String renderGuildMasters() {
return empty(guildAuthorizedUsers) ? "Only this guild's owner can control me." : "I am controlled by this guild's owner and these people: " + joinWithComma(map(__46 -> discordAtPlusID(__46), guildAuthorizedUsers));
}
public String renderGuildCount() {
return "Total guilds joined: " + guildCount + ". Live guilds: " + liveGuildCount();
}
public String renderGuildNames() {
return lines(map(discord.getGuilds(), g -> g.getName()));
}
public boolean authed(Object... __) {
return contains(authorizedUsers, optPar("userID", __));
}
public boolean perGuildAuthed(Object... __) {
long userID = longPar("userID", __);
return contains(guildAuthorizedUsers, userID) || guildID != 0 && userID == getGuild().getOwnerIdLong();
}
public Guild getGuild() {
return guildID == 0 ? null : discord.getGuildById(guildID);
}
public String checkAuth(Object... __) {
long userID = longPar("userID", __);
boolean result = authed(__);
print("Auth-checking user ID: " + userID + " => " + result);
if (!result)
return "You are not authorized";
return null;
}
public String checkPerGuildAuth(Object... __) {
if (authed(__))
return null;
long userID = longPar("userID", __);
boolean result = perGuildAuthed(__);
print("Guild-auth-checking user ID: " + userID + " => " + result);
if (!result)
return "You are not authorized";
return null;
}
public String guildStructure() {
return structure_nullingInstancesOfClass(_getClass(module()), this);
}
public String atSelfOrMyName() {
return preprocessAtSelfToMyName ? myName() : atSelf();
}
public String atSelfOrMyName_space() {
return preprocessAtSelfToMyName ? appendSpaceIfEndsWithLetter(myName) : atSelf();
}
public String guildMastersHelp() {
return "\r\n@me **masters** -- show who controls me\r\n@me **add guild master @user** -- allow @user to control me\r\n@me **delete guild master @user** -- @user can no longer control me\r\n";
}
}
public String serveGuildBackup(MessageChannel channel, Guild guild, String data) {
if (guild == null)
return "Do this in a guild";
if (containsDiscordToken(data))
return "DISCORD TOKEN EXPOSED ALARM!! NOTIFY ADMINISTRATOR";
String baseName = urlencode(jda_selfUserName(discord)) + "-" + guild.getIdLong() + "-" + ymd_minus_hms();
String zipName = baseName + ".zip";
File zip = programFile("backups/" + zipName);
createZipFileWithSingleTextFile(zip, baseName + ".txt", data);
channel.sendMessage("Here's my latest brain contents for this guild.").addFile(zip).queue();
return null;
}
public String serveGuildBackup(MessageChannel channel, Guild guild, ByServer bs) {
return serveGuildBackup(channel, guild, bs.guildStructure());
}
public String renderMasters() {
return empty(authorizedUsers) ? "I have no masters." : "My masters are: " + joinWithComma(map(__47 -> discordAtPlusID(__47), authorizedUsers));
}
}
static public class RolesExporter extends DynTalkBot2 {
public void init() {
super.init();
makeByServer = () -> new ByServer();
useAGIBlueForDropPunctuation = false;
preprocessAtSelfToMyName = false;
print("All permissions: " + Permission.ALL_PERMISSIONS);
if (myName == null)
setField("myName", "HyperCubes");
preprocessAtSelfToMyName = true;
escapeAtEveryone = true;
dropPunctuation = false;
onDiscordStarted(new Runnable() {
public void run() {
try {
doEveryAndNow(20.0, new Runnable() {
public void run() {
try {
gazelle_discord_playingGame(status);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "gazelle_discord_playingGame(status)";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "doEveryAndNow(20.0, r { gazelle_discord_playingGame(status) });";
}
});
}
transient public String discordInvite = "https://discord.gg/RXqf97d";
transient public String status = discordInvite;
public class ByServer extends DynTalkBot2.ByServer {
public boolean qaEnabled = true;
synchronized public String processSimplifiedLine(String s, Object... __) {
String __24 = super.processSimplifiedLine(s, __);
if (!empty(__24))
return __24;
long channelID = (long) (optPar("channelID", __));
if (channelID == 0)
return null;
Message msg = (Message) (optPar("msg", __));
Message.Attachment attachment = msg == null ? null : first(msg.getAttachments());
if (attachment != null) {
File file = appendToFileName(downloadFileForChannel(channelID), "." + now());
print("Downloading attachment " + attachment.getFileName() + " to " + file);
boolean authed = checkPerms(msg) == null;
deleteFile(file);
attachment.downloadToFile(file).exceptionally(error -> {
AutoCloseable __29 = enter();
try {
print("download fail");
{
postInChannel(channelID, "Couldn't download attachment");
return null;
}
} finally {
_close(__29);
}
}).thenAccept(file2 -> postInChannel(channelID, handleAttachment(file2, channelID, authed)));
}
MessageChannel channel = (MessageChannel) (optPar("channel", __));
String s1 = s;
if ((s = dropMyPrefixOrNull(s)) != null)
try {
if (match("help", s)) {
EmbedBuilder eb = new EmbedBuilder();
eb.setColor(toColor("F14527"));
eb.setAuthor(fancyName(), null, null);
eb.setTitle("Backup Your Discord Roles", null);
eb.setDescription("\r\nIn next update: Manage roles, full layout + roles backup\r\n\r\n(This bot is still under development, many features will be added later on.)\r\n\r\nType `HyperCubes howto` for a short tutorial.\r\n\r\nIf you like to support this project, join us at and consider donating. We thank you in advance\r\n\r\nIf you are interested to make your own smart bot, visit \r\n");
discordEmbed_addField(eb, "Upload", "Upload a JSON file to channel to inspect/import it");
String syntax = "\r\nExport roles + members as JSON\r\n` HyperCubes export [e]`\r\nCheck bot's rights\r\n` HyperCubes rights [r]`\r\n\r\nDiff last upload against server\r\n` HyperCubes compare [c]`\r\nAdd missing roles from last upload\r\n` HyperCubes add roles [ar]`\r\nList roles that members should have according to last import\r\n` HyperCubes list missing roles [lmr]`\r\nAdd all roles mentioned in last line\r\n` HyperCubes add member roles [amr]`\r\n\r\nList roles not used in current server\r\n` HyperCubes unused roles [ur]`\r\nDelete unused roles\r\n` HyperCubes delete unused roles [dur]`\r\n\r\nInvite bot to other server\r\n` HyperCubes invite `\r\n";
discordEmbed_addField(eb, "Syntax (abbreviations in brackets)", syntax);
eb.setThumbnail(imageSnippetURL_noHttps("#1102865"));
channel.sendMessage(eb.build()).queue();
return null;
}
if (match("howto", s) || match("how to", s) || match("how-to", s) || match("tutorial", s)) {
EmbedBuilder eb = new EmbedBuilder();
eb.setColor(toColor("F14527"));
eb.setAuthor(fancyName(), null, null);
eb.setTitle(" ", null);
eb.setDescription("\r\n**How to copy roles from an old server to a new one**\r\n\r\nIn the old server, type `HyperCubes export` which gives you a JSON file.\r\n\r\nIn a channel in the new server:\r\n*Simply upload the JSON file as an attachment. You will see a list of all differences in members+roles\r\n*Type `HyperCubes lmr` to see missing roles\r\n*Type `HyperCubes amr` to create missing roles and assign them to appropriate members \r\n ");
channel.sendMessage(eb.build()).queue();
return null;
}
if (match("export", s) || match("e", s))
return uploadFileInChannel(channelID, toUtf8(jsonEncode_breakAtNLevels(3, makeData())), "members-and-roles-" + guild.getIdLong() + ".json.txt", null, null);
if (match("rights", s) || match("r", s))
return canManageRoles() ? "I have the right to manage roles. I have everything I want!" : "I am not authorized to manage roles, so I can only preview changes, not perform them.";
if (match("compare", s) || match("c", s)) {
File f = downloadFileForChannel(channelID);
if (!fileExists(f))
return "No past upload found in this channel";
return pairA(diff(f));
}
if (match("add roles", s) || match("ar", s))
return or2(addRoles(__), "Nothing to do");
if (match("unused roles", s) || match("ur", s))
return or2(lines(unusedRoles()), "No unused roles");
if (match("delete unused roles", s) || match("dur", s)) {
String __25 = checkPerms(msg);
if (!empty(__25))
return __25;
return or2(mapToLines(unusedRoles(), role -> {
queue(role.delete());
return "Deleted role: " + role.getName();
}), "No unused roles");
}
if (match("list missing roles", s) || match("lmr", s))
return or2(missingMemberRoles(false, __), "Nothing to do");
if (match("add member roles", s) || match("amr", s)) {
String __26 = checkPerms(msg);
if (!empty(__26))
return __26;
String a = addRoles(__);
return or2(a + missingMemberRoles(true, __), "Nothing to do");
}
if (match("stats", s))
return "Brains: " + l(dataByServer) + "\n" + "Persistent data size: " + (l(dm_moduleStruct()) + l(conceptsFile()));
if (match("invite", s))
return "Invite me to a server: <" + discordBotInviteLink(discordBotID, discord_adminPermission()) + ">\n" + "Join my Discord: <" + discordInvite + ">";
} catch (Throwable e) {
printStackTrace(e);
return "Internal error: " + e;
}
if (qaEnabled) {
String __27 = webBot_answer(s1, "#1026544");
if (!empty(__27))
return __27;
}
return null;
}
public String missingMemberRoles(boolean doIt, Object... __) {
long channelID = (long) (optPar("channelID", __));
Either p = diffWithLastUpload(channelID);
if (!isB(p))
return eitherGetA(p);
Map diff = (Map) (p.b());
Map membersDiff = (Map) (mapGet(diff, "members"));
List buf = new ArrayList();
for (Map.Entry extends JsonDiff.GatheredKey, ? extends Object> __22 : _entrySet(unnull(membersDiff))) {
JsonDiff.GatheredKey memberID = __22.getKey();
Object memberDiff = __22.getValue();
long _memberID = (long) memberID.get();
Member member = guild.getMemberById(_memberID);
if (member == null)
continue;
if (memberDiff instanceof Map) {
Collection roleDiffs = values((Map) get("roles", (Map) memberDiff));
for (Object roleDiff : roleDiffs) if (roleDiff instanceof JsonDiff.Added) {
String roleName = getString("name", ((JsonDiff.Added) roleDiff).b);
buf.add(discordAt(_memberID) + " needs role " + roleName);
if (doIt) {
List roles = guild.getRolesByName(roleName, false);
if (empty(roles))
buf.add("Role " + quote(roleName) + " not found");
for (Role role : roles) {
queue(guild.addRoleToMember(member, role));
buf.add(" Added role " + role);
}
}
}
}
}
return lines(buf);
}
public List unusedRoles() {
return filter(guild.getRoles(), r -> empty(guild.getMembersWithRoles(r)));
}
public String checkPerms(Message msg) {
if (!msg.getMember().hasPermission(Permission.MANAGE_ROLES))
return "You have no permission to do that you sneaky boy";
return null;
}
public File downloadFileForChannel(long channelID) {
return prepareCacheProgramFile(guildID + "/" + channelID);
}
public boolean canManageRoles() {
return guild.getSelfMember().hasPermission(Permission.MANAGE_ROLES);
}
public Map makeData() {
List roles = map(guild.getRoles(), r -> litorderedmap("name", r.getName(), "id", r.getIdLong(), "permissions", r.getPermissionsRaw()));
List members = map(guild.getMembers(), m -> litorderedmap("nickName", m.getNickname(), "effectiveName", m.getEffectiveName(), "userName", m.getUser().getName(), "id", m.getIdLong(), "isOwner", trueOrNull(m.isOwner()), "roles", map(m.getRoles(), r -> litorderedmap("name", r.getName(), "id", r.getIdLong()))));
return litorderedmap("dataType", "members and roles for guild", "dateExported", dateWithSecondsGMT(), "guild", litorderedmap("name", guild.getName(), "id", guild.getIdLong()), "roles", roles, "members", members);
}
public String handleAttachment(File file, long channelID, boolean authed) {
AutoCloseable __30 = enter();
try {
try {
print("Handling attachment " + f2s(file));
Object json;
try {
json = decodeJson(loadTextFile(file));
} catch (Throwable e) {
{
print("Not a JSON file: " + f2s(file));
return null;
}
}
if (!isMyKindOfData(json))
return null;
String a = "";
if (authed) {
copyFile(file, downloadFileForChannel(channelID));
a = "Saving upload\n";
}
return a + unnull(pairA(diff(file)));
} catch (Throwable e) {
printStackTrace(e);
return "Internal error";
}
} finally {
_close(__30);
}
}
public Pair diff(File file) {
Object json;
try {
json = decodeJson(loadTextFile(file));
} catch (Throwable e) {
{
print("Not a JSON file: " + f2s(file));
return null;
}
}
fixImportedData(json);
JsonDiff differ = new JsonDiff();
differ.getListKey = path -> eq(last(path), "roles") ? "name" : "id";
Object diff = differ.diff(makeData(), json);
return pair("Differences:\n" + nicelyFormatJsonDiff(diff), diff);
}
public void fixImportedData(Object data) {
changeKey((Map) data, "allRoles", "roles");
}
public boolean isMyKindOfData(Object data) {
return isMap(data) && containsOneKeyOf((Map) data, "roles", "allRoles");
}
public Either diffWithLastUpload(long channelID) {
File f = downloadFileForChannel(channelID);
if (!fileExists(f))
return eitherA("No past upload found in this channel");
Pair p = diff(f);
if (p == null)
return eitherA("There was an error with the last upload");
return eitherB(p.b);
}
public String addRoles(Object... __) {
Message msg = (Message) (optPar("msg", __));
long channelID = (long) (optPar("channelID", __));
{
String __28 = checkPerms(msg);
if (!empty(__28))
return __28;
}
Either p = diffWithLastUpload(channelID);
if (!isB(p))
return eitherGetA(p);
Map diff = (Map) (p.b());
Map rolesDiff = (Map) (mapGet(diff, "roles"));
print("rolesDiff", rolesDiff);
List buf = new ArrayList();
for (Map.Entry extends JsonDiff.GatheredKey, ? extends Object> __21 : _entrySet(unnull(rolesDiff))) {
JsonDiff.GatheredKey roleName = __21.getKey();
Object roleDiff = __21.getValue();
if (roleDiff instanceof JsonDiff.Added) {
Map roleMap = (Map) (((JsonDiff.Added) roleDiff).b);
print("roleMap", roleMap);
String name = getString("name", roleMap);
long permissions = getLong("permissions", roleMap);
guild.createRole().setName(name).setPermissions(permissions & Permission.ALL_PERMISSIONS).complete();
buf.add("Added role " + quote(name));
}
}
return lines(buf);
}
public String fancyName() {
return hexToUTF8("e2848d20e284bd20e2849920e284b020e2849b20e2848220e182ae20e284ac20e284b020d58f");
}
}
}
static public boolean _moduleClass_RolesExporter = true;
static public String programID;
static public void _onLoad_initUtils() {
utils.__javax = javax();
}
static public void _onLoad_defaultClassFinder() {
setDefaultClassFinder(new F1() {
public Class get(String name) {
Class c = findClass_fullName(name);
if (c != null)
return c;
if (name.startsWith("main$"))
return loadableUtils.utils.findClass_fullName("loadableUtils.utils" + name.substring(4));
return null;
}
});
}
static public ThreadLocal dynamicObjectIsLoading_threadLocal() {
return DynamicObject_loading;
}
static volatile public Concepts mainConcepts;
static public Concepts db_mainConcepts() {
if (mainConcepts == null)
mainConcepts = newConceptsWithClassFinder(getDBProgramID());
return mainConcepts;
}
static public void cleanMeUp_concepts() {
if (db_mainConcepts() != null)
db_mainConcepts().cleanMeUp();
}
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 String shortClassName_dropNumberPrefix(Object o) {
return dropNumberPrefix(shortClassName(o));
}
static public boolean eq(Object a, Object b) {
return a == b || a != null && b != null && a.equals(b);
}
static public boolean eq(Symbol a, String b) {
return eq(str(a), 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 void mapPut(Map map, A key, B value) {
if (map != null && key != null && value != null)
map.put(key, value);
}
static public void mapPut(Map map, Pair p) {
if (map != null && p != null)
map.put(p.a, p.b);
}
static public A nu(Class c, Object... values) {
A a = nuObject(c);
setAll(a, values);
return a;
}
static public void change() {
callOpt(getOptMC("mainConcepts"), "allChanged");
}
static public AutoCloseable dm_vmBus_onMessage_q(final String msg, final VF1 onMessage) {
final DynModule m = dm_current_mandatory();
return dm_vmBus_onMessage(msg, new VF1 () {
public void get(final A a) {
try {
m.q().add(new Runnable() {
public void run() {
try {
callF(onMessage, a);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, a);";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "switch to m.q();\r\n callF(onMessage, a);";
}
});
}
static public AutoCloseable dm_vmBus_onMessage_q(final String msg, final IVF1 onMessage) {
final DynModule m = dm_current_mandatory();
return dm_vmBus_onMessage(msg, new VF1 () {
public void get(final A a) {
try {
m.q().add(new Runnable() {
public void run() {
try {
callF(onMessage, a);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, a);";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "switch to m.q();\r\n callF(onMessage, a);";
}
});
}
static public AutoCloseable dm_vmBus_onMessage_q(final String msg, final IVF2 onMessage) {
final DynModule m = dm_current_mandatory();
return dm_vmBus_onMessage(msg, new VF2 () {
public void get(A a, B b) {
try {
m.q().add(new Runnable() {
public void run() {
try {
callF(onMessage, a, b);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, a, b);";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "switch to m.q();\r\n callF(onMessage, a, b);";
}
});
}
static public AutoCloseable dm_vmBus_onMessage_q(final String msg, final IVF3 onMessage) {
DynModule m = dm_current_mandatory();
return dm_vmBus_onMessage(msg, new VF3 () {
public void get(A a, B b, C c) {
try {
m.q().add(new Runnable() {
public void run() {
try {
callF(onMessage, a, b, c);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, a, b, c);";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "switch to m.q();\r\n callF(onMessage, a, b, c);";
}
});
}
static public AutoCloseable dm_vmBus_onMessage_q(final String msg, final VF2 onMessage) {
final DynModule m = dm_current_mandatory();
return dm_vmBus_onMessage(msg, new VF2 () {
public void get(final A a, final B b) {
try {
m.q().add(new Runnable() {
public void run() {
try {
callF(onMessage, a, b);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, a, b);";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "switch to m.q();\r\n callF(onMessage, a, b);";
}
});
}
static public AutoCloseable dm_vmBus_onMessage_q(final String msg, final VF3 onMessage) {
final DynModule m = dm_current_mandatory();
return dm_vmBus_onMessage(msg, new VF3 () {
public void get(final A a, final B b, final C c) {
try {
m.q().add(new Runnable() {
public void run() {
try {
callF(onMessage, a, b, c);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, a, b, c);";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "switch to m.q();\r\n callF(onMessage, a, b, c);";
}
});
}
static public AutoCloseable dm_vmBus_onMessage_q(final String msg, final Runnable onMessage) {
final DynModule m = dm_current_mandatory();
return dm_vmBus_onMessage(msg, new VF1 () {
public void get(final A a) {
try {
m.q().add(new Runnable() {
public void run() {
try {
callF(onMessage);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage);";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "switch to m.q();\r\n callF(onMessage);";
}
});
}
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(combinePrintParameters(s, o));
return o;
}
static public A print(A o) {
ping_okInCleanUp();
if (print_silent)
return o;
String s = o + "\n";
print_noNewLine(s);
return o;
}
static public void print_noNewLine(String s) {
try {
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;
} catch (Throwable e) {
System.out.println(getStackTrace(e));
}
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);
vmBus_send("printed", mc(), s);
}
static public void print_autoRotate() {
}
static public long getLong(Object o, String field) {
return toLong(getOpt(o, field));
}
static public long getLong(String field, Object o) {
return getLong(o, field);
}
static public List synchroList() {
return synchroList(new ArrayList ());
}
static public List synchroList(List l) {
return Collections.synchronizedList(l);
}
static public Map synchroMap() {
return synchroHashMap();
}
static public Map synchroMap(Map map) {
return Collections.synchronizedMap(map);
}
static public long longPar(String name, Object... params) {
return toLong(optPar(name, params));
}
static public boolean empty(Collection c) {
return c == null || c.isEmpty();
}
static public boolean empty(Iterable c) {
return c == null || !c.iterator().hasNext();
}
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(BitSet bs) {
return bs == null || bs.isEmpty();
}
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(MultiMap mm) {
return mm == null || mm.isEmpty();
}
static public boolean empty(File f) {
return getFileSize(f) == 0;
}
static public boolean empty(Rect r) {
return !(r != null && r.w != 0 && r.h != 0);
}
static public A or(A a, A b) {
return a != null ? a : b;
}
static public String dropPrefixICTrim_orNull(String prefix, String s) {
return swic(s, prefix) ? trim(s.substring(l(prefix))) : null;
}
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 == '\t')
out.append("\\t");
else if (c == '\0')
out.append("\\0");
else
out.append(c);
}
out.append('"');
}
static public String sfu(Object o) {
return structureForUser(o);
}
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 String dropPunctuation3_withAGIBlue(boolean useAGIBlue, String s) {
return useAGIBlue ? dropPunctuation3_withAGIBlue(s) : dropPunctuation3(s);
}
static public String dropPunctuation3_withAGIBlue(String s) {
if (!agiBlue_validPageName(s))
return dropPunctuation3(s);
String y = dropPunctuation3_cache.get(s);
if (y != null)
return y;
{
String __1 = agiBlue_lookupInSlice_pcall("xwxxvxozhdlwsxzj", s, "dropPunctuation");
if (!empty(__1))
return __1;
}
y = dropPunctuation3(s);
agiBlue_postInSlice_pcall("xwxxvxozhdlwsxzj", s, "dropPunctuation", y);
return y;
}
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 String simpleSpaces_noTok(String s) {
return s == null ? null : s.replaceAll("\\s+", " ");
}
static public boolean endsWithLetterOrDigit(String s) {
return s != null && s.length() > 0 && Character.isLetterOrDigit(s.charAt(s.length() - 1));
}
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 void lock(Lock lock) {
try {
ping();
if (lock == null)
return;
try {
vmBus_send("locking", lock, "thread", currentThread());
lock.lockInterruptibly();
vmBus_send("locked", lock, "thread", currentThread());
} catch (InterruptedException e) {
Object reason = vm_threadInterruptionReasonsMap().get(currentThread());
print("Locking interrupted! Reason: " + strOr(reason, "Unknown"));
printStackTrace(e);
rethrow(e);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public void lock(Lock lock, String msg) {
print("Locking: " + msg);
lock(lock);
}
static public void lock(Lock lock, String msg, long timeout) {
print("Locking: " + msg);
lockOrFail(lock, timeout);
}
static public ReentrantLock lock() {
return fairLock();
}
static public boolean eqicOneOf(String s, String... l) {
for (String x : l) if (eqic(s, x))
return true;
return false;
}
static public String nextGenBotsDiscordInvite() {
return "https://discord.gg/kcKKZEg";
}
static public String snippetLink(String id) {
return empty(id) ? id : snippetLink(parseSnippetID(id));
}
static public String snippetLink(long id) {
return "https://code.botcompany.de/" + id;
}
static public String programID() {
return getProgramID();
}
static public String programID(Object o) {
return getProgramID(o);
}
static public boolean swic_trim(String a, String b, Matches m) {
if (!swic(a, b))
return false;
m.m = new String[] { trim(substring(a, l(b))) };
return true;
}
static public boolean setAdd(Collection c, A a) {
if (c == null || c.contains(a))
return false;
c.add(a);
return true;
}
static public long parseFirstLong(String s) {
return parseLong(jextract("", s));
}
static public String n2(long l) {
return formatWithThousands(l);
}
static public String n2(AtomicLong l) {
return n2(l.get());
}
static public String n2(Collection l) {
return n2(l(l));
}
static public String n2(Map map) {
return n2(l(map));
}
static public String n2(double l, String singular) {
return empty(singular) ? str(l) : 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 empty(singular) ? n2(l) : 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(long[] a, String singular) {
return n2(l(a), 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 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(Symbol a, Symbol b) {
return eq(a, b);
}
static public boolean eqic(Symbol a, String b) {
return eqic(asString(a), 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 String linesLL(Object... x) {
return lines(ll(x));
}
static public void remove(List l, int i) {
if (l != null && i >= 0 && i < l(l))
l.remove(i);
}
static public void remove(Collection l, A a) {
if (l != null)
l.remove(a);
}
static public B remove(Map map, Object a) {
return map == null ? null : map.remove(a);
}
static public void remove(BitSet bs, int i) {
bs.clear(i);
}
static public void unlock(Lock lock, String msg) {
if (lock == null)
return;
lock.unlock();
vmBus_send("unlocked", lock, "thread", currentThread());
print("Unlocked: " + msg);
}
static public void unlock(Lock lock) {
if (lock == null)
return;
lock.unlock();
vmBus_send("unlocked", lock, "thread", currentThread());
}
static public String joinWithComma(Collection c) {
return join(", ", c);
}
static public String joinWithComma(Object... 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 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) {
ping();
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) {
ping();
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) {
ping();
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) {
ping();
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()) {
ping();
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 List map(IF1 f, A data1, A... moreData) {
List x = emptyList(l(moreData) + 1);
x.add(f.get(data1));
if (moreData != null)
for (A o : moreData) {
ping();
x.add(f.get(o));
}
return x;
}
static public String discordAtPlusID(long userID) {
return userID == 0 ? "unknown person" : "<@" + userID + "> (" + userID + ")";
}
static public String lines(Iterable lines) {
return fromLines(lines);
}
static public String lines(Object[] lines) {
return fromLines(asList(lines));
}
static public List lines(String s) {
return toLines(s);
}
static public String lines(Iterable l, IF1 f) {
return mapToLines(l, f);
}
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 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 String structure_nullingInstancesOfClass(Class c, Object o) {
if (c == null)
return structure(o);
structure_Data data = new structure_Data();
structure_ClassInfo info = new structure_ClassInfo();
info.special = info.nullInstances = true;
data.infoByClass.put(c, info);
return structure(o, data);
}
static public Class> _getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
return null;
}
}
static public Class _getClass(Object o) {
return o == null ? null : o instanceof Class ? (Class) o : o.getClass();
}
static public Class _getClass(Object realm, String name) {
try {
return classLoaderForObject(realm).loadClass(classNameToVM(name));
} catch (ClassNotFoundException e) {
return null;
}
}
static public String appendSpaceIfEndsWithLetter(String s) {
return endsWithLetter(s) ? s + " " : s;
}
static public boolean containsDiscordToken(String s) {
return regexpFind(discordTokenRegexp(), s);
}
static public String urlencode(String x) {
try {
return URLEncoder.encode(unnull(x), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
static public String jda_selfUserName(JDA jda) {
return jda_selfUser(jda).getName();
}
static public String ymd_minus_hms() {
return ymd() + "-" + hms();
}
static public File programFile(String name) {
return prepareProgramFile(name);
}
static public File programFile(String progID, String name) {
return prepareProgramFile(progID, name);
}
static public File createZipFileWithSingleTextFile(File zipFile, String name, String text) {
ZipOutputStream outZip = newZipOutputStream(zipFile);
try {
zip_addTextFile(outZip, name, text);
return zipFile;
} finally {
_close(outZip);
}
}
static public FixedRateTimer doEveryAndNow(int delay, Object r) {
return doEveryStartingNow(delay, r);
}
static public FixedRateTimer doEveryAndNow(double delay, Object r) {
return doEveryStartingNow(toInt(toMS(delay)), r);
}
static public void gazelle_discord_playingGame(String gameName) {
Object presence = gazelle_discordPresence();
Object game = call(getClass_vmName(gazelle_jda(), "net.dv8tion.jda.core.entities.Game"), "playing", gameName);
if (game != null)
call(presence, "setGame", game);
else {
Object activity = call(getClass_vmName(gazelle_jda(), "net.dv8tion.jda.api.entities.Activity"), "playing", gameName);
call(presence, "setActivity", activity);
}
}
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 Pair first(Map map) {
return mapEntryToPair(first(entrySet(map)));
}
static public 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 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 Character first(CharSequence 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 A first(A[] l, IF1 pred) {
return firstThat(l, pred);
}
static public A first(Iterable l, IF1 pred) {
return firstThat(l, pred);
}
static public A first(IF1 pred, Iterable l) {
return firstThat(pred, l);
}
static public File appendToFileName(File f, String suffix) {
return fileAppendToName(f, suffix);
}
static public File appendToFileName(String suffix, File f) {
return appendToFileName(f, suffix);
}
static public long now_virtualTime;
static public long now() {
return now_virtualTime != 0 ? now_virtualTime : System.currentTimeMillis();
}
static public boolean deleteFile(File file) {
return file != null && file.delete();
}
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 Color toColor(RGB rgb) {
return rgb == null ? null : rgb.getColor();
}
static public Color toColor(int rgb) {
return new Color(rgb);
}
static public Color toColor(String hex) {
return awtColor(hex);
}
static public Color toColor(int[] rgb) {
return new Color(rgb[0], rgb[1], rgb[2]);
}
static public int discordEmbed_addField_maxLength = 800;
static public void discordEmbed_addField(EmbedBuilder eb, String field, String text) {
int n = 1;
while (l(text) > discordEmbed_addField_maxLength) {
ping();
List lines = lines(text);
StringBuilder buf = new StringBuilder();
int i = 0;
while (i < l(lines) && l(buf) + l(lines.get(i)) + 1 <= discordEmbed_addField_maxLength) buf.append(lines.get(i++)).append("\n");
String part = str(buf);
if (i == 0) {
part = takeFirst(text, discordEmbed_addField_maxLength);
text = substring(text, discordEmbed_addField_maxLength);
} else
text = lines(subList(lines, i));
eb.addField(appendNumberUnless1(field, n++), part, false);
}
if (!emptyAfterTrim(text))
eb.addField(appendNumberUnless1(field, n), text, false);
}
static public String imageSnippetURL_noHttps(String snippetID) {
return snippetImageURL_noHttps(snippetID);
}
static public String imageSnippetURL_noHttps(String snippetID, String contentType) {
return snippetImageURL_noHttps(snippetID, contentType);
}
static public byte[] toUtf8(String s) {
try {
return s.getBytes(utf8charset());
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public String jsonEncode_breakAtNLevels(int levels, Object o) {
StringBuilder buf = new StringBuilder();
jsonEncode_breakAtNLevels(1, levels, o, buf);
return str(buf);
}
static public void jsonEncode_breakAtNLevels(int level, int levels, Object o, StringBuilder buf) {
if (o == null)
buf.append("null");
else if (o instanceof String)
buf.append(quote((String) o));
else if (o instanceof Number || o instanceof Boolean)
buf.append(o);
else if (o instanceof Map) {
Map map = (Map) o;
buf.append("{");
boolean first = true;
for (Object key : keys(map)) {
if (first)
first = false;
else
buf.append(",");
if (level <= levels)
buf.append("\n" + indent(level * 2));
buf.append(quote((String) key));
buf.append(":");
jsonEncode_breakAtNLevels(level + 1, levels, map.get(key), buf);
}
if (level <= levels)
buf.append("\n" + indent((level - 1) * 2));
buf.append("}");
} else if (o instanceof Collection) {
Collection l = (Collection) o;
buf.append("[");
boolean first = true;
for (Object element : l) {
if (first)
first = false;
else
buf.append(",");
if (level <= levels)
buf.append("\n" + indent(level * 2));
jsonEncode_breakAtNLevels(level + 1, levels, element, buf);
}
if (level <= levels)
buf.append("\n" + indent((level - 1) * 2));
buf.append("]");
} else
throw fail("Unknown object for JSON encoding: " + className(o));
}
static public boolean fileExists(String path) {
return path != null && new File(path).exists();
}
static public boolean fileExists(File f) {
return f != null && f.exists();
}
static public A pairA(Pair p) {
return p == null ? null : p.a;
}
static public List diff(Collection a, Collection b) {
Set set = asSet(b);
List l = new ArrayList();
for (String s : a) if (!set.contains(s))
l.add(s);
return l;
}
static public String or2(String a, String b) {
return nempty(a) ? a : b;
}
static public String or2(String a, String b, String c) {
return or2(or2(a, b), c);
}
static public List mapToLines(Map map) {
List l = new ArrayList();
for (Object key : keys(map)) l.add(str(key) + " = " + str(map.get(key)));
return l;
}
static public String mapToLines(Map map, Object f) {
return lines(map(map, f));
}
static public String mapToLines(Object f, Map map) {
return lines(map(map, f));
}
static public String mapToLines(Object f, Iterable l) {
return lines(map(f, l));
}
static public String mapToLines(Iterable l, IF1 f) {
return mapToLines((Object) f, l);
}
static public String mapToLines(IF1 f, Iterable l) {
return mapToLines((Object) f, l);
}
static public String mapToLines(Map map, IF2 f) {
return lines(map(map, f));
}
static public String mapToLines(IF1 f, A data1, A... moreData) {
return lines(map(f, data1, moreData));
}
static public String dm_moduleStruct(Object module) {
return dm_getStructure(module);
}
static public String dm_moduleStruct() {
return dm_moduleStruct(dm_current_generic());
}
static public File conceptsFile(String progID) {
return getProgramFile(progID, conceptsFileName());
}
static public File conceptsFile() {
return conceptsFile(dbProgramID());
}
static public String discordBotInviteLink(long clientID, long permissions) {
return "https://discordapp.com/oauth2/authorize?client_id=" + clientID + "&permissions=" + permissions + "&scope=bot";
}
static public long discord_adminPermission() {
return 8;
}
static public A printStackTrace(A e) {
if (e != null)
print(getStackTrace(e));
return e;
}
static public void printStackTrace() {
printStackTrace(new Throwable());
}
static public void printStackTrace(String msg) {
printStackTrace(new Throwable(msg));
}
static public void printStackTrace(String msg, Throwable e) {
printStackTrace(new Throwable(msg, e));
}
static public String webBot_answer(String s, String botID) {
String answer = loadPageWithParams("https://botcompany.de/" + psI(botID) + "/raw/answer/rand=" + randomID(), "q", s, "noDefault", 1);
print(botID + ": " + answer);
return eq(answer, "ERROR.") ? null : answer;
}
static public boolean isB(Either e) {
return eitherIsB(e);
}
static public A eitherGetA(Either e) {
return eitherAOpt(e);
}
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 Set> _entrySet(Map map) {
return map == null ? Collections.EMPTY_SET : map.entrySet();
}
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 int[] unnull(int[] l) {
return l == null ? emptyIntArray() : l;
}
static public char[] unnull(char[] l) {
return l == null ? emptyCharArray() : l;
}
static public double[] unnull(double[] l) {
return l == null ? emptyDoubleArray() : 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[]) emptyObjectArray() : 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 Symbol unnull(Symbol s) {
return s == null ? emptySymbol() : s;
}
static public Pair unnull(Pair p) {
return p != null ? p : new Pair(null, null);
}
static public int unnull(Integer i) {
return i == null ? 0 : i;
}
static public long unnull(Long l) {
return l == null ? 0L : l;
}
static public double unnull(Double l) {
return l == null ? 0.0 : l;
}
static public Collection values(Map map) {
return map == null ? emptyList() : map.values();
}
static public Collection values(Object map) {
return values((Map) map);
}
static public Collection values(MultiMap mm) {
return mm == null ? emptyList() : concatLists(values(mm.data));
}
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 discordAt(long userID) {
return userID == 0 ? "unknown person" : "<@" + userID + ">";
}
static public List filter(Iterable c, Object pred) {
if (pred instanceof F1)
return filter(c, (F1 ) pred);
List x = new ArrayList();
if (c != null)
for (Object o : c) if (isTrue(callF(pred, o)))
x.add(o);
return x;
}
static public List filter(Object pred, Iterable c) {
return filter(c, pred);
}
static public List filter(Iterable c, F1 pred) {
List x = new ArrayList();
if (c != null)
for (B o : c) if (pred.get(o))
x.add(o);
return x;
}
static public List filter(F1 pred, Iterable c) {
return filter(c, pred);
}
static public List filter(Iterable c, IF1 pred) {
List x = new ArrayList();
if (c != null)
for (B o : c) if (pred.get(o))
x.add(o);
return x;
}
static public List filter(B[] c, IF1 pred) {
List x = new ArrayList();
if (c != null)
for (B o : c) if (pred.get(o))
x.add(o);
return x;
}
static public List filter(IF1 pred, Iterable c) {
return filter(c, pred);
}
static public File prepareCacheProgramFile(String name) {
return mkdirsForFile(getCacheProgramFile(name));
}
static public File prepareCacheProgramFile(String progID, String name) {
return mkdirsForFile(getCacheProgramFile(progID, name));
}
static public LinkedHashMap litorderedmap(Object... x) {
LinkedHashMap map = new LinkedHashMap();
litmap_impl(map, x);
return map;
}
static public Boolean trueOrNull(Boolean b) {
return eq(b, false) ? null : b;
}
static public String dateWithSecondsGMT(long time) {
SimpleDateFormat format = simpleDateFormat_GMT("yyyy/MM/dd");
return format.format(time) + " " + formatGMTWithSeconds_24(time);
}
static public String dateWithSecondsGMT() {
return dateWithSecondsGMT(now());
}
static public String f2s(File f) {
return f == null ? null : f.getAbsolutePath();
}
static public String f2s(String s) {
return f2s(newFile(s));
}
static public String f2s(java.nio.file.Path p) {
return p == null ? null : f2s(p.toFile());
}
static public Object decodeJson(String text) {
return jsonDecode(text);
}
static public String loadTextFile(String fileName) {
return loadTextFile(fileName, null);
}
static public String loadTextFile(File f, String defaultContents) {
return loadTextFile(f, defaultContents, "UTF-8");
}
static public String loadTextFile(File f, String defaultContents, String encoding) {
try {
checkFileNotTooBigToRead(f);
if (f == null || !f.exists())
return defaultContents;
FileInputStream fileInputStream = new FileInputStream(f);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, encoding);
return loadTextFile(inputStreamReader);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static String loadTextFile(File fileName) {
return loadTextFile(fileName, null);
}
static public String loadTextFile(String fileName, String defaultContents) {
return fileName == null ? defaultContents : loadTextFile(newFile(fileName), defaultContents);
}
static public String loadTextFile(Reader reader) throws IOException {
StringBuilder builder = new StringBuilder();
try {
char[] buffer = new char[1024];
int n;
while (-1 != (n = reader.read(buffer))) builder.append(buffer, 0, n);
} finally {
reader.close();
}
return str(builder);
}
static public File copyFile(File src, File dest) {
try {
FileInputStream inputStream = new FileInputStream(src.getPath());
FileOutputStream outputStream = newFileOutputStream(dest.getPath());
try {
copyStream(inputStream, outputStream);
inputStream.close();
} finally {
outputStream.close();
}
return dest;
} catch (Exception __e) {
throw rethrow(__e);
}
}
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;
if (l instanceof List)
return (A) last((List) l);
if (l instanceof SortedSet)
return (A) last((SortedSet) l);
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 Pair pair(A a, B b) {
return new Pair(a, b);
}
static public Pair pair(A a) {
return new Pair(a, a);
}
static public String nicelyFormatJsonDiff(Object diff) {
StringBuilderWithIndent buf = new StringBuilderWithIndent();
nicelyFormatJsonDiff(diff, buf);
return str(buf);
}
static public void nicelyFormatJsonDiff(Object diff, StringBuilderWithIndent buf) {
if (diff == null) {
buf.println("No differences");
return;
}
if (diff instanceof JsonDiff.Removed) {
buf.println("DELETE " + ((JsonDiff.Removed) diff).a);
return;
}
if (diff instanceof JsonDiff.Added) {
buf.println("ADD " + ((JsonDiff.Added) diff).b);
return;
}
if (diff instanceof JsonDiff.Different) {
buf.println(((JsonDiff.Different) diff).a + " -> " + ((JsonDiff.Different) diff).b);
return;
}
if (diff instanceof Map) {
for (Map.Entry extends Object, ? extends Object> __0 : _entrySet((Map) diff)) {
Object key = __0.getKey();
Object value = __0.getValue();
if (!(value instanceof JsonDiff.Different) || !(key instanceof JsonDiff.GatheredKey))
if (key instanceof JsonDiff.GatheredKey) {
buf.println(((JsonDiff.GatheredKey) key).key + "=" + ((JsonDiff.GatheredKey) key).value);
} else
buf.println(key);
AutoCloseable __2 = buf.indent();
try {
nicelyFormatJsonDiff(value, buf);
} finally {
_close(__2);
}
}
return;
}
buf.println(sfu(diff));
}
static public void changeKey(Map map, Object oldKey, Object newKey) {
if (map == null || eq(oldKey, newKey) || !map.containsKey(oldKey))
return;
map.put(newKey, map.get(oldKey));
map.remove(oldKey);
}
static public boolean isMap(Object o) {
return o instanceof Map;
}
static public boolean containsOneKeyOf(Map map, A... keys) {
for (A key : unnullForIteration(keys)) if (containsKey(map, key))
return true;
return false;
}
static public Either eitherA(A a) {
return new Either(1, a);
}
static public Either eitherB(B b) {
return new Either(2, b);
}
static public String hexToUTF8(String hex) {
return fromUtf8(hexToBytes(hex));
}
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 AutoCloseable tempInterceptPrintIfNotIntercepted(F1 f) {
return print_byThread().get() == null ? tempInterceptPrint(f) : null;
}
static public Object _defaultClassFinder_value = defaultDefaultClassFinder();
static public Object _defaultClassFinder() {
return _defaultClassFinder_value;
}
static public Concepts newConceptsWithClassFinder(String progID) {
Concepts cc = new Concepts(progID);
cc.classFinder = _defaultClassFinder();
return cc;
}
static public String getDBProgramID_id;
static public String getDBProgramID() {
return nempty(getDBProgramID_id) ? getDBProgramID_id : programIDWithCase();
}
static public String dropNumberPrefix(String s) {
return dropFirst(s, indexOfNonDigit(s));
}
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 String str(Object o) {
return o == null ? "null" : o.toString();
}
static public String str(char[] c) {
return new String(c);
}
static public Object nuObject(String className, Object... args) {
try {
return nuObject(classForName(className), args);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public A nuObject(Class c, Object... args) {
try {
if (args.length == 0)
return nuObjectWithoutArguments(c);
Constructor m = nuObject_findConstructor(c, args);
makeAccessible(m);
return (A) m.newInstance(args);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Constructor nuObject_findConstructor(Class c, Object... args) {
for (Constructor m : c.getDeclaredConstructors()) {
if (!nuObject_checkArgs(m.getParameterTypes(), args, false))
continue;
return m;
}
throw fail("Constructor " + c.getName() + getClasses(args) + " not found" + (args.length == 0 && (c.getModifiers() & java.lang.reflect.Modifier.STATIC) == 0 ? " - hint: it's a non-static class!" : ""));
}
static public boolean nuObject_checkArgs(Class[] types, Object[] args, boolean debug) {
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;
}
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 Object getOptMC(String field) {
return getOpt(mc(), field);
}
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, final VF3 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 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 C callF(F2 f, A a, B b) {
return f == null ? null : f.get(a, b);
}
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 combinePrintParameters(String s, Object o) {
return (endsWithLetterOrDigit(s) ? s + ": " : s) + o;
}
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 getStackTrace(Throwable throwable) {
lastException(throwable);
return getStackTrace_noRecord(throwable);
}
static public String getStackTrace_noRecord(Throwable throwable) {
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
return hideCredentials(writer.toString());
}
static public String getStackTrace() {
return getStackTrace_noRecord(new Throwable());
}
static public String getStackTrace(String msg) {
return getStackTrace_noRecord(new Throwable(msg));
}
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 void vmBus_send(String msg, Object... args) {
Object arg = vmBus_wrapArgs(args);
pcallFAll_minimalExceptionHandling(vm_busListeners_live(), msg, arg);
pcallFAll_minimalExceptionHandling(vm_busListenersByMessage_live().get(msg), msg, arg);
}
static public void vmBus_send(String msg) {
vmBus_send(msg, (Object) null);
}
static public Class mc() {
return main.class;
}
static public long toLong(Object o) {
if (o instanceof Number)
return ((Number) o).longValue();
if (o instanceof String)
return parseLong((String) o);
return 0;
}
static public Map synchroHashMap() {
return synchronizedMap(new HashMap());
}
static public RuntimeException fail() {
throw new RuntimeException("fail");
}
static public RuntimeException fail(Throwable e) {
throw asRuntimeException(e);
}
static public RuntimeException fail(Object msg) {
throw new RuntimeException(String.valueOf(msg));
}
static public RuntimeException fail(Object... objects) {
throw new Fail(objects);
}
static public RuntimeException fail(String msg) {
throw new RuntimeException(msg == null ? "" : msg);
}
static public RuntimeException fail(String msg, Throwable innerException) {
throw new RuntimeException(msg, innerException);
}
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 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 String structureForUser(Object o) {
return beautifyStructure(struct_noStringSharing(o));
}
static public List dropPunctuation3_keep = ll("*", "<", ">");
static public Map dropPunctuation3_cache = defaultSizeMRUCache();
static public List dropPunctuation3(List tok) {
tok = new ArrayList(tok);
for (int i = 1; i < tok.size(); i += 2) {
String t = tok.get(i);
if (t.length() == 1 && !Character.isLetter(t.charAt(0)) && !Character.isDigit(t.charAt(0)) && !dropPunctuation3_keep.contains(t)) {
tok.set(i - 1, or2(tok.get(i - 1) + tok.get(i + 1), " "));
tok.remove(i);
tok.remove(i);
i -= 2;
}
}
return tok;
}
static public String dropPunctuation3(String s) {
return getOrCreate_f0(dropPunctuation3_cache, s, () -> join(dropPunctuation3(javaTokNoQuotes(s))));
}
static public boolean agiBlue_validPageName(String s) {
s = trim(s);
return nempty(s) && !containsNewLine(s);
}
static public String agiBlue_lookupInSlice_pcall(String sliceID, String q, String... keys) {
try {
return agiBlue_lookupInSlice(sliceID, q, keys);
} catch (Throwable __e) {
return null;
}
}
static public String agiBlue_postInSlice_pcall(String slice, String a, String b, String c) {
try {
return agiBlue_postInSlice(slice, a, b, c);
} catch (Throwable __e) {
return null;
}
}
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() {
newPing();
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 Thread currentThread() {
return Thread.currentThread();
}
static public Map vm_threadInterruptionReasonsMap() {
return vm_generalWeakSubMap("Thread interruption reasons");
}
static public String strOr(Object o, String ifNull) {
return o == null ? ifNull : str(o);
}
static public void lockOrFail(Lock lock, long timeout) {
try {
ping();
vmBus_send("locking", lock, "thread", currentThread());
if (!lock.tryLock(timeout, TimeUnit.MILLISECONDS)) {
String s = "Couldn't acquire lock after " + timeout + " ms.";
if (lock instanceof ReentrantLock) {
ReentrantLock l = (ReentrantLock) lock;
s += " Hold count: " + l.getHoldCount() + ", owner: " + call(l, "getOwner");
}
throw fail(s);
}
vmBus_send("locked", lock, "thread", currentThread());
ping();
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public ReentrantLock fairLock() {
return new ReentrantLock(true);
}
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 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 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;
int n = s.length();
if (y < x)
y = x;
if (y > n)
y = n;
if (x >= y)
return "";
return s.substring(x, y);
}
static public String substring(String s, CharSequence l) {
return substring(s, lCharSequence(l));
}
static public long parseLong(String s) {
if (empty(s))
return 0;
return Long.parseLong(dropSuffix("L", s));
}
static public long parseLong(Object s) {
return Long.parseLong((String) s);
}
static public String jextract(String pat, String s) {
return jextract(pat, javaTok(s));
}
static public String jextract(String pat, List tok) {
List tokpat = javaTok(pat);
jfind_preprocess(tokpat);
int i = jfind(tok, tokpat);
if (i < 0)
return null;
int j = i + l(tokpat) - 2;
return joinSubList(tok, i, j);
}
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 String asString(Object o) {
return o == null ? null : o.toString();
}
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));
}
public static String join(String glue, Object... 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 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 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(long[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (long 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(short[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (short i : a) l.add(i);
return l;
}
static public ArrayList asList(Iterator it) {
ArrayList l = new ArrayList();
if (it != null)
while (it.hasNext()) l.add(it.next());
return l;
}
static public ArrayList asList(IterableIterator s) {
return asList((Iterator) s);
}
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 List asList(Pair p) {
return p == null ? null : ll(p.a, p.b);
}
static public String fromLines(Iterable lines) {
StringBuilder buf = new StringBuilder();
if (lines != null)
for (Object line : lines) buf.append(str(line)).append('\n');
return buf.toString();
}
static public String fromLines(String... lines) {
return fromLines(asList(lines));
}
static public IterableIterator toLines(File f) {
return linesFromFile(f);
}
static public List toLines(String s) {
List lines = new ArrayList();
if (s == null)
return lines;
int start = 0;
while (true) {
int i = toLines_nextLineBreak(s, start);
if (i < 0) {
if (s.length() > start)
lines.add(s.substring(start));
break;
}
lines.add(s.substring(start, i));
if (s.charAt(i) == '\r' && i + 1 < s.length() && s.charAt(i + 1) == '\n')
i += 2;
else
++i;
start = i;
}
return lines;
}
static public int toLines_nextLineBreak(String s, int start) {
int n = s.length();
for (int i = start; i < n; i++) {
char c = s.charAt(i);
if (c == '\r' || c == '\n')
return i;
}
return -1;
}
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 ClassLoader classLoaderForObject(Object o) {
if (o instanceof ClassLoader)
return ((ClassLoader) o);
if (o == null)
return null;
return _getClass(o).getClassLoader();
}
static public String classNameToVM(String name) {
return name.replace(".", "$");
}
static public boolean endsWithLetter(String s) {
return nempty(s) && isLetter(last(s));
}
static public boolean regexpFind(String pat, String s) {
return regexpFinds(pat, s);
}
static public String discordTokenRegexp() {
return "[MN][A-Za-z\\d]{23}\\.[\\w-]{6}\\.[\\w-]{27}";
}
static public SelfUser jda_selfUser(JDA jda) {
return jda.getSelfUser();
}
static public String ymd() {
return ymd(now());
}
static public String ymd(long now) {
return year(now) + formatInt(month(now), 2) + formatInt(dayOfMonth(now), 2);
}
static public String ymd(long now, TimeZone tz) {
return year(now, tz) + formatInt(month(now, tz), 2) + formatInt(dayOfMonth(now, tz), 2);
}
static public String hms() {
return hms(now());
}
static public String hms(long time) {
return new SimpleDateFormat("HHmmss").format(time);
}
static public File prepareProgramFile(String name) {
return mkdirsForFile(getProgramFile(name));
}
static public File prepareProgramFile(String progID, String name) {
return mkdirsForFile(getProgramFile(progID, name));
}
static public ZipOutputStream newZipOutputStream(String path) {
return newZipOutputStream(new File(path));
}
static public ZipOutputStream newZipOutputStream(File zip) {
try {
return new ZipOutputStream(newFileOutputStream(zip));
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public void zip_addTextFile(ZipOutputStream outZip, String name, String text) {
try {
if (text == null)
return;
outZip.putNextEntry(new ZipEntry(name));
byte[] utf8 = toUtf8(text);
outZip.write(utf8, 0, l(utf8));
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public FixedRateTimer doEveryStartingNow(int delay, Object r) {
return doEvery(delay, 0, r);
}
static public int toInt(Object o) {
if (o == null)
return 0;
if (o instanceof Number)
return ((Number) o).intValue();
if (o instanceof String)
return parseInt((String) o);
if (o instanceof Boolean)
return boolToInt((Boolean) o);
throw fail("woot not int: " + getClassName(o));
}
static public int toInt(long l) {
if (l != (int) l)
throw fail("Too large for int: " + l);
return (int) l;
}
static public long toMS(double seconds) {
return (long) (seconds * 1000);
}
static public Object gazelle_discordPresence() {
return call(gazelle_jda(), "getPresence");
}
static public Class getClass_vmName(Object realm, String name) {
try {
try {
return getClass(realm).getClassLoader().loadClass(name);
} catch (ClassNotFoundException e) {
return null;
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Object gazelle_jda() {
return getFirstNonNullField(dm_current_mandatory_generic(), "discord", "bot");
}
static public Pair mapEntryToPair(Map.Entry e) {
return e == null ? null : pair(e.getKey(), e.getValue());
}
static public Set> entrySet(Map map) {
return _entrySet(map);
}
static public A firstThat(Iterable l, IF1 pred) {
for (A a : unnullForIteration(l)) if (pred.get(a))
return a;
return null;
}
static public A firstThat(A[] l, IF1 pred) {
for (A a : unnullForIteration(l)) if (pred.get(a))
return a;
return null;
}
static public A firstThat(IF1 pred, Iterable l) {
return firstThat(l, pred);
}
static public A firstThat(IF1 pred, A[] l) {
return firstThat(l, pred);
}
static public File fileAppendToName(File f, String suffix) {
return newFile(f.getPath() + suffix);
}
static public java.awt.Color awtColor(String hex) {
byte[] b = bytesFromHex(dropPrefix("#", hex));
return new Color(ubyteToInt(b[0]), ubyteToInt(b[1]), ubyteToInt(b[2]));
}
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 List subList(List l, int startIndex) {
return subList(l, startIndex, l(l));
}
static public List subList(int startIndex, List l) {
return subList(l, startIndex);
}
static public List subList(int startIndex, int endIndex, List l) {
return subList(l, startIndex, endIndex);
}
static public List subList(List l, int startIndex, int endIndex) {
if (l == null)
return null;
int n = l(l);
startIndex = Math.max(0, startIndex);
endIndex = Math.min(n, endIndex);
if (startIndex > endIndex)
return ll();
if (startIndex == 0 && endIndex == n)
return l;
return l.subList(startIndex, endIndex);
}
static public String appendNumberUnless1(String s, int i) {
return i == 1 ? s : s + " " + i;
}
static public boolean emptyAfterTrim(String s) {
return empty(trim(s));
}
static public String snippetImageURL_noHttps(String snippetID) {
return snippetImageURL_noHttps(snippetID, "png");
}
static public String snippetImageURL_noHttps(String snippetID, String contentType) {
return snippetImageURL(snippetID, contentType).replace("https://www.botcompany.de:8443/", "http://www.botcompany.de:8080/").replace("https://botcompany.de/", "http://botcompany.de/");
}
static public Charset utf8charset_cache;
static public Charset utf8charset() {
if (utf8charset_cache == null)
utf8charset_cache = utf8charset_load();
return utf8charset_cache;
}
static public Charset utf8charset_load() {
return Charset.forName("UTF-8");
}
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 Set keys(MultiMap mm) {
return mm.keySet();
}
static public int indent_default = 2;
static public String indent(int indent) {
return repeat(' ', indent);
}
static public String indent(int indent, String s) {
return indent(repeat(' ', indent), s);
}
static public String indent(String indent, String s) {
return indent + s.replace("\n", "\n" + indent);
}
static public String indent(String s) {
return indent(indent_default, s);
}
static public List indent(String indent, List lines) {
List l = new ArrayList();
if (lines != null)
for (String s : lines) l.add(indent + s);
return l;
}
static public String className(Object o) {
return getClassName(o);
}
static public Set asSet(Object[] array) {
HashSet set = new HashSet();
for (Object o : array) if (o != null)
set.add(o);
return set;
}
static public Set asSet(String[] array) {
TreeSet set = new TreeSet();
for (String o : array) if (o != null)
set.add(o);
return set;
}
static public Set asSet(Iterable l) {
if (l instanceof Set)
return (Set) l;
HashSet set = new HashSet();
for (A o : unnull(l)) if (o != null)
set.add(o);
return set;
}
static public Set asSet(MultiSet ms) {
return ms == null ? null : ms.asSet();
}
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(BitSet bs) {
return !empty(bs);
}
static public boolean nempty(Map m) {
return !empty(m);
}
static public boolean nempty(Iterator i) {
return i != null && i.hasNext();
}
static public boolean nempty(MultiMap mm) {
return mm != null && !mm.isEmpty();
}
static public boolean nempty(Object o) {
return !empty(o);
}
static public boolean nempty(Rect r) {
return r != null && r.w != 0 && r.h != 0;
}
static public String dm_getStructure(Object module) {
return (String) get(dm_getStem(module), "oStruct");
}
static public File getProgramFile(String progID, String fileName) {
if (new File(fileName).isAbsolute())
return new File(fileName);
return new File(getProgramDir(progID), fileName);
}
static public File getProgramFile(String fileName) {
return getProgramFile(getProgramID(), fileName);
}
static public String conceptsFileName() {
return "concepts.structure.gz";
}
static public String dbProgramID() {
return getDBProgramID();
}
static public String loadPageWithParams(String url, Object... params) {
return loadPage(appendQueryToURL(url, params));
}
static public String loadPageWithParams(String url, Map params) {
return loadPage(appendQueryToURL(url, params));
}
static public long psI(String snippetID) {
return parseSnippetID(snippetID);
}
static public int randomID_defaultLength = 12;
static public String randomID(int length) {
return makeRandomID(length);
}
static public String randomID(Random r, int length) {
return makeRandomID(r, length);
}
static public String randomID() {
return randomID(randomID_defaultLength);
}
static public String randomID(Random r) {
return randomID(r, randomID_defaultLength);
}
static public boolean eitherIsB(Either e) {
return e != null && e.isB();
}
static public A eitherAOpt(Either e) {
return e != null && e.isA() ? e.a() : null;
}
static public int[] emptyIntArray_a = new int[0];
static public int[] emptyIntArray() {
return emptyIntArray_a;
}
static public char[] emptyCharArray = new char[0];
static public char[] emptyCharArray() {
return emptyCharArray;
}
static public double[] emptyDoubleArray = new double[0];
static public double[] emptyDoubleArray() {
return emptyDoubleArray;
}
static public Map emptyMap() {
return new HashMap();
}
static public Object[] emptyObjectArray_a = new Object[0];
static public Object[] emptyObjectArray() {
return emptyObjectArray_a;
}
static public Symbol emptySymbol_value;
static public Symbol emptySymbol() {
if (emptySymbol_value == null)
emptySymbol_value = symbol("");
return emptySymbol_value;
}
static public List concatLists(Iterable ... lists) {
List l = new ArrayList();
if (lists != null)
for (Iterable list : lists) addAll(l, list);
return l;
}
static public List concatLists(Collection extends Iterable > lists) {
List l = new ArrayList();
if (lists != null)
for (Iterable list : lists) addAll(l, list);
return l;
}
static public String getClassName(Object o) {
return o == null ? "null" : o instanceof Class ? ((Class) o).getName() : o.getClass().getName();
}
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;
}
static public File getCacheProgramFile(String progID, String fileName) {
if (new File(fileName).isAbsolute())
return new File(fileName);
return new File(getCacheProgramDir(progID), fileName);
}
static public File getCacheProgramFile(String fileName) {
return getCacheProgramFile(getProgramID(), fileName);
}
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 SimpleDateFormat simpleDateFormat_GMT(String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
return sdf;
}
static public String formatGMTWithSeconds_24(long time) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
return sdf.format(time) + " GMT";
}
static public File newFile(File base, String... names) {
for (String name : names) base = new File(base, name);
return base;
}
static public File newFile(String name) {
return name == null ? null : new File(name);
}
static public File newFile(String base, String... names) {
return newFile(newFile(base), names);
}
static public Object jsonDecode(String text) {
return new jsonDecode_Y(text).parse();
}
static public class jsonDecode_Y {
public String text;
public List tok;
public boolean useOrderedMaps = false;
public int i = 1;
public jsonDecode_Y(String text) {
this.text = text;
tok = jsonTok(text);
}
transient public IF1 fail;
public RuntimeException fail(String msg) {
return fail != null ? fail.get(msg) : fail_base(msg);
}
final public RuntimeException fail_fallback(IF1 _f, String msg) {
return _f != null ? _f.get(msg) : fail_base(msg);
}
public RuntimeException fail_base(String msg) {
return main.fail(msg);
}
public Object parse() {
if (l(tok) == 1)
return null;
return parseExpr();
}
public Object parseExpr() {
String t = tok.get(i);
if (t.startsWith("\"") || t.startsWith("'")) {
String s = unquote(tok.get(i));
i += 2;
return s;
}
if (t.equals("{"))
return parseMap();
if (t.equals("["))
return this.parseList();
if (t.equals("null")) {
i += 2;
return null;
}
if (t.equals("false")) {
i += 2;
return false;
}
if (t.equals("true")) {
i += 2;
return true;
}
boolean minus = false;
if (t.equals("-")) {
minus = true;
i += 2;
t = get(tok, i);
}
if (isInteger(t)) {
int j = i;
i += 2;
if (eqOneOf(get(tok, i), ".", "e", "E")) {
while (isInteger(get(tok, i)) || eqOneOf(get(tok, i), ".", "e", "E", "-")) i += 2;
double d = parseDouble(joinSubList(tok, j, i - 1));
if (minus)
d = -d;
return d;
} else {
long l = parseLong(t);
return boxedIntOrLong(minus ? -l : l);
}
}
throw fail("Unknown token " + (i + 1) + ": " + t + ": " + text);
}
public Object parseList() {
consume("[");
List list = new ArrayList();
while (!tok.get(i).equals("]")) {
list.add(parseExpr());
if (tok.get(i).equals(","))
i += 2;
}
consume("]");
return list;
}
public Object parseMap() {
consume("{");
Map map = useOrderedMaps ? new LinkedHashMap() : new TreeMap();
while (!tok.get(i).equals("}")) {
String key = unquote(tok.get(i));
i += 2;
consume(":");
Object value = parseExpr();
map.put(key, value);
if (tok.get(i).equals(","))
i += 2;
}
consume("}");
return map;
}
public void consume(String s) {
if (!tok.get(i).equals(s)) {
String prevToken = i - 2 >= 0 ? tok.get(i - 2) : "";
String nextTokens = join(tok.subList(i, Math.min(i + 4, tok.size())));
throw fail(quote(s) + " expected: " + prevToken + " " + nextTokens + " (" + i + "/" + tok.size() + ")");
}
i += 2;
}
}
static public ThreadLocal> checkFileNotTooBigToRead_tl = new ThreadLocal();
static public void checkFileNotTooBigToRead(File f) {
callF(checkFileNotTooBigToRead_tl.get(), f);
}
static public FileOutputStream newFileOutputStream(File path) throws IOException {
return newFileOutputStream(path.getPath());
}
static public FileOutputStream newFileOutputStream(String path) throws IOException {
return newFileOutputStream(path, false);
}
static public FileOutputStream newFileOutputStream(File path, boolean append) throws IOException {
return newFileOutputStream(path.getPath(), append);
}
static public FileOutputStream newFileOutputStream(String path, boolean append) throws IOException {
mkdirsForFile(path);
FileOutputStream f = new FileOutputStream(path, append);
_registerIO(f, path, true);
return f;
}
static public void copyStream(InputStream in, OutputStream out) {
try {
byte[] buf = new byte[65536];
while (true) {
int n = in.read(buf);
if (n <= 0)
return;
out.write(buf, 0, n);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Iterator iterator(Iterable c) {
return c == null ? emptyIterator() : c.iterator();
}
static public String unnullForIteration(String s) {
return s == null ? "" : s;
}
static public Collection unnullForIteration(Collection l) {
return l == null ? immutableEmptyList() : l;
}
static public List unnullForIteration(List l) {
return l == null ? immutableEmptyList() : l;
}
static public int[] unnullForIteration(int[] l) {
return l == null ? emptyIntArray() : l;
}
static public char[] unnullForIteration(char[] l) {
return l == null ? emptyCharArray() : l;
}
static public double[] unnullForIteration(double[] l) {
return l == null ? emptyDoubleArray() : l;
}
static public short[] unnullForIteration(short[] l) {
return l == null ? emptyShortArray() : l;
}
static public Map unnullForIteration(Map l) {
return l == null ? immutableEmptyMap() : l;
}
static public Iterable unnullForIteration(Iterable i) {
return i == null ? immutableEmptyList() : i;
}
static public A[] unnullForIteration(A[] a) {
return a == null ? (A[]) emptyObjectArray() : a;
}
static public BitSet unnullForIteration(BitSet b) {
return b == null ? new BitSet() : b;
}
static public Pt unnullForIteration(Pt p) {
return p == null ? new Pt() : p;
}
static public Symbol unnullForIteration(Symbol s) {
return s == null ? emptySymbol() : s;
}
static public Pair unnullForIteration(Pair p) {
return p != null ? p : new Pair(null, null);
}
static public long unnullForIteration(Long l) {
return l == null ? 0L : l;
}
static public boolean containsKey(Map map, A key) {
return map != null && map.containsKey(key);
}
static public String fromUtf8(byte[] bytes) {
try {
return bytes == null ? null : new String(bytes, utf8charset());
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public byte[] hexToBytes(String s) {
if (odd(l(s)))
throw fail("Hex string has odd length: " + quote(shorten(10, s)));
int n = l(s) / 2;
byte[] bytes = new byte[n];
for (int i = 0; i < n; i++) {
int a = parseHexChar(s.charAt(i * 2));
int b = parseHexChar(s.charAt(i * 2 + 1));
if (a < 0 || b < 0)
throw fail("Bad hex byte: " + quote(substring(s, i * 2, i * 2 + 2)) + " at " + i * 2 + "/" + l(s));
bytes[i] = (byte) ((a << 4) | b);
}
return bytes;
}
static public Class __javax;
static public Class getJavaX() {
try {
return __javax;
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public void __setJavaX(Class j) {
__javax = j;
_onJavaXSet();
}
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 Object defaultDefaultClassFinder() {
return new F1() {
public Class get(String name) {
Class c = get2(name);
return c;
}
public Class get2(String name) {
if (eq(name, ""))
return mc();
{
Class c = findClass_fullName(name);
if (c != null)
return c;
}
if (startsWithAny(name, "loadableUtils.utils$", "main$", mcDollar()))
for (String pkg : ll("loadableUtils.utils$", mcDollar())) {
String newName = pkg + afterDollar(name);
{
Class c = findClass_fullName(newName);
if (c != null)
return c;
}
}
return null;
}
};
}
static public String programIDWithCase() {
return nempty(caseID()) ? programID() + "/" + quoteUnlessIdentifierOrInteger(caseID()) : programID();
}
static public String[] dropFirst(int n, String[] a) {
return drop(n, a);
}
static public String[] dropFirst(String[] a) {
return drop(1, a);
}
static public Object[] dropFirst(Object[] a) {
return drop(1, a);
}
static public List dropFirst(List l) {
return dropFirst(1, l);
}
static public List dropFirst(int n, Iterable i) {
return dropFirst(n, toList(i));
}
static public List dropFirst(Iterable i) {
return dropFirst(toList(i));
}
static public List dropFirst(int n, List l) {
return n <= 0 ? l : new ArrayList(l.subList(Math.min(n, l.size()), l.size()));
}
static public List dropFirst(List l, int n) {
return dropFirst(n, l);
}
static public String dropFirst(int n, String s) {
return substring(s, n);
}
static public String dropFirst(String s, int n) {
return substring(s, n);
}
static public String dropFirst(String s) {
return substring(s, 1);
}
static public int indexOfNonDigit(String s) {
int n = l(s);
for (int i = 0; i < n; i++) if (!isDigit(s.charAt(i)))
return i;
return -1;
}
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 Map classForName_cache = synchroHashMap();
static public Class classForName(String name) {
return classForName(name, null);
}
static public Class classForName(String name, Object classFinder) {
if (classForName_cache == null || classFinder != null)
return classForName_uncached(name, classFinder);
Class c = classForName_cache.get(name);
if (c == null)
classForName_cache.put(name, c = classForName_uncached(name, null));
return c;
}
static public Class classForName_uncached(String name, Object classFinder) {
try {
if (classFinder != null)
return (Class) callF(classFinder, name);
return Class.forName(name);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Map nuObjectWithoutArguments_cache = newDangerousWeakHashMap();
static public Object nuObjectWithoutArguments(String className) {
try {
return nuObjectWithoutArguments(classForName(className));
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public A nuObjectWithoutArguments(Class c) {
try {
if (nuObjectWithoutArguments_cache == null)
return (A) nuObjectWithoutArguments_findConstructor(c).newInstance();
Constructor m = nuObjectWithoutArguments_cache.get(c);
if (m == null)
nuObjectWithoutArguments_cache.put(c, m = nuObjectWithoutArguments_findConstructor(c));
return (A) m.newInstance();
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Constructor nuObjectWithoutArguments_findConstructor(Class c) {
for (Constructor m : c.getDeclaredConstructors()) if (empty(m.getParameterTypes())) {
makeAccessible(m);
return m;
}
throw fail("No default constructor found in " + c.getName());
}
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 List getClasses(Object[] array) {
List l = emptyList(l(array));
for (Object o : array) l.add(_getClass(o));
return l;
}
static public boolean isInstanceX(Class type, Object arg) {
if (type == boolean.class)
return arg instanceof Boolean;
if (type == int.class)
return arg instanceof Integer;
if (type == long.class)
return arg instanceof Long;
if (type == float.class)
return arg instanceof Float;
if (type == short.class)
return arg instanceof Short;
if (type == char.class)
return arg instanceof Character;
if (type == byte.class)
return arg instanceof Byte;
if (type == double.class)
return arg instanceof Double;
return type.isInstance(arg);
}
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 set(BitSet bs, int idx) {
{
if (bs != null)
bs.set(idx);
}
}
static public void failIfOddCount(Object... list) {
if (odd(l(list)))
throw fail("Odd list size: " + list);
}
static public A dm_ownResource(A resource) {
dm_currentModuleMandatory().ownResource(resource);
return resource;
}
static public AutoCloseable vmBus_onMessage(String msg, IVF1 onMessage) {
return vmBus_onMessage(msg, ivf1ToVF1(onMessage));
}
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, final VF3 onMessage) {
return vmBus_onMessage(msg, new VF1() {
public void get(Object[] o) {
try {
callF(onMessage, first(o), second(o), third(o));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, first(o), second(o), third(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 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 volatile public PersistableThrowable lastException_lastException;
static public PersistableThrowable lastException() {
return lastException_lastException;
}
static public void lastException(Throwable e) {
lastException_lastException = persistableThrowable(e);
}
static public String hideCredentials(URL url) {
return url == null ? null : hideCredentials(str(url));
}
static public String hideCredentials(String url) {
try {
if (startsWithOneOf(url, "http://", "https://") && isAGIBlueDomain(hostNameFromURL(url)))
return url;
} catch (Throwable e) {
print("HideCredentials", e);
}
return url.replaceAll("([&?])(_pass|key|cookie)=[^&\\s\"]*", "$1$2=");
}
static public String hideCredentials(Object o) {
return hideCredentials(str(o));
}
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 Object vmBus_wrapArgs(Object... args) {
return empty(args) ? null : l(args) == 1 ? args[0] : args;
}
static public void pcallFAll_minimalExceptionHandling(Collection l, Object... args) {
if (l != null)
for (Object f : cloneList(l)) {
ping();
pcallF_minimalExceptionHandling(f, args);
}
}
static public void pcallFAll_minimalExceptionHandling(Iterator it, Object... args) {
while (it.hasNext()) {
ping();
pcallF_minimalExceptionHandling(it.next(), args);
}
}
static public Set vm_busListeners_live_cache;
static public Set vm_busListeners_live() {
if (vm_busListeners_live_cache == null)
vm_busListeners_live_cache = vm_busListeners_live_load();
return vm_busListeners_live_cache;
}
static public Set vm_busListeners_live_load() {
return vm_generalIdentityHashSet("busListeners");
}
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 Map synchronizedMap() {
return synchroMap();
}
static public Map synchronizedMap(Map map) {
return synchroMap(map);
}
static public RuntimeException asRuntimeException(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
return t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static public boolean startsWithIgnoreCase(String a, String b) {
return regionMatchesIC(a, 0, b, 0, b.length());
}
static public String beautifyStructure(String s) {
List tok = javaTokForStructure(s);
structure_addTokenMarkers(tok);
jreplace(tok, "lhm", "");
return join(tok);
}
static public String struct_noStringSharing(Object o) {
structure_Data d = new structure_Data();
d.noStringSharing = true;
return structure(o, d);
}
static public Map defaultSizeMRUCache() {
return mruCache(defaultStringTransformerCacheSize());
}
static public B getOrCreate_f0(Map map, A key, F0 create) {
B b = map.get(key);
if (b == null)
mapPut(map, key, b = callF(create));
return b;
}
static public B getOrCreate_f0(Map map, A key, IF0 create) {
B b = map.get(key);
if (b == null)
mapPut(map, key, b = callF(create));
return b;
}
static public List javaTokNoQuotes(String s) {
return quotelessJavaTok(s);
}
static public boolean containsNewLine(String s) {
return contains(s, '\n');
}
static public String agiBlue_lookupInSlice(String sliceID, String q, String... keys) {
return first((List) loadJSONPage(printHidingCredentials(agiBlue_linkForPhrase(q, paramsPlus(paramsWithSameKey("get", keys), "slice", sliceID)))));
}
static public ThreadLocal>> agiBlue_postInSlice_queue = new ThreadLocal();
static public String agiBlue_postInSlice(String slice, String a, String b, String c) {
List> queue = agiBlue_postInSlice_queue.get();
if (queue != null) {
queue.add(ll(slice, a, b, c));
return "Queued";
} else
return loadPage(agiBlueURL() + "/bot/post" + hquery("slice", slice, "q", a, "key", b, "value", c));
}
static public void newPing() {
var tl = newPing_actionTL();
Runnable action = tl == null ? null : tl.get();
{
if (action != null)
action.run();
}
}
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 String shortenSnippetID(String snippetID) {
if (snippetID.startsWith("#"))
snippetID = snippetID.substring(1);
String httpBlaBla = "http://tinybrain.de/";
if (snippetID.startsWith(httpBlaBla))
snippetID = snippetID.substring(httpBlaBla.length());
return "" + parseLong(snippetID);
}
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;
ClassLoader cl = (o instanceof Class ? (Class) o : o.getClass()).getClassLoader();
if (cl == null)
return null;
String name = mainClassNameForClassLoader(cl);
return loadClassFromClassLoader_orNull(cl, name);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public int strL(String s) {
return s == null ? 0 : s.length();
}
static public int lCharSequence(CharSequence s) {
return s == null ? 0 : s.length();
}
static public String dropSuffix(String suffix, String s) {
return nempty(suffix) && endsWith(s, suffix) ? s.substring(0, l(s) - l(suffix)) : s;
}
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;
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 && !regionMatches(s, j, "*/"));
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));
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 < l && !regionMatches(s, j, "]]"));
j = Math.min(j + 2, l);
} else if (c == '[' && d == '=' && i + 2 < l && s.charAt(i + 2) == '[') {
do ++j; while (j + 2 < l && !regionMatches(s, j, "]=]"));
j = Math.min(j + 3, l);
} else
++j;
tok.add(javaTok_substringC(s, i, j));
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 int jfind(String s, String in) {
return jfind(javaTok(s), in);
}
static public int jfind(List tok, String in) {
return jfind(tok, 1, in);
}
static public int jfind(List tok, int startIdx, String in) {
return jfind(tok, startIdx, in, null);
}
static public int jfind(List tok, String in, Object condition) {
return jfind(tok, 1, in, condition);
}
static public int jfind(List tok, String in, ITokCondition condition) {
return jfind(tok, 1, in, condition);
}
static public int jfind(List tok, int startIndex, String in, ITokCondition condition) {
return jfind(tok, startIndex, in, (Object) condition);
}
static public int jfind(List tok, int startIdx, String in, Object condition) {
return jfind(tok, startIdx, javaTokForJFind_array(in), condition);
}
static public int jfind(List tok, List tokin) {
return jfind(tok, 1, tokin);
}
static public int jfind(List tok, int startIdx, List tokin) {
return jfind(tok, startIdx, tokin, null);
}
static public int jfind(List tok, int startIdx, String[] tokinC, Object condition) {
return findCodeTokens(tok, startIdx, false, tokinC, condition);
}
static public int jfind(List tok, int startIdx, List tokin, Object condition) {
return jfind(tok, startIdx, codeTokensAsStringArray(tokin), condition);
}
static public List jfind_preprocess(List tok) {
for (String type : litlist("quoted", "id", "int")) replaceSublist(tok, ll("<", "", type, "", ">"), ll("<" + type + ">"));
replaceSublist(tok, ll("\\", "", "*"), ll("\\*"));
return tok;
}
static public String joinSubList(List l, int i, int j) {
return join(subList(l, i, j));
}
static public String joinSubList(List l, int i) {
return join(subList(l, i));
}
static public String formatWithThousandsSeparator(long l) {
return NumberFormat.getInstance(new Locale("en_US")).format(l);
}
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 CloseableIterableIterator linesFromFile(File f) {
return linesFromFile(f, null);
}
static public CloseableIterableIterator linesFromFile(File f, IResourceHolder resourceHolder) {
try {
if (!f.exists())
return emptyCloseableIterableIterator();
if (ewic(f.getName(), ".gz"))
return linesFromReader(utf8bufferedReader(newGZIPInputStream(f)), resourceHolder);
return linesFromReader(utf8bufferedReader(f), resourceHolder);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public CloseableIterableIterator linesFromFile(String path) {
return linesFromFile(path, null);
}
static public CloseableIterableIterator linesFromFile(String path, IResourceHolder resourceHolder) {
return linesFromFile(newFile(path), resourceHolder);
}
static public boolean even(int i) {
return (i & 1) == 0;
}
static public boolean even(long i) {
return (i & 1) == 0;
}
static public boolean even(BigInteger n) {
return even(n.intValue());
}
static public boolean isLetter(char c) {
return Character.isLetter(c);
}
static public boolean regexpFinds(String pat, String s) {
return regexp(pat, s).find();
}
static public boolean regexpFinds(Pattern pat, String s) {
return regexp(pat, s).find();
}
static public int year() {
return localYear();
}
static public int year(long now) {
return localYear(now);
}
static public int year(long now, TimeZone tz) {
return parseInt(simpleDateFormat("y", tz).format(now));
}
static public String formatInt(int i, int digits) {
return padLeft(str(i), '0', digits);
}
static public String formatInt(long l, int digits) {
return padLeft(str(l), '0', digits);
}
static public int month() {
return localMonth();
}
static public int month(long now) {
return localMonth(now);
}
static public int month(long now, TimeZone tz) {
return parseInt(simpleDateFormat("M", tz).format(now));
}
static public int dayOfMonth() {
return localDayOfMonth();
}
static public int dayOfMonth(long now) {
return localDayOfMonth(now);
}
static public int dayOfMonth(long now, TimeZone tz) {
return parseInt(simpleDateFormat("d", tz).format(now));
}
static public FixedRateTimer doEvery(long delay, final Object r) {
return doEvery(delay, delay, r);
}
static public FixedRateTimer doEvery(long delay, long firstDelay, final Object r) {
FixedRateTimer timer = new FixedRateTimer(shorten(programID() + ": " + r, 80));
timer.scheduleAtFixedRate(smartTimerTask(r, timer, toInt(delay)), toInt(firstDelay), toInt(delay));
return vmBus_timerStarted(timer);
}
static public FixedRateTimer doEvery(double initialSeconds, double delaySeconds, final Object r) {
return doEvery(toMS(delaySeconds), toMS(initialSeconds), r);
}
static public FixedRateTimer doEvery(double delaySeconds, final Object r) {
return doEvery(toMS(delaySeconds), r);
}
static public int parseInt(String s) {
return emptyString(s) ? 0 : Integer.parseInt(s);
}
static public int parseInt(char c) {
return Integer.parseInt(str(c));
}
static public int boolToInt(boolean b) {
return b ? 1 : 0;
}
static public Class> getClass(String name) {
return _getClass(name);
}
static public Class getClass(Object o) {
return _getClass(o);
}
static public Class getClass(Object realm, String name) {
return _getClass(realm, name);
}
static public Object getFirstNonNullField(Object o, String... fields) {
for (String field : unnullForIteration(fields)) {
Object __1 = getOpt(o, field);
if (__1 != null)
return __1;
}
return null;
}
static public byte[] bytesFromHex(String s) {
return hexToBytes(s);
}
static public String dropPrefix(String prefix, String s) {
return s == null ? null : s.startsWith(prefix) ? s.substring(l(prefix)) : s;
}
static public int ubyteToInt(byte b) {
return b & 0x0FF;
}
static public int ubyteToInt(char c) {
return c & 0x0FF;
}
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 CharSequence subCharSequence(CharSequence s, int x) {
return subCharSequence(s, x, s == null ? 0 : s.length());
}
static public CharSequence subCharSequence(CharSequence 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.subSequence(x, y);
}
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 String snippetImageURL(long snippetID) {
return snippetImageURL(fsI(snippetID));
}
static public String snippetImageURL(String snippetID) {
return snippetImageURL(snippetID, "png");
}
static public String snippetImageURL(String snippetID, String contentType) {
if (snippetID == null || isURL(snippetID))
return snippetID;
long id = parseSnippetID(snippetID);
String url;
if (isImageServerSnippet(id))
url = imageServerLink(id);
else
url = "https://botcompany.de/img/" + id;
return url;
}
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 Object dm_getStem(Object moduleOrID) {
if (isString(moduleOrID) && isIdentifier(((String) moduleOrID)))
moduleOrID = dm_getService(((String) moduleOrID));
if (isStringOrIntOrLong(moduleOrID))
return dm_getStemByID(moduleOrID);
return or(getOpt(dm_getModule(moduleOrID), "_host"), moduleOrID);
}
static public File getProgramDir() {
return programDir();
}
static public File getProgramDir(String snippetID) {
return programDir(snippetID);
}
static public String appendQueryToURL(String url, Map params) {
if (url == null)
return null;
String data = makePostData(params);
if (empty(data))
return url;
int idx = smartIndexOf(url, '#');
String url2 = takeFirst(url, idx);
return url2 + (url2.contains("?") ? "&" : "?") + data + substring(url, idx);
}
static public String appendQueryToURL(String url, Object... data) {
return appendQueryToURL(url, paramsToMap(data));
}
static public String makeRandomID(int length) {
return makeRandomID(length, defaultRandomGenerator());
}
static public String makeRandomID(int length, Random random) {
char[] id = new char[length];
for (int i = 0; i < id.length; i++) id[i] = (char) ((int) 'a' + random.nextInt(26));
return new String(id);
}
static public String makeRandomID(Random r, int length) {
return makeRandomID(length, r);
}
static public WeakHasherMap symbol_map = new WeakHasherMap(new Hasher() {
public int hashCode(Symbol symbol) {
return symbol.text.hashCode();
}
public boolean equals(Symbol a, Symbol b) {
if (a == null)
return b == null;
return b != null && eq(a.text, b.text);
}
});
static public Symbol symbol(String s) {
if (s == null)
return null;
synchronized (symbol_map) {
Symbol symbol = new Symbol(s, true);
Symbol existingSymbol = symbol_map.findKey(symbol);
if (existingSymbol == null)
symbol_map.put(existingSymbol = symbol, true);
return existingSymbol;
}
}
static public Symbol symbol(CharSequence s) {
if (s == null)
return null;
if (s instanceof Symbol)
return (Symbol) s;
if (s instanceof String)
return symbol((String) s);
return symbol(str(s));
}
static public Symbol symbol(Object o) {
return symbol((CharSequence) o);
}
static public void addAll(Collection c, Iterable b) {
if (c != null && b != null)
for (A a : b) c.add(a);
}
static public boolean addAll(Collection c, Collection b) {
return c != null && b != null && c.addAll(b);
}
static public boolean addAll(Collection c, B... b) {
return c != null && b != null && c.addAll(Arrays.asList(b));
}
static public Map addAll(Map a, Map extends A, ? extends B> b) {
if (a != null && b != null)
a.putAll(b);
return a;
}
static public File getCacheProgramDir() {
return getCacheProgramDir(getProgramID());
}
static public File getCacheProgramDir(String snippetID) {
return new File(userHome(), "JavaX-Caches/" + formatSnippetIDOpt(snippetID));
}
static public List jsonTok(String s) {
List tok = new ArrayList();
int l = l(s);
int i = 0;
while (i < l) {
int j = i;
char c;
String cc;
while (j < l) {
c = s.charAt(j);
cc = s.substring(j, Math.min(j + 2, l));
if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
++j;
else if (cc.equals("/*")) {
do ++j; while (j < l && !s.substring(j, Math.min(j + 2, l)).equals("*/"));
j = Math.min(j + 2, l);
} else if (cc.equals("//")) {
do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0);
} else
break;
}
tok.add(s.substring(i, j));
i = j;
if (i >= l)
break;
c = s.charAt(i);
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.isLetter(c))
do ++j; while (j < l && Character.isLetter(s.charAt(j)));
else if (Character.isDigit(c))
do ++j; while (j < l && Character.isDigit(s.charAt(j)));
else
++j;
tok.add(s.substring(i, j));
i = j;
}
if ((tok.size() % 2) == 0)
tok.add("");
return tok;
}
static public Class main() {
return getMainClass();
}
static public String unquote(String s) {
if (s == null)
return null;
if (startsWith(s, '[')) {
int i = 1;
while (i < s.length() && s.charAt(i) == '=') ++i;
if (i < s.length() && s.charAt(i) == '[') {
String m = s.substring(1, i);
if (s.endsWith("]" + m + "]"))
return s.substring(i + 1, s.length() - i - 1);
}
}
if (s.length() > 1) {
char c = s.charAt(0);
if (c == '\"' || c == '\'') {
int l = endsWith(s, c) ? s.length() - 1 : s.length();
StringBuilder sb = new StringBuilder(l - 1);
for (int i = 1; i < l; i++) {
char ch = s.charAt(i);
if (ch == '\\') {
char nextChar = (i == l - 1) ? '\\' : s.charAt(i + 1);
if (nextChar >= '0' && nextChar <= '7') {
String code = "" + nextChar;
i++;
if ((i < l - 1) && s.charAt(i + 1) >= '0' && s.charAt(i + 1) <= '7') {
code += s.charAt(i + 1);
i++;
if ((i < l - 1) && s.charAt(i + 1) >= '0' && s.charAt(i + 1) <= '7') {
code += s.charAt(i + 1);
i++;
}
}
sb.append((char) Integer.parseInt(code, 8));
continue;
}
switch(nextChar) {
case '\"':
ch = '\"';
break;
case '\\':
ch = '\\';
break;
case 'b':
ch = '\b';
break;
case 'f':
ch = '\f';
break;
case 'n':
ch = '\n';
break;
case 'r':
ch = '\r';
break;
case 't':
ch = '\t';
break;
case '\'':
ch = '\'';
break;
case 'u':
if (i >= l - 5) {
ch = 'u';
break;
}
int code = Integer.parseInt("" + s.charAt(i + 2) + s.charAt(i + 3) + s.charAt(i + 4) + s.charAt(i + 5), 16);
sb.append(Character.toChars(code));
i += 5;
continue;
default:
ch = nextChar;
}
i++;
}
sb.append(ch);
}
return sb.toString();
}
}
return s;
}
static public boolean isInteger(String s) {
int n = l(s);
if (n == 0)
return false;
int i = 0;
if (s.charAt(0) == '-')
if (++i >= n)
return false;
while (i < n) {
char c = s.charAt(i);
if (c < '0' || c > '9')
return false;
++i;
}
return true;
}
static public boolean eqOneOf(Object o, Object... l) {
for (Object x : l) if (eq(o, x))
return true;
return false;
}
static public double parseDouble(String s) {
return empty(s) ? 0.0 : Double.parseDouble(s);
}
static public Number boxedIntOrLong(long l) {
return l != (int) l ? boxed(l) : boxed((int) l);
}
static public void _registerIO(Object object, String path, boolean opened) {
}
static public Iterator emptyIterator() {
return Collections.emptyIterator();
}
static public List immutableEmptyList() {
return Collections.emptyList();
}
static public short[] emptyShortArray = new short[0];
static public short[] emptyShortArray() {
return emptyShortArray;
}
static public Map immutableEmptyMap() {
return Collections.emptyMap();
}
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 int shorten_default = 100;
static public String shorten(CharSequence s) {
return shorten(s, shorten_default);
}
static public String shorten(CharSequence s, int max) {
return shorten(s, max, "...");
}
static public String shorten(CharSequence s, int max, String shortener) {
if (s == null)
return "";
if (max < 0)
return str(s);
return s.length() <= max ? str(s) : subCharSequence(s, 0, min(s.length(), max - l(shortener))) + shortener;
}
static public String shorten(int max, CharSequence s) {
return shorten(s, max);
}
static public int parseHexChar(char c) {
if (c >= '0' && c <= '9')
return charDiff(c, '0');
if (c >= 'a' && c <= 'f')
return charDiff(c, 'a') + 10;
if (c >= 'A' && c <= 'F')
return charDiff(c, 'A') + 10;
return -1;
}
static public void _onJavaXSet() {
}
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 Object get2(Object o, String field1, String field2) {
return get(get(o, field1), field2);
}
static public boolean startsWithAny(String a, Collection b) {
for (String prefix : unnullForIteration(b)) if (startsWith(a, prefix))
return true;
return false;
}
static public boolean startsWithAny(String a, String... b) {
if (b != null)
for (String prefix : unnullForIteration(b)) if (startsWith(a, prefix))
return true;
return false;
}
static public boolean startsWithAny(String a, Collection b, Matches m) {
for (String prefix : unnullForIteration(b)) if (startsWith(a, prefix, m))
return true;
return false;
}
static public String mcDollar() {
return mcName() + "$";
}
static public String afterDollar(String s) {
return substring(s, smartIndexOf(s, '$') + 1);
}
static volatile public String caseID_caseID;
static public String caseID() {
return caseID_caseID;
}
static public void caseID(String id) {
caseID_caseID = id;
}
static public String quoteUnlessIdentifierOrInteger(String s) {
return quoteIfNotIdentifierOrInteger(s);
}
static public String[] drop(int n, String[] a) {
n = Math.min(n, a.length);
String[] b = new String[a.length - n];
System.arraycopy(a, n, b, 0, b.length);
return b;
}
static public Object[] drop(int n, Object[] a) {
n = Math.min(n, a.length);
Object[] b = new Object[a.length - n];
System.arraycopy(a, n, b, 0, b.length);
return b;
}
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 boolean isDigit(char c) {
return Character.isDigit(c);
}
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 lastIndexOf(List l, int i, A a) {
if (l == null)
return -1;
for (i = min(l(l), i) - 1; i >= 0; i--) if (eq(l.get(i), a))
return i;
return -1;
}
static public int lastIndexOf(List l, A a) {
if (l == null)
return -1;
for (int i = l(l) - 1; i >= 0; i--) if (eq(l.get(i), a))
return i;
return -1;
}
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) {
f.set(o, ((Long) value).intValue());
return;
}
if (type == boolean.class && value instanceof String) {
f.set(o, isTrueOrYes(((String) value)));
return;
}
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 DynModule dm_currentModuleMandatory() {
return dm_current_mandatory();
}
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 B second(Either e) {
return e == null ? null : e.bOpt();
}
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 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 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) {
_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 List classNames(Collection l) {
return getClassNames(l);
}
static public List classNames(Object[] l) {
return getClassNames(Arrays.asList(l));
}
static public PersistableThrowable persistableThrowable(Throwable e) {
return e == null ? null : new PersistableThrowable(e);
}
static public boolean startsWithOneOf(String s, String... l) {
for (String x : l) if (startsWith(s, x))
return true;
return false;
}
static public boolean startsWithOneOf(String s, Matches m, String... l) {
for (String x : l) if (startsWith(s, x, m))
return true;
return false;
}
static public boolean isAGIBlueDomain(String domain) {
return domainIsUnder(domain, theAGIBlueDomain());
}
static public String hostNameFromURL(String url) {
try {
return new URL(url).getHost();
} catch (Exception __e) {
throw rethrow(__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 pcallF_minimalExceptionHandling(Object f, Object... args) {
try {
return callFunction(f, args);
} catch (Throwable e) {
System.out.println(getStackTrace(e));
_storeException(e);
}
return null;
}
static public void _handleError(Error e) {
call(javax(), "_handleError", e);
}
static public boolean regionMatchesIC(String a, int offsetA, String b, int offsetB, int len) {
return a != null && a.regionMatches(true, offsetA, b, offsetB, len);
}
static public List javaTokForStructure(String s) {
return javaTok_noMLS(s);
}
static public String structure_addTokenMarkers(String s) {
return join(structure_addTokenMarkers(javaTokForStructure(s)));
}
static public List structure_addTokenMarkers(List tok) {
TreeSet refs = new TreeSet();
for (int i = 1; i < l(tok); i += 2) {
String t = tok.get(i);
if (t.startsWith("t") && isInteger(t.substring(1)))
refs.add(parseInt(t.substring(1)));
}
if (empty(refs))
return tok;
for (int i : refs) {
int idx = i * 2 + 1;
if (idx >= l(tok))
continue;
String t = "";
if (endsWithLetterOrDigit(tok.get(idx - 1)))
t = " ";
tok.set(idx, t + "m" + i + " " + tok.get(idx));
}
return tok;
}
static public String jreplace(String s, String in, String out) {
return jreplace(s, in, out, null);
}
static public String jreplace(String s, String in, String out, Object condition) {
List tok = javaTok(s);
return jreplace(tok, in, out, condition) ? join(tok) : s;
}
static public boolean jreplace(List tok, String in, String out) {
return jreplace(tok, in, out, false, true, null);
}
static public boolean jreplace(List tok, String in, String out, Object condition) {
return jreplace(tok, in, out, false, true, condition);
}
static public boolean jreplace(List tok, String in, String out, IF2, Integer, Boolean> condition) {
return jreplace(tok, in, out, (Object) condition);
}
static public boolean jreplace(List tok, String in, String out, boolean ignoreCase, boolean reTok, Object condition) {
String[] toks = javaTokForJFind_array(in);
int lTokin = toks.length * 2 + 1;
boolean anyChange = false;
int i = -1;
for (int n = 0; n < 10000; n++) {
i = findCodeTokens(tok, i + 1, ignoreCase, toks, condition);
if (i < 0)
return anyChange;
List subList = tok.subList(i - 1, i + lTokin - 1);
String expansion = jreplaceExpandRefs(out, subList);
int end = i + lTokin - 2;
clearAllTokens(tok, i, end);
tok.set(i, expansion);
if (reTok)
reTok(tok, i, end);
i = end;
anyChange = true;
}
throw fail("woot? 10000! " + quote(in) + " => " + quote(out));
}
static public boolean jreplace_debug = false;
static public Map mruCache(int maxSize) {
return synchronizedMRUCache(maxSize);
}
static public int defaultStringTransformerCacheSize() {
return 1000;
}
static public List quotelessJavaTok(String s) {
ArrayList tok = new ArrayList();
int l = l(s);
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 (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
++j;
tok.add(javaTok_substringC(s, i, j));
++n;
i = j;
}
if ((tok.size() % 2) == 0)
tok.add("");
return tok;
}
static public Object loadJSONPage(String url) {
return jsonDecode(loadPage(url));
}
static public A printHidingCredentials(A o) {
print(hideCredentials(str(o)));
return o;
}
static public String agiBlue_linkForPhrase(String phrase, Object... additionalParams) {
return agiBlueURL() + hquery(arrayPlus(additionalParams, "q", phrase));
}
static public Object[] paramsPlus(Object[] a1, Object... a2) {
if (a2 == null)
return a1;
if (a1 == null)
return a2;
if (l(a1) == 1 && a1[0] instanceof Map)
return new Object[] { mapPlus((Map) a1[0], a2) };
assertEvenLength(a1);
assertEvenLength(a2);
Map map = paramsToOrderedMap(a1);
int n = l(a2);
for (int i = 0; i < n; i += 2) {
Object key = a2[i];
if (key != null)
map.put(key, a2[i + 1]);
}
return mapToParams(map);
}
static public Object[] paramsPlus(Map a1, Object... a2) {
return paramsPlus(new Object[] { a1 }, a2);
}
static public Object[] paramsWithSameKey(Object key, Collection values) {
return paramsWithSameKey(key, asObjectArray(values));
}
static public Object[] paramsWithSameKey(Object key, Object... values) {
int n = l(values);
Object[] o = new Object[n * 2];
for (int i = 0; i < n; i++) {
o[i * 2] = key;
o[i * 2 + 1] = values[i];
}
return o;
}
static public boolean agiBlueURL_noHTTPS = false;
static public String agiBlueURL_url = "https://agi.blue";
static public String agiBlueURL() {
return agiBlueURL_noHTTPS ? replacePrefix("https://", "http://", agiBlueURL_url) : agiBlueURL_url;
}
static public String hquery(Map params) {
return htmlQuery(params);
}
static public String hquery(Object... data) {
return htmlQuery(data);
}
static public x30_pkg.x30_util.BetterThreadLocal newPing_actionTL;
static public x30_pkg.x30_util.BetterThreadLocal newPing_actionTL() {
if (newPing_actionTL == null)
newPing_actionTL = vm_generalMap_getOrCreate("newPing_actionTL", () -> {
Runnable value = (Runnable) (callF_gen(vm_generalMap_get("newPing_valueForNewThread")));
var tl = new x30_pkg.x30_util.BetterThreadLocal();
tl.set(value);
return tl;
});
return newPing_actionTL;
}
static volatile public boolean licensed_yes = true;
static public boolean licensed() {
if (!licensed_yes)
return false;
ping_okInCleanUp();
return true;
}
static public void licensed_off() {
licensed_yes = false;
}
public static boolean isSnippetID(String s) {
try {
parseSnippetID(s);
return true;
} catch (RuntimeException e) {
return false;
}
}
static public String mainClassNameForClassLoader(ClassLoader cl) {
return or((String) callOpt(cl, "mainClassName"), "main");
}
static public Class loadClassFromClassLoader_orNull(ClassLoader cl, String name) {
try {
return cl == null ? null : cl.loadClass(name);
} catch (ClassNotFoundException e) {
return null;
}
}
static public boolean endsWith(String a, String b) {
return a != null && a.endsWith(b);
}
static public boolean endsWith(String a, char c) {
return nempty(a) && lastChar(a) == c;
}
static public boolean endsWith(String a, String b, Matches m) {
if (!endsWith(a, b))
return false;
m.m = new String[] { dropLast(l(b), a) };
return true;
}
static public boolean regionMatches(String a, int offsetA, String b, int offsetB, int len) {
return a != null && b != null && a.regionMatches(offsetA, b, offsetB, len);
}
static public boolean regionMatches(String a, int offsetA, String b) {
return regionMatches(a, offsetA, b, 0, l(b));
}
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 Map javaTokForJFind_array_cache = synchronizedMRUCache(1000);
static public String[] javaTokForJFind_array(String s) {
String[] tok = javaTokForJFind_array_cache.get(s);
if (tok == null)
javaTokForJFind_array_cache.put(s, tok = codeTokensAsStringArray(jfind_preprocess(javaTok(s))));
return tok;
}
static public int findCodeTokens(List tok, String... tokens) {
return findCodeTokens(tok, 1, false, tokens);
}
static public int findCodeTokens(List tok, boolean ignoreCase, String... tokens) {
return findCodeTokens(tok, 1, ignoreCase, tokens);
}
static public int findCodeTokens(List tok, int startIdx, boolean ignoreCase, String... tokens) {
return findCodeTokens(tok, startIdx, ignoreCase, tokens, null);
}
static public HashSet findCodeTokens_specials = lithashset("*", "", "", "", "\\*");
static public int findCodeTokens_bails, findCodeTokens_nonbails;
static public interface findCodeTokens_Matcher {
public boolean get(String token);
}
static public int findCodeTokens(List tok, int startIdx, boolean ignoreCase, String[] tokens, Object condition) {
int end = tok.size() - tokens.length * 2 + 2, nTokens = tokens.length;
int i = startIdx | 1;
if (i >= end)
return -1;
String firstToken = tokens[0];
if (!ignoreCase && !findCodeTokens_specials.contains(firstToken)) {
while (i < end && !firstToken.equals(tok.get(i))) i += 2;
}
findCodeTokens_Matcher[] matchers = new findCodeTokens_Matcher[nTokens];
for (int j = 0; j < nTokens; j++) {
String p = tokens[j];
findCodeTokens_Matcher matcher;
if (p.equals("*"))
matcher = t -> true;
else if (p.equals(""))
matcher = t -> isQuoted(t);
else if (p.equals(""))
matcher = t -> isIdentifier(t);
else if (p.equals(""))
matcher = t -> isInteger(t);
else if (p.equals("\\*"))
matcher = t -> t.equals("*");
else if (ignoreCase)
matcher = t -> eqic(p, t);
else
matcher = t -> t.equals(p);
matchers[j] = matcher;
}
outer: for (; i < end; i += 2) {
for (int j = 0; j < nTokens; j++) if (!matchers[j].get(tok.get(i + j * 2)))
continue outer;
if (condition == null || checkTokCondition(condition, tok, i - 1))
return i;
}
return -1;
}
static public String[] codeTokensAsStringArray(List tok) {
int n = max(0, (l(tok) - 1) / 2);
String[] out = new String[n];
for (int i = 0; i < n; i++) out[i] = tok.get(i * 2 + 1);
return out;
}
static public ArrayList litlist(A... a) {
ArrayList l = new ArrayList(a.length);
for (A x : a) l.add(x);
return l;
}
static public List replaceSublist(List l, List x, List y) {
if (x == null)
return l;
int i = 0;
while (true) {
i = indexOfSubList(l, x, i);
if (i < 0)
break;
replaceSublist(l, i, i + l(x), y);
i += l(y);
}
return l;
}
static public List replaceSublist(List l, int fromIndex, int toIndex, List y) {
int n = y.size(), toIndex_new = fromIndex + n;
if (toIndex_new < toIndex) {
removeSubList(l, toIndex_new, toIndex);
copyListPart(y, 0, l, fromIndex, n);
} else {
copyListPart(y, 0, l, fromIndex, toIndex - fromIndex);
if (toIndex_new > toIndex)
l.addAll(toIndex, subList(y, toIndex - fromIndex));
}
return l;
}
static public CloseableIterableIterator emptyCloseableIterableIterator_instance = new CloseableIterableIterator() {
public Object next() {
throw fail();
}
public boolean hasNext() {
return false;
}
};
static public CloseableIterableIterator emptyCloseableIterableIterator() {
return emptyCloseableIterableIterator_instance;
}
static public boolean ewic(String a, String b) {
return endsWithIgnoreCase(a, b);
}
static public boolean ewic(String a, String b, Matches m) {
return endsWithIgnoreCase(a, b, m);
}
static public CloseableIterableIterator linesFromReader(Reader r) {
return linesFromReader(r, null);
}
static public CloseableIterableIterator linesFromReader(Reader r, IResourceHolder resourceHolder) {
final BufferedReader br = bufferedReader(r);
return holdResource(resourceHolder, iteratorFromFunction_f0_autoCloseable(new F0() {
public String get() {
try {
return readLineFromReaderWithClose(br);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret readLineFromReaderWithClose(br);";
}
}, _wrapIOCloseable(r)));
}
static public BufferedReader utf8bufferedReader(InputStream in) {
try {
return in == null ? null : bufferedReader(_registerIOWrap(new InputStreamReader(in, "UTF-8"), in));
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public BufferedReader utf8bufferedReader(File f) {
try {
return utf8bufferedReader(newFileInputStream(f));
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public GZIPInputStream newGZIPInputStream(File f) {
return gzInputStream(f);
}
static public GZIPInputStream newGZIPInputStream(InputStream in) {
return gzInputStream(in);
}
static public Matcher regexp(String pat, String s) {
return regexp(compileRegexp(pat), unnull(s));
}
static public Matcher regexp(java.util.regex.Pattern pat, String s) {
return pat.matcher(unnull(s));
}
static public java.util.regex.Pattern regexp(String pat) {
return compileRegexp(pat);
}
static public int localYear() {
return localYear(now());
}
static public int localYear(long time) {
return parseInt(simpleDateFormat_local("yyyy").format(time));
}
static public java.text.SimpleDateFormat simpleDateFormat(String format, TimeZone timeZone) {
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format);
sdf.setTimeZone(timeZone);
return sdf;
}
static public String padLeft(String s, char c, int n) {
return rep(c, n - l(s)) + s;
}
static public String padLeft(String s, int n) {
return padLeft(s, ' ', n);
}
static public int localMonth(long time) {
return parseInt(simpleDateFormat_local("MM").format(time));
}
static public int localMonth() {
return localMonth(now());
}
static public int localDayOfMonth(long time) {
return parseInt(simpleDateFormat_local("dd").format(time));
}
static public int localDayOfMonth() {
return localDayOfMonth(now());
}
static public TimerTask smartTimerTask(Object r, java.util.Timer timer, long delay) {
return new SmartTimerTask(r, timer, delay, _threadInfo());
}
static public class SmartTimerTask extends TimerTask implements IFieldsToList {
public Object r;
public java.util.Timer timer;
public long delay;
public Object threadInfo;
public SmartTimerTask() {
}
public SmartTimerTask(Object r, java.util.Timer timer, long delay, Object threadInfo) {
this.threadInfo = threadInfo;
this.delay = delay;
this.timer = timer;
this.r = r;
}
public String toString() {
return shortClassName_dropNumberPrefix(this) + "(" + r + ", " + timer + ", " + delay + ", " + threadInfo + ")";
}
public Object[] _fieldsToList() {
return new Object[] { r, timer, delay, threadInfo };
}
public long lastRun;
public void run() {
if (!licensed())
timer.cancel();
else {
_threadInheritInfo(threadInfo);
AutoCloseable __1 = tempActivity(r);
try {
lastRun = fixTimestamp(lastRun);
long now = now();
if (now >= lastRun + delay * 0.9) {
lastRun = now;
if (eq(false, pcallF(r)))
timer.cancel();
}
} finally {
_close(__1);
}
}
}
}
static public A vmBus_timerStarted(A timer) {
vmBus_send("timerStarted", timer, costCenter());
return timer;
}
static public boolean emptyString(String s) {
return s == null || s.length() == 0;
}
static public int min(int a, int b) {
return Math.min(a, b);
}
static public long min(long a, long b) {
return Math.min(a, b);
}
static public float min(float a, float b) {
return Math.min(a, b);
}
static public float min(float a, float b, float c) {
return min(min(a, b), c);
}
static public double min(double a, double b) {
return Math.min(a, b);
}
static public double min(double[] c) {
double x = Double.MAX_VALUE;
for (double d : c) x = Math.min(x, d);
return x;
}
static public float min(float[] c) {
float x = Float.MAX_VALUE;
for (float d : c) x = Math.min(x, d);
return x;
}
static public byte min(byte[] c) {
byte x = 127;
for (byte d : c) if (d < x)
x = d;
return x;
}
static public short min(short[] c) {
short x = 0x7FFF;
for (short d : c) if (d < x)
x = d;
return x;
}
static public int min(int[] c) {
int x = Integer.MAX_VALUE;
for (int d : c) if (d < x)
x = d;
return x;
}
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 String fsI(String id) {
return formatSnippetID(id);
}
static public String fsI(long id) {
return formatSnippetID(id);
}
static public boolean isURL(String s) {
return startsWithOneOf(s, "http://", "https://", "file:");
}
static public boolean isImageServerSnippet(long id) {
return id >= 1100000 && id < 1200000;
}
static public String imageServerLink(String md5OrID) {
if (possibleMD5(md5OrID))
return "https://botcompany.de/images/md5/" + md5OrID;
return imageServerLink(parseSnippetID(md5OrID));
}
static public String imageServerLink(long id) {
return "https://botcompany.de/images/" + id;
}
static public boolean isString(Object o) {
return o instanceof String;
}
static public boolean isIdentifier(String s) {
return isJavaIdentifier(s);
}
static public Object dm_getService(String serviceName) {
return empty(serviceName) ? null : dm_getModule(vmBus_query(assertIdentifier(serviceName)));
}
static public boolean isStringOrIntOrLong(Object o) {
return o instanceof String || o instanceof Integer || o instanceof Long;
}
static public Object dm_getStemByID(Object id) {
return dm_callOS("getModuleByID", str(id));
}
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 File programDir_mine;
static public File programDir() {
return programDir(getProgramID());
}
static public File programDir(String snippetID) {
boolean me = sameSnippetID(snippetID, programID());
if (programDir_mine != null && me)
return programDir_mine;
File dir = new File(javaxDataDir(), formatSnippetIDOpt(snippetID));
if (me) {
String c = caseID();
if (nempty(c))
dir = newFile(dir, c);
}
return dir;
}
static public File programDir(String snippetID, String subPath) {
return new File(programDir(snippetID), subPath);
}
static public String makePostData(Map map) {
StringBuilder buf = new StringBuilder();
for (Map.Entry e : castMapToMapO(map).entrySet()) {
String key = (String) (e.getKey());
Object val = e.getValue();
if (val != null) {
String value = str(val);
if (nempty(buf))
buf.append("&");
buf.append(urlencode(key)).append("=").append(urlencode((value)));
}
}
return str(buf);
}
static public String makePostData(Object... params) {
StringBuilder buf = new StringBuilder();
int n = l(params);
for (int i = 0; i + 1 < n; i += 2) {
String key = (String) (params[i]);
Object val = params[i + 1];
if (val != null) {
String value = str(val);
if (nempty(buf))
buf.append("&");
buf.append(urlencode(key)).append("=").append(urlencode((value)));
}
}
return str(buf);
}
static public int smartIndexOf(String s, String sub, int i) {
if (s == null)
return 0;
i = s.indexOf(sub, min(i, l(s)));
return i >= 0 ? i : l(s);
}
static public int smartIndexOf(String s, int i, char c) {
return smartIndexOf(s, c, i);
}
static public int smartIndexOf(String s, char c, int i) {
if (s == null)
return 0;
i = s.indexOf(c, min(i, l(s)));
return i >= 0 ? i : l(s);
}
static public int smartIndexOf(String s, String sub) {
return smartIndexOf(s, sub, 0);
}
static public int smartIndexOf(String s, char c) {
return smartIndexOf(s, c, 0);
}
static public int smartIndexOf(List l, A sub) {
return smartIndexOf(l, sub, 0);
}
static public int smartIndexOf(List l, int start, A sub) {
return smartIndexOf(l, sub, start);
}
static public int smartIndexOf(List l, A sub, int start) {
int i = indexOf(l, sub, start);
return i < 0 ? l(l) : i;
}
static public Map paramsToMap(Object... params) {
int n = l(params);
if (l(params) == 1 && params[0] instanceof Map)
return (Map) params[0];
LinkedHashMap map = new LinkedHashMap();
for (int i = 0; i + 1 < n; i += 2) mapPut(map, params[i], params[i + 1]);
return map;
}
static public Random defaultRandomGenerator() {
return ThreadLocalRandom.current();
}
static public String _userHome;
static public String userHome() {
if (_userHome == null)
return actualUserHome();
return _userHome;
}
static public File userHome(String path) {
return new File(userDir(), path);
}
static public boolean startsWith(String a, String b) {
return a != null && a.startsWith(unnull(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;
if (m != null)
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 Integer boxed(int i) {
return i;
}
static public Long boxed(long l) {
return l;
}
static public int charDiff(char a, char b) {
return (int) a - (int) b;
}
static public int charDiff(String a, char b) {
return charDiff(stringToChar(a), b);
}
static public A setThreadLocal(ThreadLocal tl, A value) {
if (tl == null)
return null;
A old = tl.get();
tl.set(value);
return old;
}
static public String mcName() {
return mc().getName();
}
static public String quoteIfNotIdentifierOrInteger(String s) {
if (s == null)
return null;
return isJavaIdentifier(s) || isInteger(s) ? s : quote(s);
}
static public boolean isTrueOrYes(Object o) {
return isTrueOpt(o) || o instanceof String && (eqicOneOf(((String) o), "1", "t", "true") || isYes(((String) o)));
}
static public LinkedHashMap asLinkedHashMap(Map map) {
if (map instanceof LinkedHashMap)
return (LinkedHashMap) map;
LinkedHashMap m = new LinkedHashMap();
if (map != null)
synchronized (collectionMutex(map)) {
m.putAll(map);
}
return m;
}
static public Set synchronizedSet() {
return synchroHashSet();
}
static public Set synchronizedSet(Set set) {
return Collections.synchronizedSet(set);
}
static public Set identityHashSet() {
return Collections.newSetFromMap(new IdentityHashMap());
}
static public char charAt(String s, int i) {
return s != null && i >= 0 && i < s.length() ? s.charAt(i) : '\0';
}
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 Throwable getExceptionCause(Throwable e) {
Throwable c = e.getCause();
return c != null ? c : e;
}
static public String joinWithSpace(Iterable c) {
return join(" ", c);
}
static public String joinWithSpace(String... c) {
return join(" ", c);
}
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, Math.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 boolean domainIsUnder(String domain, String mainDomain) {
return eqic(domain, mainDomain) || ewic(domain, "." + mainDomain);
}
static public String theAGIBlueDomain() {
return "agi.blue";
}
static public Object collectionMutex(List l) {
return l;
}
static public Object collectionMutex(Object o) {
if (o instanceof List)
return o;
String c = className(o);
if (eq(c, "java.util.TreeMap$KeySet"))
c = className(o = getOpt(o, "m"));
else if (eq(c, "java.util.HashMap$KeySet"))
c = className(o = get_raw(o, "this$0"));
if (eqOneOf(c, "java.util.TreeMap$AscendingSubMap", "java.util.TreeMap$DescendingSubMap"))
c = className(o = get_raw(o, "m"));
return o;
}
static public Object callFunction(Object f, Object... args) {
return callF(f, args);
}
static public Throwable _storeException_value;
static public void _storeException(Throwable e) {
_storeException_value = e;
}
static public List javaTok_noMLS(String s) {
ArrayList