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 Iterable<?> iterable, final String separator) 

Source Link

Document

Joins the elements of the provided Iterable into a single String containing the provided elements.

No delimiter is added before or after the list.

Usage

From source file:edu.illinois.cs.cogcomp.utils.Utils.java

/**
 * This reads a file in the ngram-format
 * http://www.speech.sri.com/projects/srilm/manpages/ngram-format.5.html
 *
 * and populates the languagemodel datastructure.
 *
 * @param fname/*from w ww.  j  a  v a  2  s  . c  o  m*/
 * @return
 * @throws FileNotFoundException
 */
public static HashMap<String, Double> readSRILM(String fname) throws FileNotFoundException {
    List<String> lines = LineIO.read(fname);

    HashMap<String, Double> out = new HashMap<>();

    for (String line : lines) {

        if (line.trim().length() == 0 || line.startsWith("\\") || line.contains("ngram")) {
            // do nothing.
        } else {
            String[] sline = line.trim().split("\t");
            // important because of the log probabilities
            Double v = Math.exp(Double.parseDouble(sline[0]));
            String ngram = sline[1];

            String[] chars = ngram.split(" ");

            out.put(StringUtils.join(chars, ""), v);
        }
    }

    return out;
}

From source file:de.micromata.genome.util.i18n.ChainedResourceBundleTranslationResolver.java

@Override
public I18NTranslationProvider getTranslationFor(Locale locale) {
    Map<String, Object> entries = new HashMap<>();
    for (String resId : resIds) {
        ResourceBundle resbundle = ResourceBundle.getBundle(resId, locale);
        for (String key : resbundle.keySet()) {
            entries.putIfAbsent(key, resbundle.getObject(key));
        }/*  w  w w .  j  a  va 2 s.  c  o m*/
    }
    return new MapTranslationProvider(StringUtils.join(resIds, "_"), entries);
}

From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.user.GetPlayerSummaries.java

public GetPlayerSummaries(int apiVersion, Long... steamIds) {
    super("GetPlayerSummaries", apiVersion);
    urlParam("steamids", StringUtils.join(steamIds, ","));
}

From source file:com.mingo.query.util.QueryUtils.java

/**
 * Builds composite query ID ith next structure "dbName.collectionName.id".
 *
 * @param dbName         DB name//from   www . j av  a  2s  .  c om
 * @param collectionName collection name
 * @param id             query id
 * @return composite ID - { [dbName].[collectionName].[id] }
 */
public static String buildCompositeId(String dbName, String collectionName, String id) {
    Validate.notBlank(dbName, "dbName cannot be null");
    Validate.notBlank(collectionName, "collectionName cannot be null");
    Validate.notBlank(id, "id cannot be null");
    return StringUtils.join(Lists.newArrayList(dbName, collectionName, id), ".");
}

From source file:ductive.parse.CombinedTests.java

@Test
public void test() {
    String text = StringUtils.join(Arrays.asList("line1", "'line2'", "\"line3\""), "\n");

    Parser<?> endOfLine = Parsers.or(Parsers.EOL, Parsers.EOF);
    Parser<String> stuff = Parsers.string("line").followedBy(Parsers.number());
    Parser<String> stuffRepr = Parsers.or(Parsers.doubleQuoted(stuff), Parsers.singleQuoted(stuff), stuff);
    Parser<String> line = stuffRepr.followedBy(endOfLine);
    Parser<List<String>> lines = line.many1();

    List<String> result = lines.parseFully(text);

    assertEquals(3, result.size());/*from   w  w w.  j  av  a  2  s.  c  o  m*/
    assertThat(result, is(Arrays.asList("line", "line", "line")));
}

From source file:net.ae97.pokebot.extensions.mcf.MCFExtension.java

@Override
public void runEvent(CommandEvent event) {
    String[] args = event.getArgs();
    BufferedReader reader = null;
    String total = StringUtils.join(args, " ");
    if (args.length == 0 || total.isEmpty()) {
        event.respond("http://www.minecraftforum.net");
        return;/*  w  w w.j a  v  a 2  s  . c om*/
    }
    try {
        String url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:http://www.minecraftforum.net%20"
                + total.replace(" ", "%20");
        URL path = new URL(url);
        reader = new BufferedReader(new InputStreamReader(path.openStream()));
        List<String> parts = new ArrayList<>();
        String s;
        while ((s = reader.readLine()) != null) {
            parts.add(s);
        }
        List<String> b = new ArrayList<>();
        for (String part : parts) {
            String[] c = part.split(",");
            b.addAll(Arrays.asList(c));
        }
        for (String string : b) {
            if (string.startsWith("\"url\":")) {
                string = string.replace("\"", "");
                string = string.replace("url:", "");
                event.respond(string);
                break;
            }
        }
    } catch (IOException ex) {
        PokeBot.getLogger().log(Level.SEVERE, null, ex);
        event.respond("An error occured");
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (IOException ex) {
            PokeBot.getLogger().log(Level.SEVERE, null, ex);
        }
    }
}

