Example usage for org.apache.commons.lang3 StringUtils join

List of usage examples for org.apache.commons.lang3 StringUtils join

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils join.

Prototype

public static String join(final Object[] array, String separator, final int startIndex, final int endIndex) 

Source Link

Document

Joins the elements of the provided array into a single String containing the provided list of elements.

No delimiter is added before or after the list.

Usage

From source file:com.kantenkugel.discordbot.Main.java

public static void main(String[] args) {
    boolean isDbBot = false;
    if (args.length == 2 && Boolean.parseBoolean(args[1])) {
        isDbBot = true;/*  w ww .j a v  a2 s.  c  o  m*/
    } else if (args.length < 4) {
        System.out.println("Missing arguments!");
        return;
    }

    if (!BotConfig.load()) {
        System.out.println("Bot config created/updated. Please populate/check it before restarting the Bot");
        System.exit(Statics.NORMAL_EXIT_CODE);
    }

    if (BotConfig.get("logToFiles", true)) {
        try {
            SimpleLog.addFileLogs(new File("logs/main.txt"), new File("logs/err.txt"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (!isDbBot) {
        Statics.START_TIME = Long.parseLong(args[1]);
        Statics.VERSION = Integer.parseInt(args[3]);
    }

    if (!isDbBot && args.length > 4) {
        Statics.CHANGES = StringUtils.join(args, '\n', 4, args.length);
    } else {
        Statics.CHANGES = null;
    }

    if (isDbBot) {
        if ("".equals(BotConfig.get("historyBase"))) {
            Statics.LOG.fatal("Please specify a history-base in the config");
            System.exit(Statics.NORMAL_EXIT_CODE);
        }
        if (!DbEngine.init()) {
            Statics.LOG.fatal("Could not connect to db! shutting down");
            System.exit(Statics.NORMAL_EXIT_CODE);
        }
    } else {
        DocParser.init();
        Module.init();
    }
    try {
        JDABuilder jdaBuilder = new JDABuilder().setBotToken(args[0]).setAudioEnabled(false);
        if (isDbBot)
            jdaBuilder.addListener(new DbListener());
        else
            jdaBuilder.addListener(new StatusListener()).addListener(new InviteListener())
                    .addListener(new MessageListener());
        if (!isDbBot && !args[2].equals("-")) {
            boolean success = Boolean.parseBoolean(args[2]);
            if (success) {
                checker = UpdateValidator.getInstance();
                checker.start();
            }
            jdaBuilder.addListener(new UpdatePrintListener(success));
        }
        Statics.jdaInstance = jdaBuilder.buildAsync();
        if (!isDbBot)
            CommandRegistry.loadCommands(Statics.jdaInstance);
        new UpdateWatcher(Statics.jdaInstance);
    } catch (LoginException e) {
        Statics.LOG.fatal("Login informations were incorrect!");
        System.err.flush();
    }
}

From source file:com.act.lcms.v2.TraceIndexExtractor.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());/*from w  w  w.  j a  v  a 2s .c om*/
    }

    CommandLine cl = null;
    try {
        CommandLineParser parser = new DefaultParser();
        cl = parser.parse(opts, args);
    } catch (ParseException e) {
        System.err.format("Argument parsing failed: %s\n", e.getMessage());
        HELP_FORMATTER.printHelp(TraceIndexExtractor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        System.exit(1);
    }

    if (cl.hasOption("help")) {
        HELP_FORMATTER.printHelp(TraceIndexExtractor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        return;
    }

    // Not enough memory available?  We're gonna need a bigger heap.
    long maxMemory = Runtime.getRuntime().maxMemory();
    if (maxMemory < 1 << 34) { // 16GB
        String msg = StringUtils.join(
                String.format(
                        "You have run this class with a maximum heap size of less than 16GB (%d to be exact). ",
                        maxMemory),
                "There is no way this process will complete with that much space available. ",
                "Crank up your heap allocation with -Xmx and try again.", "");
        throw new RuntimeException(msg);
    }

    File inputFile = new File(cl.getOptionValue(OPTION_SCAN_FILE));
    if (!inputFile.exists()) {
        System.err.format("Cannot find input scan file at %s\n", inputFile.getAbsolutePath());
        HELP_FORMATTER.printHelp(TraceIndexExtractor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        System.exit(1);
    }

    File rocksDBFile = new File(cl.getOptionValue(OPTION_INDEX_PATH));
    if (rocksDBFile.exists()) {
        System.err.format("Index file at %s already exists--remove and retry\n", rocksDBFile.getAbsolutePath());
        HELP_FORMATTER.printHelp(TraceIndexExtractor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true);
        System.exit(1);
    }

    List<Double> targetMZs = new ArrayList<>();
    try (BufferedReader reader = new BufferedReader(new FileReader(cl.getOptionValue(OPTION_TARGET_MASSES)))) {
        String line;
        while ((line = reader.readLine()) != null) {
            targetMZs.add(Double.valueOf(line));
        }
    }

    TraceIndexExtractor extractor = new TraceIndexExtractor();
    extractor.processScan(targetMZs, inputFile, rocksDBFile);
}

From source file:com.xiaoke.common.util.EncryptionUtil.java

/**
 * ????MD5/*from  w  ww.ja  va 2 s  .  co m*/
 * @param password
 * @DESCRIPION :
 * @Create on: 2012-9-12 ?9:46:31
 * @Author : "wwh"
 * @return : String
 */
public static String encryption(String userName, String password) {
    String userPassword = StringUtils.join(password, "{", userName, "}");
    String newPassword = MD5.md5(userPassword);
    return newPassword;
}

From source file:com.blackducksoftware.integration.hub.util.HubUrlParser.java

public static String getBaseUrl(final String url) throws URISyntaxException {
    final URI uri = new URI(url);
    final String derivedUrlPrefix = StringUtils.join(uri.getScheme(), "://", uri.getAuthority(), "/");
    return derivedUrlPrefix;
}

From source file:info.mikaelsvensson.devtools.common.PathUtils.java

public static String getRelativePath(File source, File target) {
    source = source.isDirectory() ? source : source.getParentFile();

    String sourceFixed = fixPath(source);
    String targetFixed = fixPath(target);

    String[] sourceParts = StringUtils.split(sourceFixed, SEP);
    String[] targetParts = StringUtils.split(targetFixed, SEP);
    int sharedParts = 0;
    for (int i = 0; i < sourceParts.length; i++) {
        String sourcePart = sourceParts[i];
        if (targetParts.length == i) {
            break;
        }//w  w  w . j  a  v a  2 s  . co  m
        String targetPart = targetParts[i];
        if (sourcePart.equals(targetPart)) {
            sharedParts = i;
        }
    }

    String toSharedRoot = StringUtils.repeat(".." + SEP, sourceParts.length - sharedParts - 1);
    String fromSharedRoot = StringUtils.join(targetParts, SEP, sharedParts + 1, targetParts.length);
    if (StringUtils.isEmpty(toSharedRoot) && StringUtils.isEmpty(fromSharedRoot)) {
        return "." + SEP;
    } else {
        return toSharedRoot + fromSharedRoot;
    }

}

From source file:net.dv8tion.discord.commands.MyAnimeListCommand.java

@Override
public void onCommand(MessageReceivedEvent e, String[] args) {
    List<SearchResult> results = GoogleSearch.performSearch("018291224751151548851:pwowlyhmpyc",
            StringUtils.join(args, "+", 1, args.length));

    sendMessage(e, results.get(0).getSuggestedReturn());
}

From source file:net.dv8tion.discord.commands.SearchCommand.java

@Override
public void onCommand(MessageReceivedEvent e, String[] args) {
    String filter = null;//from   ww  w  . ja v  a2s  .  c  o m
    switch (args[0]) {
    case ".google":
    case ".g":
        break;
    case ".wiki":
        filter = "wiki";
        break;
    case ".urban":
        filter = "site:urbandictionary.com";
        break;
    default:
        return;
    }

    List<SearchResult> results = GoogleSearch.performSearch("018291224751151548851%3Ajzifriqvl1o",
            StringUtils.join(args, "+", 1, args.length) + ((filter != null) ? ("+" + filter) : ""));

    sendMessage(e, results.get(0).getSuggestedReturn());
}

From source file:dev.maisentito.suca.commands.FourChanCommandHandler.java

private void searchCommand(MessageEvent event, String[] args) throws IOException {
    String seq = StringUtils.join(args, ' ', 2, args.length);
    Pattern pattern;//from  w w  w . j  a  va  2s  .c om
    try {
        pattern = Pattern.compile(seq, Pattern.CASE_INSENSITIVE);
    } catch (PatternSyntaxException e) {
        pattern = null;
    }

    for (FourChan.Catalog.Page page : FourChan.getCatalog(args[1]).pages) {
        for (FourChan.Catalog.ThreadPreview thread : page.threads) {
            if ((thread == null) || (thread.com == null)) {
                continue;
            }

            thread.com = Jsoup.parseBodyFragment(thread.com).text();

            if (pattern != null) {
                if (pattern.matcher(thread.com).find()) {
                    event.respond("match found: " + threadUrl(args[1], thread.no));
                    return;
                }
            } else {
                if (thread.com.contains(seq)) {
                    event.respond("match found: " + threadUrl(args[1], thread.no));
                    return;
                }
            }
        }
    }

    event.respond("no matches found");
}

From source file:net.ae97.pokebot.extensions.removal.RemoveExtension.java

@Override
public void runEvent(CommandEvent ce) {
    if (ce.getArgs().length == 0) {
        return;/*  w w w.j  a va 2s . co m*/
    }
    if (ce.getChannel() == null) {
        return;
    }
    List<String> enabledChannels = getConfig().getStringList("channels");
    if (!enabledChannels.contains(ce.getChannel().getName())) {
        return;
    }
    if (!ce.getUser().getChannelsVoiceIn().contains(ce.getChannel())) {
        return;
    }
    String targetUser = ce.getArgs()[0];
    String kickReason = getConfig().getString("kickmessage", "You have been removed from this channel");
    if (ce.getArgs().length > 1) {
        kickReason = StringUtils.join(ce.getArgs(), " ", 1, ce.getArgs().length);
    }
    User target = PokeBot.getUser(targetUser);
    if (!target.getChannels().contains(ce.getChannel())) {
        return;
    }
    if (ce.getCommand().equalsIgnoreCase("terminate") || ce.getCommand().equalsIgnoreCase("ban")) {
        String hostname = "*!*@" + target.getHostmask();
        ce.getChannel().send().ban(hostname);
    }
    ce.getChannel().send().kick(target, kickReason);
}

From source file:net.dv8tion.discord.commands.AnimeNewsNetworkCommand.java

@Override
public void onCommand(MessageReceivedEvent e, String[] args) {
    List<SearchResult> results = GoogleSearch.performSearch("018291224751151548851:g6kjw0k_cp8",
            StringUtils.join(args, "+", 1, args.length));

    sendMessage(e, handleSearch(results.get(0)));
}