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:io.wcm.devops.conga.generator.plugins.fileheader.AbstractFileHeader.java

@Override
public final Void apply(FileContext file, FileHeaderContext context) {
    String lineBreak = StringUtils.defaultString(getLineBreak());
    try {//from  w ww  .j  a  v  a  2  s . c o  m
        String content = FileUtils.readFileToString(file.getFile(), file.getCharset());

        List<String> sanitizedCommentLines;
        if (context.getCommentLines() == null) {
            sanitizedCommentLines = ImmutableList.of();
        } else {
            sanitizedCommentLines = context.getCommentLines().stream().map(line -> sanitizeComment(line))
                    .filter(line -> line != null)
                    .map(line -> StringUtils.defaultString(getCommentLinePrefix()) + line + lineBreak)
                    .collect(Collectors.toList());
        }

        int insertPosition = getInsertPosition(content);

        content = StringUtils.substring(content, 0, insertPosition)
                + StringUtils.defaultString(getCommentBlockStart())
                + StringUtils.join(sanitizedCommentLines, "") + StringUtils.defaultString(getCommentBlockEnd())
                + StringUtils.defaultString(getBlockSuffix()) + StringUtils.substring(content, insertPosition);

        file.getFile().delete();
        FileUtils.write(file.getFile(), content, file.getCharset());
    } catch (IOException ex) {
        throw new GeneratorException("Unable to add file header to " + FileUtil.getCanonicalPath(file), ex);
    }
    return null;
}

From source file:de.chludwig.websec.saml2sp.security.ApplicationUser.java

@Override
public String toString() {
    return "ApplicationUser{" + "userId='" + userId + '\'' + ", userName='" + userName + '\'' + ", roles={"
            + StringUtils.join(roles, ", ") + '}' + '}';
}

From source file:ca.uhn.fhir.rest.method.HttpGetClientInvocation.java

public HttpGetClientInvocation(FhirContext theContext, String... theUrlFragments) {
    super(theContext);
    myParameters = new HashMap<String, List<String>>();
    myUrlPath = StringUtils.join(theUrlFragments, '/');
}

From source file:com.github.rvesse.airline.examples.io.ColorDemo.java

@Override
public int run() {
    if (this.hardReset) {
        System.out.println(AnsiControlCodes.getGraphicsResetCode());
        System.out.println("Your terminal was reset");
        return 0;
    }//w  w  w . j  a v  a2  s  . co m

    ColorizedOutputStream<T> output = openOutputStream();
    try {
        System.out.println("If your terminal supports it the subsequent output will be colorized");

        String text = StringUtils.join(args, " ");
        if (StringUtils.isEmpty(text)) {
            text = "Sample text";
        }

        T[] colors = getColors();
        System.out.println("Demoing " + colors.length + " available colours");
        for (T color : colors) {
            // This text will appear in your terminal default colour
            System.out.format("Color %s:\n", color.toString());

            // Set the colour
            if (this.background) {
                output.setBackgroundColor(color);
            } else {
                output.setForegroundColor(color);
            }

            // Anything we write now will be appropriately colorized
            output.print(text);

            // Reset back to default color
            if (this.background) {
                output.resetBackgroundColor();
            } else {
                output.resetForegroundColor();
            }
            output.println();
        }

        return 0;
    } finally {
        // Just in case we hit an error remember to reset the color
        // appropriately
        if (this.background) {
            output.resetBackgroundColor();
        } else {
            output.resetForegroundColor();
        }
        System.out.println();
        output.close();
    }
}

From source file:com.thoughtworks.go.config.exceptions.EntityType.java

public String deleteSuccessful(List<?> ids) {
    return format("%ss %ss '%s' were deleted successfully!", StringUtils.capitalize(this.entityType),
            this.nameOrId.descriptor, StringUtils.join(ids, ", "));
}

From source file:net.ontopia.persistence.rdbms.MySqlSQLProducer.java

@Override
protected List<String> createStatement(Table table, List<String> statements) throws IOException {
    StringBuilder sb = new StringBuilder();
    String[] pkeys = table.getPrimaryKeys();
    // Create table
    sb.append("create table ").append(table.getName()).append(" (\n");
    Iterator<Column> iter = table.getColumns().iterator();
    while (iter.hasNext()) {
        Column col = iter.next();// ww w . j a  v a 2  s.  c  om
        DataType type = project.getDataTypeByName(col.getType(), platforms);
        sb.append("  ").append(col.getName()).append("  ");
        if (type.getType().equals("varchar") && Integer.parseInt(type.getSize()) > 255) {
            sb.append("TEXT");
        } else {
            sb.append(type.getType()).append((type.isVariable() ? "(" + type.getSize() + ")" : ""));
        }
        sb.append((!col.isNullable() ? " not null" : ""));
        if (pkeys != null || iter.hasNext())
            sb.append(',');
        sb.append('\n');

    }
    // Primary keys
    if (pkeys != null) {
        sb.append("  constraint " + table.getName() + "_pkey primary key (")
                .append(StringUtils.join(pkeys, ", ")).append(')').append('\n');
    }

    statements.add(sb.append(") TYPE = InnoDB\n").toString());
    return statements;
}

From source file:eu.delving.x3ml.TestBase.java

