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

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

Introduction

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

Prototype

public static String join(Collection<?> collection, String separator) 

Source Link

Document

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

Usage

From source file:com.codelanx.voxelregen.command.ListCommand.java

@Override
public CommandStatus execute(CommandSender sender, String... args) {
    Set<String> names = this.plugin.getRegionNames();
    if (names.isEmpty()) {
        Lang.sendMessage(sender, VoxelLang.COMMAND_LIST_NONE);
    } else {//  www . j  a va 2 s . com
        Lang.sendMessage(sender, VoxelLang.COMMAND_LIST_FORMAT,
                StringUtils.join(names, VoxelLang.COMMAND_LIST_SEPARATOR.get()));
    }
    return CommandStatus.SUCCESS;
}

From source file:com.swtxml.util.lang.CollectionUtils.java

/**
 * Returns a comma-separated String of the collection toString values
 * alphabetically sorted by value.//ww  w .j a  v a  2 s.c o  m
 */
public static String sortedToString(Collection<?> collection) {
    List<String> strings = new ArrayList<String>(collect(collection, Functions.TO_STRING));
    Collections.sort(strings);
    return StringUtils.join(strings, ", ");
}

From source file:com.linkedin.pinot.common.client.request.filter.TermsFilterQueryTreeConstructor.java

@Override
protected FilterQueryTree doConstructFilter(Object obj) throws Exception {
    final JSONObject json = (JSONObject) obj;

    final Iterator<String> iter = json.keys();
    if (!iter.hasNext()) {
        return null;
    }/*from   w ww. j a va  2 s. c om*/

    final String field = iter.next();

    final JSONObject jsonObj = json.getJSONObject(field);

    final String[] includes = RequestConverter.getStrings(jsonObj.getJSONArray("values"));
    final String[] excludes = RequestConverter.getStrings(jsonObj.getJSONArray("excludes"));

    if (includes.length > 0) {
        Arrays.sort(includes);
        final List<String> rhs = new ArrayList<String>();
        rhs.add(StringUtils.join(includes, "\t\t"));
        return new FilterQueryTree(field, rhs, FilterOperator.IN, null);
    } else {
        Arrays.sort(excludes);
        final List<String> rhs = new ArrayList<String>();
        rhs.add(StringUtils.join(excludes, "\t\t"));
        if (excludes.length == 1) {
            return new FilterQueryTree(field, rhs, FilterOperator.NOT, null);
        } else {
            return new FilterQueryTree(field, rhs, FilterOperator.NOT_IN, null);
        }
    }
}

From source file:com.linkedin.whiteelephant.mapreduce.lib.job.StagedOutputJob.java

/**
 * Creates a job which using a temporary staging location for the output data.
 * The data is only copied to the final output directory on successful completion
 * of the job.  This prevents existing output data from being overwritten unless
 * the job completes successfully./*  w  ww . java2  s. co m*/
 * 
 * @param props Job properties
 * @param jobName Name of the job
 * @param inputPaths Input paths job will be reading from
 * @param stagingLocation Where output of job should be staged
 * @param outputPath The final output location for the data
 * @param log The logger
 * @return The job
 */
public static StagedOutputJob createStagedJob(Properties props, String jobName, List<String> inputPaths,
        String stagingLocation, String outputPath, final Logger log) {
    Configuration config = createConfigurationFromProps(props);

    final StagedOutputJob retVal;
    try {
        retVal = new StagedOutputJob(config, stagingLocation, log);

        retVal.setJobName(jobName);
        retVal.setJarByClass(getCallersClass());
        FileInputFormat.setInputPathFilter(retVal, HiddenFilePathFilter.class);

    } catch (IOException e) {
        log.error("IOException when making a job, wtf?", e);
        throw new RuntimeException(e);
    }

    try {
        FileInputFormat.setInputPaths(retVal, StringUtils.join(inputPaths.iterator(), ","));
    } catch (IOException e) {
        log.error("Unable to set up input paths.", e);
        throw new RuntimeException(e);
    }

    FileOutputFormat.setOutputPath(retVal, new Path(outputPath));

    return retVal;
}

From source file:com.codenjoy.dojo.transport.screen.PlayerScreenUpdateRequest.java

@Override
public String toString() {
    return "PlayerScreenUpdateRequest{" + "asyncContext=" + getAsyncContext() + ", playersToUpdate="
            + StringUtils.join(playersToUpdate, ",") + ", forAllPlayers=" + forAllPlayers + '}';
}

From source file:com.pureinfo.srm.srm2rpms.action.ExportAction.java