From source file:io.wcm.caravan.pipeline.extensions.hal.action.InlineEmbedded.java

@Override
public String getId() {
    return "INLINE-EMBEDDED(" + StringUtils.join(relations, '-') + ")";
}

From source file:net.ae97.pokebot.extensions.google.GoogleExtension.java

@Override
public void runEvent(CommandEvent event) {
    final String[] args = event.getArgs();
    BufferedReader reader = null;
    String total = StringUtils.join(args, "+").replace(" ", "+");
    if (args.length == 0 || total.isEmpty()) {
        event.respond("http://www.google.com");
        return;/*from www .  ja  va  2 s  . co m*/
    }
    try {
        String url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=" + total;
        URL path = new URL(url);
        reader = new BufferedReader(new InputStreamReader(path.openStream()));
        List<String> parts = new ArrayList<>();
        String s;
        while ((s = reader.readLine()) != null) {
            parts.add(s);
        }
        List<String> b = new ArrayList<>();
        for (String part : parts) {
            String[] c = part.split(",");
            b.addAll(Arrays.asList(c));
        }
        for (String string : b) {
            if (string.startsWith("\"url\":")) {
                string = string.replace("\"", "");
                string = string.replace("url:", "");
                event.respond(string);
                break;
            }
        }
    } catch (IOException ex) {
        PokeBot.getLogger().log(Level.SEVERE, null, ex);
        event.respond("An error occureed");
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (IOException ex) {
            PokeBot.getLogger().log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.microsoft.azure.shortcuts.resources.samples.StorageAccountsSample.java

public static void test(Subscription subscription) throws Exception {
    String newStorageAccountName = "store" + String.valueOf(System.currentTimeMillis());
    String newGroupName = "testgroup";

    // Provision a new storage account with minimum parameters
    StorageAccount storageAccount = subscription.storageAccounts().define(newStorageAccountName)
            .withRegion(Region.US_WEST).withNewResourceGroup().create();

    printStorageAccount(storageAccount);

    String groupName = storageAccount.resourceGroup();

    // Listing all storage accounts
    Map<String, StorageAccount> storageAccounts = subscription.storageAccounts().asMap();
    System.out.println(/*from www . ja v a  2 s .c o  m*/
            String.format("Storage accounts ids: \n\t%s", StringUtils.join(storageAccounts.keySet(), ",\n\t")));

    // Listing storage accounts in a specific resource group
    storageAccounts = subscription.storageAccounts().asMap(groupName);
    System.out.println(String.format("Storage account ids in group '%s': \n\t%s", groupName,
            StringUtils.join(storageAccounts.keySet(), ",\n\t")));

    // Get info about a specific storage account using its group and name
    storageAccount = subscription.storageAccounts(groupName, newStorageAccountName);
    printStorageAccount(storageAccount);

    // Delete this storage account
    storageAccount.delete();

    // Delete the group
    subscription.resourceGroups().delete(groupName);

    // Provision a test group
    ResourceGroup resourceGroup = subscription.resourceGroups().define(newGroupName).withRegion(Region.US_WEST)
            .create();

    // Provision a new storage account in an existing resource group
    storageAccount = subscription.storageAccounts().define(newStorageAccountName).withRegion(Region.US_WEST)
            .withExistingResourceGroup(newGroupName).withAccountType(AccountType.StandardLRS).create();

    printStorageAccount(storageAccount);

    // Delete the storage account
    storageAccount.delete();

    // Delete the groups
    resourceGroup.delete();
}

From source file:com.agileEAP.module.cache.memcached.SpyMemcachedClient.java

/**
 * GetBulk, ??./*from   ww  w .j a va2  s  . c om*/
 */
public <T> Map<String, T> getBulk(Collection<String> keys) {
    try {
        return (Map<String, T>) memcachedClient.getBulk(keys);
    } catch (RuntimeException e) {
        handleException(e, StringUtils.join(keys, ","));
        return null;
    }
}