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:com.hulaki.smtp.api.ServerStatusRequest.java

public ServerStatusRequest(String requestBody) throws ApiProtocolException {
    super(requestBody, ApiCommand.SERVER_STATUS);
    String[] tokens = requestBody.split(" ");
    if (tokens.length != 2) {
        throw new ApiProtocolException("Server status should be in format SERVER_STATUS ["
                + StringUtils.join(ServerName.values(), '|') + "]");
    }// w  w  w .j  a  v a 2  s.c om
    serverName = ServerName.parse(tokens[1].trim());
}

From source file:com.github.guava.JoinerPractice.java

@Test
public void test() {
    String join = Joiner.on('|').skipNulls().join(str);
    Assert.assertEquals(StringUtils.join(str, '|'), join);
}

From source file:com.thoughtworks.go.helper.TestStreamConsumer.java

public String output() {
    return StringUtils.join(lines, "\n");
}

From source file:ca.umontreal.iro.rxnav.RxClass.java

/**
 * Get all classes for each specified class type.
 * <p/>//from   w w w.  j  av a 2  s  .  c o  m
 * http://rxnav.nlm.nih.gov/RxNormAPIs.html#uLink=RxClass_REST_getAllClasses
 *
 * @param classTypes
 * @return
 * @throws java.io.IOException
 * @throws org.json.JSONException
 */
public JSONArray allClasses(String... classTypes) throws IOException, JSONException {
    if (classTypes.length > 0)
        return get("allClasses", new BasicNameValuePair("classTypes", StringUtils.join(classTypes, " ")))
                .getJSONObject("rxclassMinConceptList").getJSONArray("rxclassMinConcept");

    return get("allClasses").getJSONObject("rxclassMinConceptList").getJSONArray("rxclassMinConcept");
}

From source file:com.microsoft.azure.shortcuts.services.samples.OSImagesSample.java

public static void test(Azure azure) throws Exception {
    final String imageName = "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-12_04_5_LTS-amd64-server-20150413-en-us-30GB";

    // List the OS images
    Map<String, OSImage> osImages = azure.osImages().asMap();
    Set<String> osImageNames = osImages.keySet();

    System.out.println("Available OS images: \n\t" + StringUtils.join(osImageNames, ",\n\t"));

    // Get information about a specific OS image
    OSImage osImage = azure.osImages(imageName);
    printOsImage(osImage);/*from   w  w  w.  ja va  2s .c om*/
}

From source file:com.lyncode.jtwig.functions.internal.list.Join.java

@Override
public Object execute(Object... arguments) throws FunctionException {
    if (arguments.length < 1)
        throw new FunctionException("Requires at least a list as argument");

    String separator = "";
    if (arguments.length == 2)
        separator = arguments[1].toString();

    if (arguments[0] == null)
        return "";
    else if (arguments[0] instanceof Iterable)
        return StringUtils.join((Iterable) arguments[0], separator);
    else if (arguments[0].getClass().isArray())
        return StringUtils.join((Object[]) arguments[0], separator);
    else//from  w  ww . j  a  v a  2s .co  m
        throw new FunctionException("First arguments must be a list or an array.");
}

From source file:com.yahoo.rdl.maven.ProcessRunner.java

public String run(List<String> command, ProcessBuilder processBuilder) throws IOException {
    Process process = processBuilder.start();
    try (StreamConsumer stdout = new StreamConsumer(process.getInputStream()).start()) {
        try (StreamConsumer stderr = new StreamConsumer(process.getErrorStream()).start()) {
            if (!process.waitFor(10, TimeUnit.SECONDS)) {
                throw new IOException("Process took longer than 10 seconds to execute: " + command);
            }/*  w  ww  .  ja  v a2 s  .c o  m*/
            if (process.exitValue() != 0) {
                String s = stderr.getContents();
                throw new IOException("command '" + StringUtils.join(command, " ") + "' produced error: " + s);
            }
        }
        return stdout.getContents();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }

}

From source file:com.thoughtworks.go.util.CsvRow.java

public String toString() {
    StringBuilder sb = new StringBuilder();
    Set<String> fields = fields();
    sb.append(StringUtils.join(fields, ",")).append("\n");
    sb.append(toString(fields)).append("\n");
    return sb.toString();
}

From source file:com.netflix.dyno.contrib.consul.ConsulHelper.java

public static Map<String, String> getMetadata(List<String> tags) {
    LinkedHashMap<String, String> metadata = new LinkedHashMap<>();
    if (tags != null) {
        for (String tag : tags) {
            String[] parts = StringUtils.split(tag, "=");
            switch (parts.length) {
            case 0:
                break;
            case 1:
                metadata.put(parts[0], parts[0]);
                break;
            case 2:
                metadata.put(parts[0], parts[1]);
                break;
            default:
                String[] end = Arrays.copyOfRange(parts, 1, parts.length);
                metadata.put(parts[0], StringUtils.join(end, "="));
                break;
            }/*from   w  w  w  . ja  va2  s.  c om*/

        }
    }

    return metadata;
}

From source file:dk.dma.ais.sentence.SentenceException.java

public SentenceException(String msg, Deque<String> sentenceTrace) {
    super(msg + "\nSentence trace:\n---\n" + StringUtils.join(sentenceTrace, "\n") + "\n---\n");
    this.sentenceTrace = sentenceTrace;
}