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.fengduo.bee.commons.core.lang.ArrayUtils.java

public static void main(String[] args) {
    String[] s = { "zxc", null, "msunmss", "" };
    s = ArrayUtils.replaceNullElement(s, new IHandle<String>() {

        @Override//from   w w  w  .jav  a2 s  .c o  m
        public boolean isNull(String obj) {
            return obj == null || StringUtils.isEmpty((String) obj);
        }

        @Override
        public String init(Class<String> clazz) {
            if (clazz.equals(String.class)) {
                return (String) new String("wu");
            }
            try {
                return clazz.newInstance();
            } catch (InstantiationException e) {
                System.out.println(e.getMessage());
            } catch (IllegalAccessException e) {
                System.out.println(e.getMessage());
            }
            System.out.println("replaceNullElement: init error");
            return null;
        }
    });
    System.out.println(StringUtils.join(s, ";"));

    String[] a = removeBlankElement(new String[] { "1", null, "2", "", "3" });
    for (int i = 0, j = a.length; i < j; i++) {
        System.out.println(a[i]);
    }

    String[] t = null;
    System.out.println("Orignal:" + org.apache.commons.lang.ArrayUtils.toString(t, "NULL"));
    System.out.println("shift:" + org.apache.commons.lang.ArrayUtils.toString(shift(t, "a"), "NULL"));
    System.out.println("unshift:" + org.apache.commons.lang.ArrayUtils.toString(unshift(t, "a"), "NULL"));
    System.out.println("add(-1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, -1, "a"), "NULL"));
    System.out.println("add(0):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length+1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 1, "a"), "NULL"));
    t = new String[] { "1", null, "2", "", "3" };
    System.out.println("Orignal:" + org.apache.commons.lang.ArrayUtils.toString(t, "NULL"));
    System.out.println("shift:" + org.apache.commons.lang.ArrayUtils.toString(shift(t, "a"), "NULL"));
    System.out.println("unshift:" + org.apache.commons.lang.ArrayUtils.toString(unshift(t, "a"), "NULL"));
    System.out.println("add(-1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, -1, "a"), "NULL"));
    System.out.println("add(0):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 0, "a"), "NULL"));
    System.out.println("add(length+1):" + org.apache.commons.lang.ArrayUtils.toString(add(t, 1, "a"), "NULL"));
}

From source file:com.thinkbiganalytics.spark.datavalidator.Validator.java

public static void main(String[] args) {
    log.info("Running Spark Validator with the following command line args (comma separated):"
            + StringUtils.join(args, ","));

    // Check how many arguments were passed in
    if (args.length < 4) {
        System.out.println("Proper Usage is: <targetDatabase> <entity> <partition> <path-to-policy-file>");
        System.out.println(/*w w w .  j a  va 2s.c  om*/
                "You can optionally add: --hiveConf hive.setting=value --hiveConf hive.other.setting=value");
        System.out.println("You can optionally add: --storageLevel rdd_persistence_level_value");
        System.out.println("You can optionally add: --numPartitions number_of_rdd_partitions");
        System.out.println("You provided " + args.length + " args which are (comma separated): "
                + StringUtils.join(args, ","));
        System.exit(1);
    }
    try {
        ApplicationContext ctx = new AnnotationConfigApplicationContext("com.thinkbiganalytics.spark");
        Validator app = ctx.getBean(Validator.class);
        app.setArguments(args[0], args[1], args[2], args[3]);
        app.addParameters(parseRemainingParameters(args, 4));
        app.doValidate();
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:edu.indiana.d2i.sloan.internal.CreateVMSimulator.java

public static void main(String[] args) {
    CreateVMSimulator simulator = new CreateVMSimulator();

    CommandLineParser parser = new PosixParser();

    try {/*from  www  . j  a v  a2s  .  c  om*/
        CommandLine line = simulator.parseCommandLine(parser, args);

        String imagePath = line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.IMAGE_PATH));
        int vcpu = Integer.parseInt(line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VCPU)));
        int mem = Integer.parseInt(line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.MEM)));

        if (!HypervisorCmdSimulator.resourceExist(imagePath)) {
            logger.error(String.format("Cannot find requested image: %s", imagePath));
            System.exit(ERROR_CODE.get(ERROR_STATE.IMAGE_NOT_EXIST));
        }

        if (!hasEnoughCPUs(vcpu)) {
            logger.error(String.format("Don't have enough cpus, requested %d", vcpu));
            System.exit(ERROR_CODE.get(ERROR_STATE.NOT_ENOUGH_CPU));
        }

        if (!hasEnoughMem(mem)) {
            logger.error(String.format("Don't have enough memory, requested %d", mem));
            System.exit(ERROR_CODE.get(ERROR_STATE.NOT_ENOUGH_MEM));
        }

        String wdir = line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.WORKING_DIR));

        if (HypervisorCmdSimulator.resourceExist(wdir)) {
            logger.error(String.format("Working directory %s already exists ", wdir));
            System.exit(ERROR_CODE.get(ERROR_STATE.VM_ALREADY_EXIST));
        }

        // copy VM image to working directory
        File imageFile = new File(imagePath);
        FileUtils.copyFile(imageFile, new File(HypervisorCmdSimulator.cleanPath(wdir) + imageFile.getName()));

        // write state as property file so that we can query later
        Properties prop = new Properties();

        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.IMAGE_PATH), imagePath);
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VCPU), String.valueOf(vcpu));
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.MEM), String.valueOf(mem));
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.WORKING_DIR), wdir);
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VNC_PORT),
                line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VNC_PORT)));
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.SSH_PORT),
                line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.SSH_PORT)));
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.LOGIN_USERNAME),
                line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.LOGIN_USERNAME)));
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.LOGIN_PASSWD),
                line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.LOGIN_PASSWD)));

        // write VM state as shutdown
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_STATE), VMState.SHUTDOWN.toString());
        // write VM mode as undefined
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_MODE), VMMode.NOT_DEFINED.toString());

        prop.store(
                new FileOutputStream(new File(
                        HypervisorCmdSimulator.cleanPath(wdir) + HypervisorCmdSimulator.VM_INFO_FILE_NAME)),
                "");

        // do other related settings
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.error(e.getMessage());
        }

        // success
        System.exit(0);

    } catch (ParseException e) {
        logger.error(String.format("Cannot parse input arguments: %s%n, expected:%n%s",
                StringUtils.join(args, " "), simulator.getUsage(100, "", 5, 5, "")));

        System.exit(ERROR_CODE.get(ERROR_STATE.INVALID_INPUT_ARGS));
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        System.exit(ERROR_CODE.get(ERROR_STATE.IO_ERR));
    }
}