public ActionForward executeAction() throws PureException {
    if (BuildInfo.isUpdated()) {
        //0. to get the parameter
        String[] tables = request.getParameterValues("data");
        if (tables == null || tables.length == 0) {
            throw new PureException(PureException.INVALID_REQUEST, "");
        }// w  ww . j  a  va 2 s.  c  om

        try {
            //1. to read database info
            Properties props = DolphinConfigHelper.lookupConnectionProviderCfgByName("Export");
            String sDBName = props.getProperty(DolphinEnvironment.DATABASE);
            String sPassword = props.getProperty(DolphinEnvironment.PASSWORD);
            String sPort = props.getProperty("port");

            //2. to execute command to dump sql script
            String sPath = ClassResourceUtil.mapFullPath("mysqldump.exe", true);
            String sCommand = sPath.substring(1) + " -u root -p" + sPassword + " -P " + sPort
                    + " --compatible=mysql323 " + sDBName;
            sCommand += " " + StringUtils.join(tables, ' ');
            logger.debug("do dump sql script: " + sCommand);

            Process process = Runtime.getRuntime().exec(sCommand);
            InputStream is = process.getInputStream();

            //3. to download
            response.setContentType("application/rpms");
            response.setHeader("Content-Disposition", "attachment; filename=srm-export.rpms");
            OutputStream os = response.getOutputStream();
            IOUtil.transfer(is, os);
            is.close();
            os.close();
        } catch (Exception ex) {
            throw new PureException(0, "dump sql script from school", ex);
        }
    }
    return null;
}

From source file:com.titankingdoms.dev.titanchat.command.defaults.ChatCommand.java

@Override
public void execute(CommandSender sender, Channel channel, String[] args) {
    EndPoint msgSender = plugin.getParticipantManager().getParticipant(sender);
    EndPoint msgRecipient = channel;/* ww w  . j  a v a  2 s  .c o  m*/

    String format = msgRecipient.getConversationFormat();
    String message = StringUtils.join(args, " ");

    ChatProcessEvent event = msgRecipient.processConversation(msgSender, format, message);
    plugin.getServer().getPluginManager().callEvent(event);
}

From source file:com.liferay.jenkins.tools.DurationMatcher.java

protected int parseDuration(String[] optionValues) throws IllegalArgumentException {
    String joinedString = StringUtils.join(optionValues, "");
    String spacedString = StringUtils.join(optionValues, " ");

    try {/*  ww  w. ja va 2 s  .  com*/
        return Integer.parseInt(joinedString);
    } catch (NumberFormatException e) {
        logger.debug("'{}' is not a numeric duration string", spacedString);
    }

    try {
        Duration durationObject = Duration.parse(joinedString);

        return (int) durationObject.toMillis();
    } catch (DateTimeParseException e) {
        logger.debug("'{}' is not an ISO-8601 duration string", spacedString);
    }

    try {
        String textDurationString = parseTextDuration(optionValues);

        Duration durationObject = Duration.parse(textDurationString);

        return (int) durationObject.toMillis();
    } catch (DateTimeParseException e) {
        logger.debug("'{}' is not a text duration string", spacedString);
    }

    throw new IllegalArgumentException("Unable to parse duration string '" + spacedString + "'");
}

From source file:com.cognifide.slice.core.internal.execution.ExecutionContextStackImpl.java

private String joinPath(final Object... args) {
    return StringUtils.join(args, "/").replace("//", "/");
}

From source file:com.uber.stream.kafka.mirrormaker.common.utils.C3QueryUtils.java

public static Map<String, TopicWorkload> retrieveTopicInRate(long timeInMs, long windowInMs, String c3Host,
        int c3Port, String kafkaCluster, List<String> topics) throws IOException {
    Map<String, TopicWorkload> workloads = new HashMap<>();
    if (c3Port == 0) {
        return workloads;
    }/*from   w ww .  j  a  v  a 2 s.  com*/
    long endSec = (timeInMs / 1000 - DEFAULT_QUERY_MINIMUM_END_TO_CURRENT_SEC) / 600 * 600;
    long startSec = endSec - windowInMs / 1000L;
    LOGGER.info("Retrieve workload for [{}, {}] for {} for {} topics", startSec, endSec, kafkaCluster,
            topics.size());
    long ts1 = System.currentTimeMillis();
    for (int i = 0; i < topics.size(); i += DEFAULT_BATCH_TOPICS) {
        StringBuilder query = new StringBuilder();
        query.append("startSec=");
        query.append(startSec);
        query.append("&endSec=");
        query.append(endSec);
        query.append("&tier=");
        query.append(kafkaCluster);
        query.append("&topicList=");
        List<String> batch = topics.subList(i, Math.min(i + DEFAULT_BATCH_TOPICS, topics.size()));
        query.append(StringUtils.join(batch, ","));
        String jsonStr = makeQuery(c3Host, c3Port, query.toString());
        extractJsonResults(jsonStr, batch, workloads);
    }
    LOGGER.info("took {} ms to retrieve {} topics for {}", System.currentTimeMillis() - ts1, topics.size(),
            kafkaCluster);
    return workloads;
}