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.conversantmedia.mapreduce.tool.RunJobTest.java

@Test
public void testScanPackages_SystemProperty() {
    String packages = "package4,package5,package6";
    System.setProperty(RunJob.SYSPROP_DRIVER_SCAN_PACKAGES, packages);

    try {/*from  w w w .ja va  2  s  . c  o  m*/
        String[] result = RunJob.getBasePackagesToScanForDrivers();

        assertNotNull(result);
        assertThat(result.length, equalTo(3));
        assertThat(StringUtils.join(result, ","), equalTo(packages));

    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:net.easymfne.factionsdb.Util.java

/**
 * Convert a time in milliseconds to a user-friendly String format.
 * /*from w  w w.  java2s.  c  o m*/
 * @param time
 *            Number of milliseconds
 * @return User-friendly String
 */
public static String generateTimeString(long time) {
    List<String> timeStrings = new ArrayList<String>();
    long d = TimeUnit.MILLISECONDS.toDays(time);
    time -= TimeUnit.DAYS.toMillis(d);
    long h = TimeUnit.MILLISECONDS.toHours(time);
    time -= TimeUnit.HOURS.toMillis(h);
    long m = TimeUnit.MILLISECONDS.toMinutes(time);
    time -= TimeUnit.MINUTES.toMillis(m);
    long s = TimeUnit.MILLISECONDS.toSeconds(time);

    if (d > 0) {
        timeStrings.add(d + (d == 1 ? " day" : " days"));
    }
    if (h > 0) {
        timeStrings.add(h + (h == 1 ? " hour" : " hours"));
    }
    if (m > 0) {
        timeStrings.add(m + (m == 1 ? " minute" : " minutes"));
    }
    if (s > 0 || timeStrings.size() < 1) {
        timeStrings.add(s + (s == 1 ? " second" : " seconds"));
    }

    return StringUtils.join(timeStrings, ", ");
}

From source file:jp.co.tis.gsp.tools.dba.CsvInsertHandler.java

public void prepare() throws SQLException {
    StringBuilder sb = new StringBuilder("INSERT INTO ");
    sb.append(schema).append(".").append(tableName).append("(").append(StringUtils.join(columns, ','))
            .append(") VALUES (");
    for (int i = 0; i < columns.size(); i++) {
        sb.append("?");
        if (i < columns.size() - 1) {
            sb.append(",");
        }/*w  w w . j a  v a2  s.  co  m*/
    }
    sb.append(")");
    stmt = conn.prepareStatement(sb.toString());
}

From source file:de.iai.ilcd.model.dao.UserGroupDao.java

@SuppressWarnings("unchecked")
public List<Long> getGroupIds(List<Organization> orgs) {
    if (orgs == null || orgs.isEmpty()) {
        return null;
    }//from  www.j  ava2  s  .  c om
    EntityManager em = PersistenceUtil.getEntityManager();

    List<Long> orgIds = new ArrayList<Long>();
    for (Organization o : orgs) {
        orgIds.add(o.getId());
    }

    try {
        return (List<Long>) em.createQuery("SELECT DISTINCT g.id FROM UserGroup g WHERE g.organization.id IN("
                + StringUtils.join(orgIds, ',') + ")").getResultList();
    } catch (Exception e) {
        return null;
    }
}

From source file:com.microsoft.azure.shortcuts.resources.samples.VirtualMachinesSample.java

public static void test(Subscription subscription) throws Exception {
    // Creating a Windows VM
    String deploymentId = String.valueOf(System.currentTimeMillis());
    String groupName = "group" + deploymentId;

    VirtualMachine vmWin = subscription.virtualMachines().define("vm" + deploymentId).withRegion(Region.US_WEST)
            .withNewResourceGroup(groupName).withNewNetwork("net" + deploymentId, "10.0.0.0/28")
            .withPrivateIpAddressDynamic().withNewPublicIpAddress().withAdminUsername("shortcuts")
            .withAdminPassword("Abcd.1234")
            .withLatestImage("MicrosoftWindowsServer", "WindowsServer", "2008-R2-SP1")
            .withSize(Size.Type.BASIC_A1).withNewStorageAccount().withNewDataDisk(100)
            //.withExistingAvailabilitySet(new URI("/subscriptions/9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef/resourceGroups/marcinsrg123/providers/Microsoft.Compute/availabilitySets/marcinsas123"))
            //.withExistingDataDisk("https://vm1455045717874store.blob.core.windows.net/vm1455045717874/disk0.vhd")
            .create();/*from www  .  ja v a 2 s .  c om*/

    printVM(vmWin);

    // Listing all virtual machine ids in a subscription
    Map<String, VirtualMachine> vms = subscription.virtualMachines().asMap();
    System.out.println(String.format("Virtual machines: \n\t%s", StringUtils.join(vms.keySet(), "\n\t")));

    // Adding a Linux VM to the same group and VNet
    VirtualMachine vmLinux = subscription.virtualMachines().define("lx" + deploymentId)
            .withRegion(Region.US_WEST).withExistingResourceGroup(groupName)
            .withExistingNetwork(subscription.networks(groupName, "net" + deploymentId)).withSubnet("subnet1")
            .withPrivateIpAddressDynamic().withNewPublicIpAddress().withAdminUsername("shortcuts")
            .withAdminPassword("Abcd.1234").withLatestImage("Canonical", "UbuntuServer", "14.04.3-LTS")
            .withSize(Size.Type.BASIC_A1).create();

    // Listing vms in a specific group
    Map<String, VirtualMachine> vmsInGroup = subscription.virtualMachines().asMap(groupName);
    System.out
            .println(String.format("Virtual machines: \n\t%s", StringUtils.join(vmsInGroup.keySet(), "\n\t")));

    // Listing virtual machines as objects
    String vmID = null;
    for (VirtualMachine vm : vms.values()) {
        if (vmID == null) {
            vmID = vm.id();
        }
        printVM(vm);
    }

    // Getting a specific virtual machine using its id
    VirtualMachine vm = subscription.virtualMachines(vmID);
    printVM(vm);

    // Getting a specific virtual machine using its group and name
    vm = subscription.virtualMachines(vm.resourceGroup(), vm.name());
    printVM(vm);

    // Restart the VM
    vmWin.restart();

    // Deallocate the VM
    vmWin.deallocate();

    // Delete VM
    vmWin.delete();

    // Delete the group
    subscription.resourceGroups().delete(groupName);
}

From source file:edu.snu.dolphin.dnn.NeuralNetworkDriverParameters.java

/**
 * Converts a list of integer for an input shape to a string.
 * @param dimensionList a list of integers for an input shape.
 * @return a string for an input shape.//from  www  . j a  va 2  s . c  o  m
 */
public static String inputShapeToString(final List<Integer> dimensionList) {
    return StringUtils.join(dimensionList, SHAPE_DELIMITER);
}

From source file:com.github.stagirs.lingvo.syntax.model.items.WordSyntaxItem.java

public static String getType(String word, Form form) {
    List<Attr> res = new ArrayList<Attr>();
    for (Attr a : form.getAttrs()) {
        if (attr2attr.containsKey(a)) {
            a = attr2attr.get(a);/*from w  w w  .  j  av  a  2s  .  c om*/
        }
        if (!significant.contains(a)) {
            continue;
        }
        res.add(a);
    }
    String type = StringUtils.join(res, ",");
    if (form.isStop()) {
        type += "," + word;
    }
    return type;
}

From source file:ips1ap101.lib.core.db.util.DBUtils.java

public static String getConstraintMessageJoin(String message, String identifier) {
    String[] messages = getConstraintMessages(message, identifier);
    if (messages != null && messages.length > 0) {
        return StringUtils.join(messages, "; ");
    }/*from   ww w  .j a v a 2  s .  c o  m*/
    return null;
}

From source file:de.banapple.maven.antlr.SyntaxDiagramMojo.java

public void execute() throws MojoExecutionException {
    getLog().info("outputDirectory: " + outputDirectory);
    getLog().info("grammarFile: " + grammarFile);

    /* create output directory if it not exists */
    File f = outputDirectory;/*www  .  j  a v  a2s.c o  m*/
    if (!f.exists()) {
        f.mkdirs();
    }

    /* create the rule images using antlrworks */
    String[] args = new String[] { "-f", grammarFile.getAbsolutePath(), "-o", outputDirectory.getAbsolutePath(),
            "-sd", "png" };
    try {
        getLog().info("generate diagrams using antlrworks with arguments: " + StringUtils.join(args, " "));
        Console.main(args);
    } catch (Exception e) {
        getLog().error("failed to generate syntax diagrams", e);
        throw new RuntimeException(e);
    }

    /* create an index file */
    createIndex();
}

From source file:com.htmlhifive.tools.wizard.ui.page.tree.LibraryTreeLabelProvider.java

@Override
public String getColumnText(Object element, int columnIndex) {

    if (columnIndex == 0) {
        if (element instanceof LibraryTreeNode) {
            return ((LibraryTreeNode) element).getLabel();
        }/*  w ww  . j av a  2 s . c om*/
        return super.getText(element);
    }

    if (columnIndex == 1) {
        if (element instanceof CategoryNode) {
            CategoryNode categoryNode = (CategoryNode) element;
            return categoryNode.getPathLable();
        }
        if (element instanceof LibraryNode) {
            LibraryNode libraryNode = (LibraryNode) element;
            if (libraryNode.getFileList() != null) {
                return "    " + StringUtils.join(libraryNode.getFileList(), ", ");
            }
        }
    }
    return null;
}