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:controllers.FeaturedShortcuts.java

private static Call createForwardUrl(ShortcutRequest request, boolean crossover) {
    List<String> params = new ArrayList<>();
    params.add("crossover=" + (crossover ? "true" : "false"));
    for (String station : request.getFroms(crossover)) {
        params.add("from[]=" + station);
    }//  w ww.  j  a va2  s.c o m
    for (String station : request.getTos(crossover)) {
        params.add("to[]=" + station);
    }
    String url = "http://" + request().host() + routes.Application.showTimetable().url() + "?"
            + StringUtils.join(params, "&");
    return new play.api.mvc.Call("GET", url);
}

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

public static String joinForDisplay(final Collection<?> objects) {
    return StringUtils.join(objects, " | ").trim();
}

From source file:cc.sion.core.utils.Collections3.java

/**
 * ?Collection(toString())String,  separator
 *//*from w  w w. j  a va 2 s  .com*/
public static String convertToString(final Collection collection, final String separator) {
    return StringUtils.join(collection, separator);
}

From source file:com.l2jfree.sql.L2DataSourceMySQL.java

@Override
public void optimize() throws SQLException {
    Connection con = null;/*from  w ww .jav  a  2 s. com*/
    try {
        con = getConnection();

        final Statement st = con.createStatement();

        final ArrayList<String> tables = new ArrayList<String>();
        {
            final ResultSet rs = st.executeQuery("SHOW FULL TABLES");

            while (rs.next()) {
                final String tableType = rs.getString(2/*"Table_type"*/);

                if (tableType.equals("VIEW"))
                    continue;

                tables.add(rs.getString(1));
            }

            rs.close();
        }

        {
            final ResultSet rs = st.executeQuery("CHECK TABLE " + StringUtils.join(tables, ","));

            while (rs.next()) {
                final String table = rs.getString("Table");
                final String msgType = rs.getString("Msg_type");
                final String msgText = rs.getString("Msg_text");

                if (msgType.equals("status"))
                    if (msgText.equals("OK"))
                        continue;

                _log.warn("TableOptimizer: CHECK TABLE " + table + ": " + msgType + " -> " + msgText);
            }

            rs.close();

            _log.info("TableOptimizer: Database tables have been checked.");
        }

        {
            final ResultSet rs = st.executeQuery("ANALYZE TABLE " + StringUtils.join(tables, ","));

            while (rs.next()) {
                final String table = rs.getString("Table");
                final String msgType = rs.getString("Msg_type");
                final String msgText = rs.getString("Msg_text");

                if (msgType.equals("status"))
                    if (msgText.equals("OK") || msgText.equals("Table is already up to date"))
                        continue;

                _log.warn("TableOptimizer: ANALYZE TABLE " + table + ": " + msgType + " -> " + msgText);
            }

            rs.close();

            _log.info("TableOptimizer: Database tables have been analyzed.");
        }

        {
            final ResultSet rs = st.executeQuery("OPTIMIZE TABLE " + StringUtils.join(tables, ","));

            while (rs.next()) {
                final String table = rs.getString("Table");
                final String msgType = rs.getString("Msg_type");
                final String msgText = rs.getString("Msg_text");

                if (msgType.equals("status"))
                    if (msgText.equals("OK") || msgText.equals("Table is already up to date"))
                        continue;

                if (msgType.equals("note"))
                    if (msgText.equals("Table does not support optimize, doing recreate + analyze instead"))
                        continue;

                _log.warn("TableOptimizer: OPTIMIZE TABLE " + table + ": " + msgType + " -> " + msgText);
            }

            rs.close();

            _log.info("TableOptimizer: Database tables have been optimized.");
        }

        st.close();
    } finally {
        L2Database.close(con);
    }
}

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

@Test
public void testDimension() {
    X3MLEngine engine = engine("/rijks/01-dimension.x3ml");
    X3MLEngine.Output output = engine.execute(document("/rijks/rijks.xml"),
            policy("/rijks/01-dimension-policy.xml"));
    String[] mappingResult = output.toStringArray();
    String[] expectedResult = xmlToNTriples("/rijks/01-dimension-rdf.xml");
    List<String> diff = compareNTriples(expectedResult, mappingResult);
    assertTrue("\n" + StringUtils.join(diff, "\n") + "\n", errorFree(diff));
}