@Test
public void testReadWrite() throws IOException {
    String xml = engine("/base/base.x3ml").toString();
    String[] lines = xml.split("\n");
    List<String> serialized = new ArrayList<String>();
    List<String> originalLines = IOUtils.readLines(resource("/base/base.x3ml"));
    List<String> original = new ArrayList<String>();
    boolean ignore = false;
    int index = 0;
    for (String orig : originalLines) {
        orig = orig.trim();//from w  w w.  j a v  a2 s.  co  m
        if (orig.startsWith("<!--"))
            continue;
        if (orig.startsWith("<comments") || orig.startsWith("<info"))
            ignore = true;
        if (!ignore) {
            serialized.add(lines[index].trim());
            original.add(orig);
            index++;
        }
        if (orig.startsWith("</comments") || orig.startsWith("</info"))
            ignore = false;
    }
    Assert.assertEquals("Mismatch", StringUtils.join(original, "\n"), StringUtils.join(serialized, "\n"));
}

From source file:net.ontopia.persistence.query.jdo.JDOSetOperation.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    String op;//w ww  . jav  a  2  s  . co m
    switch (operator) {
    case UNION:
        op = ") union (";
        break;
    case UNION_ALL:
        op = ") union all (";
        break;
    case INTERSECT:
        op = ") intersect (";
        break;
    case INTERSECT_ALL:
        op = ") intersect all (";
        break;
    case EXCEPT:
        op = ") except (";
        break;
    case EXCEPT_ALL:
        op = ") except all (";
        break;
    default:
        throw new OntopiaRuntimeException("Unsupported set operator: '" + operator + "'");
    }
    sb.append('(');
    sb.append(StringUtils.join(sets, op));
    sb.append(')');
    return sb.toString();
}

From source file:com.creditcloud.ump.model.ump.base.BaseResponse.java

public String chkString() {
    Map<String, String> values = MessageUtils.getFieldValuesMap(this);
    Set<String> sets = new TreeSet<>();

    for (String key : values.keySet()) {
        String value = values.get(key);
        if (!key.equals("sign") && !key.equals("sign_type") && !key.equals("rspType")) {
            // skip sign and sign_type and rspType field, they are not in checksum string
            if (value != null) {
                sets.add(key + "=" + value);
            }/*from w  ww  . j av a2  s .c om*/
        }
    }

    return StringUtils.join(sets, "&");
}

From source file:com.searchcode.app.service.route.SearchRouteService.java

public SearchResult codeSearch(Request request, Response response) {
    CodeSearcher cs = new CodeSearcher();
    CodeMatcher cm = new CodeMatcher(Singleton.getData());
    SearchcodeLib scl = Singleton.getSearchcodeLib(Singleton.getData());

    if (request.queryParams().contains("q") && !request.queryParams("q").trim().equals(Values.EMPTYSTRING)) {
        String query = request.queryParams("q").trim();

        int page = 0;

        if (request.queryParams().contains("p")) {
            try {
                page = Integer.parseInt(request.queryParams("p"));
                page = page > 19 ? 19 : page;
            } catch (NumberFormatException ex) {
                page = 0;// w  w w.j a v a  2  s  .  c o  m
            }
        }

        String[] repos;
        String[] langs;
        String[] owners;
        String reposFilter = Values.EMPTYSTRING;
        String langsFilter = Values.EMPTYSTRING;
        String ownersFilter = Values.EMPTYSTRING;

        if (request.queryParams().contains("repo")) {
            repos = request.queryParamsValues("repo");

            if (repos.length != 0) {
                List<String> reposList = Arrays.asList(repos).stream()
                        .map((s) -> "reponame:" + QueryParser.escape(s.replace(" ", "_")))
                        .collect(Collectors.toList());

                reposFilter = " && (" + StringUtils.join(reposList, " || ") + ")";
            }
        }

        if (request.queryParams().contains("lan")) {
            langs = request.queryParamsValues("lan");

            if (langs.length != 0) {
                List<String> langsList = Arrays.asList(langs).stream()
                        .map((s) -> "languagename:" + QueryParser.escape(s.replace(" ", "_")))
                        .collect(Collectors.toList());

                langsFilter = " && (" + StringUtils.join(langsList, " || ") + ")";
            }
        }

        if (request.queryParams().contains("own")) {
            owners = request.queryParamsValues("own");

            if (owners.length != 0) {
                List<String> ownersList = Arrays.asList(owners).stream()
                        .map((s) -> "codeowner:" + QueryParser.escape(s.replace(" ", "_")))
                        .collect(Collectors.toList());

                ownersFilter = " && (" + StringUtils.join(ownersList, " || ") + ")";
            }
        }

        // split the query escape it and and it together
        String cleanQueryString = scl.formatQueryString(query);

        SearchResult searchResult = cs.search(cleanQueryString + reposFilter + langsFilter + ownersFilter,
                page);
        searchResult.setCodeResultList(cm.formatResults(searchResult.getCodeResultList(), query, true));

        searchResult.setQuery(query);

        for (String altQuery : scl.generateAltQueries(query)) {
            searchResult.addAltQuery(altQuery);
        }

        // Null out code as it isnt required and there is no point in bloating our ajax requests
        for (CodeResult codeSearchResult : searchResult.getCodeResultList()) {
            codeSearchResult.setCode(null);
        }

        return searchResult;
    }

    return null;
}