From source file:de.codesourcery.springmass.springmass.SimulationParamsBuilder.java

public static void main(String[] args) {
    final List<SimulationParameter> parameters = new SimulationParamsBuilder().getParameters();
    System.out.println(StringUtils.join(parameters, "\n"));
}

From source file:com.hortonworks.historian.model.HistorianModelGenerator.java

public static void main(String[] args) throws Exception {
    HistorianModelGenerator HistorianDataModelGenerator = new HistorianModelGenerator();
    System.out.println("HistorianDataModelAsJSON = " + HistorianDataModelGenerator.getModelAsJson());

    TypesDef typesDef = HistorianDataModelGenerator.getTypesDef();
    for (EnumTypeDefinition enumType : typesDef.enumTypesAsJavaList()) {
        System.out.println(String.format("%s(%s) - values %s", enumType.name, EnumType.class.getSimpleName(),
                Arrays.toString(enumType.enumValues)));
    }/*from w  ww  .j av a  2 s .co  m*/
    for (StructTypeDefinition structType : typesDef.structTypesAsJavaList()) {
        System.out.println(String.format("%s(%s) - attributes %s", structType.typeName,
                StructType.class.getSimpleName(), Arrays.toString(structType.attributeDefinitions)));
    }
    for (HierarchicalTypeDefinition<ClassType> classType : typesDef.classTypesAsJavaList()) {
        System.out.println(String.format("%s(%s) - super types [%s] - attributes %s", classType.typeName,
                ClassType.class.getSimpleName(), StringUtils.join(classType.superTypes, ","),
                Arrays.toString(classType.attributeDefinitions)));
    }
    for (HierarchicalTypeDefinition<TraitType> traitType : typesDef.traitTypesAsJavaList()) {
        System.out.println(String.format("%s(%s) - %s", traitType.typeName, TraitType.class.getSimpleName(),
                Arrays.toString(traitType.attributeDefinitions)));
    }
}

From source file:com.ewcms.publication.freemarker.directive.UriFormat.java

/**
 * ??????/*from ww w  . jav  a  2  s .  c o  m*/
 * 
 * @param path
 * @return
 */
public static String formatChannelPath(String path) {
    String[] s = StringUtils.split(path, "/");
    return StringUtils.join(s, "/");
}

From source file:mongodb.MongoUtils.java

public static Object getValue(Document doc, String attribut) {
    if (!attribut.contains("."))
        return doc.get(attribut);
    else {/*from w ww  .ja  v a 2 s .  c  o  m*/
        //System.out.println("Attribut a splitter : ["+attribut+"]");
        String[] parties = attribut.split("\\.");
        Document nested = (Document) doc.get(parties[0]);

        return getValue(nested, StringUtils.join(Arrays.copyOfRange(parties, 1, parties.length), "."));
    }
}

From source file:com.linkedin.pinot.common.utils.StringUtil.java

public static String join(String seperator, String... keys) {
    return StringUtils.join(keys, seperator);
}

From source file:gov.nih.nci.caintegrator.application.util.CSVUtil.java

public static void renderCSV(HttpServletResponse response, List<List> csv) {
    PrintWriter out = null;//from www .  ja  v a  2 s .c  om

    long randomness = System.currentTimeMillis();
    response.setContentType("application/csv");
    response.setHeader("Content-Disposition", "attachment; filename=report_" + randomness + ".csv");

    try {
        for (List row : csv) {

            out = response.getWriter();
            out.write(StringUtils.join(row.toArray(), ",") + "\r\n");
            out.flush();
        }
    } catch (Exception e) {
        out.write("error generating report");
    }
}

From source file:com.ms.commons.log.LoggerHelper.java

private static String leftpad(int level, String msg) {
    String prefix = StringUtils.repeat("\t", level);
    String[] lines = StringUtils.split(msg, newline);
    for (int i = 0; i < lines.length; i++) {
        lines[i] = prefix + lines[i];/*  w  w w . j a  va 2s  . c  o  m*/
    }
    return StringUtils.join(lines, newline);
}