From source file:com.eryansky.common.utils.collections.Collections3.java

/**
 * ?Collection(toString())String,  separator
 *//*from ww  w  .ja  v a 2s  . c o m*/
public static String convertToString(@SuppressWarnings("rawtypes") final Collection collection,
        final String separator) {
    return StringUtils.join(collection, separator);
}

From source file:com.synopsys.integration.test.tool.TestLogger.java

public String getOutputString() {
    return StringUtils.join(outputList, System.lineSeparator());
}

From source file:com.cnksi.core.tools.utils.Collections3.java

/**
 * ?Collection(toString())String,  separator
 *//*from  w w w  .j  av a 2  s  . c o  m*/
public static String convertToString(final Collection collection, final String separator) {

    return StringUtils.join(collection, separator);
}

From source file:io.github.autsia.crowly.services.social.impl.TwitterSocialEndpoint.java

@Override
public List<Mention> gatherMentions(Campaign campaign) {
    List<Mention> result = new ArrayList<>();
    String language = campaign.getLanguages().iterator().next();
    GeoCode geoCode = geoLocationService
            .convertCoordinatesToGeoCode(campaign.getLocations().values().iterator().next());
    SearchParameters searchParameters = new SearchParameters(
            StringUtils.join(campaign.getKeywords().toArray(), SEPARATOR)).lang(language).geoCode(geoCode);
    SearchResults searchResults = twitter.searchOperations().search(searchParameters);
    for (Tweet tweet : searchResults.getTweets()) {
        String text = tweet.getText();
        Pair<Sentiment, Float> sentiment = sentimentAnalyzer.analyze(text);
        if (sentiment.getLeft().equals(campaign.getSentiment())
                && sentiment.getRight() > campaign.getThreshold()) {
            result.add(buildMention(campaign, tweet, text));
        }/*from w w  w .j a  va2s .co  m*/
    }
    return result;
}

From source file:flpitu88.web.backend.psicoweb.config.Jwt.java

/**
 * Static method to decode a JSON Web Token
 *
 * @param token Token to decode//  w w  w.j  a  v a2 s  . c o m
 * @param key Key used for the signature
 * @param verify True if you want to verify the signature
 *
 * @return payload
 *
 * @throws IllegalStateException
 * @throws IllegalArgumentException
 * @throws VerifyException
 * @throws NoSuchAlgorithmException
 * @throws UnsupportedEncodingException
 * @throws InvalidKeyException
 * @throws AlgorithmException
 */
public static Map<String, Object> decode(String token, String key, Boolean verify)
        throws IllegalStateException, VerifyException, IllegalArgumentException, NoSuchAlgorithmException,
        UnsupportedEncodingException, InvalidKeyException, AlgorithmException {
    if (token == null || token.length() == 0) {
        throw new IllegalStateException("Token not set");
    }
    // Check key
    if (key == null || key.length() == 0) {
        throw new IllegalArgumentException("Key cannot be null or empty");
    }

    String[] segments = StringUtils.split(token, ".");
    if (segments.length != 3) {
        throw new IllegalStateException("Bad number of segments: " + segments.length);
    }

    // All segment should be base64
    String headerSeg = segments[0];
    String payloadSeg = segments[1];
    String signatureSeg = segments[2];

    Type stringObjectMap = new TypeToken<HashMap<String, Object>>() {
    }.getType();
    Gson gson = new Gson();
    HashMap<String, Object> header = gson.fromJson(base64Decode(headerSeg), stringObjectMap);
    HashMap<String, Object> payload = gson.fromJson(base64Decode(payloadSeg), stringObjectMap);

    if (verify) {
        Algorithm algorithm = getAlgorithm(header.get("alg").toString());

        // Verify signature. `sign` will return base64 String
        String signinInput = StringUtils.join(new String[] { headerSeg, payloadSeg }, ".");
        if (!verify(signinInput, key, algorithm.getValue(), signatureSeg)) {
            throw new VerifyException("Bad signature");
        }
    }

    return payload;
}