Example usage for java.lang String join

List of usage examples for java.lang String join

Introduction

In this page you can find the example usage for java.lang String join.

Prototype

public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) 

Source Link

Document

Returns a new String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter .

Usage

From source file:org.eclipse.hono.service.metric.Metrics.java

/**
 * Merge the given address parts as a full string, separated by '.'.
 * @param parts The address parts//from  www.j  a va2s  . co m
 * @return The full address, separated by points
 */
protected String mergeAsMetric(final String... parts) {
    return String.join(".", parts);
}

From source file:io.github.retz.protocol.data.Application.java

@Override
public String toString() {
    String maybeUser = "";
    if (user.isPresent()) {
        maybeUser = "user=" + user.get();
    }/*from   w w w . j a  va 2 s.c  o  m*/
    String enabledStr = "";
    if (!enabled) {
        enabledStr = "(disabled)";
    }
    return String.format("Application%s name=%s: owner=%s %s container=%s: files=%s/%s", enabledStr, getAppid(),
            owner, maybeUser, container().getClass().getSimpleName(), String.join(",", getFiles()),
            String.join(",", getLargeFiles()));
}

From source file:net.sf.jabref.sql.SQLUtil.java

/**
 * Generates DML specifying table columns and their datatypes. The output of this routine should be used within a
 * CREATE TABLE statement./*from  w w  w  .  j  a  va  2s .  c om*/
 *
 * @param fields   Contains unique field names
 * @param datatype Specifies the SQL data type that the fields should take on.
 * @return The SQL code to be included in a CREATE TABLE statement.
 */
public static String fieldsAsCols(List<String> fields, String datatype) {
    List<String> newFields = new ArrayList<>();
    for (String field1 : fields) {
        StringBuilder field = new StringBuilder(field1);
        if (SQLUtil.RESERVED_DB_WORDS.contains(field.toString())) {
            field.append('_');
        }
        field.append(datatype);
        newFields.add(field.toString());
    }
    return String.join(", ", newFields);
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.local.debian.LocalDebianServiceProvider.java

@Override
public RemoteAction clean(DeploymentDetails details, SpinnakerRuntimeSettings runtimeSettings) {
    String uninstallArtifacts = String.join("\n",
            getServices().stream().filter(s -> s != null && runtimeSettings.getServiceSettings(s).getEnabled())
                    .map(s -> ((LocalDebianService) s).uninstallArtifactCommand())
                    .collect(Collectors.toList()));

    Map<String, String> bindings = new HashMap<>();
    TemplatedResource resource = new JarResource("/debian/uninstall.sh");
    bindings.put("uninstall-artifacts", uninstallArtifacts);

    return new RemoteAction().setScript(resource.setBindings(bindings).toString()).setAutoRun(true)
            .setScriptDescription("This script apt-get purges all spinnaker components & deletes their config");
}

From source file:io.github.retz.executor.FileManager.java

private static void fetchHDFSFile(String file, String dest) throws IOException {
    LOG.debug("Downloading {} to {} as HDFS file", file, dest);
    // TODO: make 'hadoop' command arbitrarily specifiable, but given that mesos-agent (slave) can fetch hdfs:// files, it should be also available, too
    String[] hadoopCmd = { "hadoop", "fs", "-copyToLocal", file, dest };
    LOG.debug("Command: {}", String.join(" ", hadoopCmd));
    ProcessBuilder pb = new ProcessBuilder();
    pb.command(hadoopCmd).inheritIO();/*  w  ww.j  av a 2 s. com*/

    Process p = pb.start();
    while (true) {
        try {
            int result = p.waitFor();
            if (result != 0) {
                LOG.error("Downloading {} failed: {}", file, result);
            } else {
                LOG.info("Download finished: {}", file);
            }
            return;
        } catch (InterruptedException e) {
            LOG.error("Download process interrupted: {}", e.getMessage()); // TODO: debug?
        }
    }
}

From source file:sample.fa.ScriptRunnerApplication.java

void createGUI() {
    Box buttonBox = Box.createHorizontalBox();

    JButton loadButton = new JButton("Load");
    loadButton.addActionListener(this::loadScript);
    buttonBox.add(loadButton);/*from  w w w .jav a2  s . c o m*/

    JButton saveButton = new JButton("Save");
    saveButton.addActionListener(this::saveScript);
    buttonBox.add(saveButton);

    JButton executeButton = new JButton("Execute");
    executeButton.addActionListener(this::executeScript);
    buttonBox.add(executeButton);

    languagesModel = new DefaultComboBoxModel();

    ScriptEngineManager sem = new ScriptEngineManager();
    for (ScriptEngineFactory sef : sem.getEngineFactories()) {
        languagesModel.addElement(sef.getScriptEngine());
    }

    JComboBox<ScriptEngine> languagesCombo = new JComboBox<>(languagesModel);
    JLabel languageLabel = new JLabel();
    languagesCombo.setRenderer((JList<? extends ScriptEngine> list, ScriptEngine se, int index,
            boolean isSelected, boolean cellHasFocus) -> {
        ScriptEngineFactory sef = se.getFactory();
        languageLabel.setText(sef.getEngineName() + " - " + sef.getLanguageName() + " (*."
                + String.join(", *.", sef.getExtensions()) + ")");
        return languageLabel;
    });
    buttonBox.add(Box.createHorizontalGlue());
    buttonBox.add(languagesCombo);

    scriptContents = new JTextArea();
    scriptContents.setRows(8);
    scriptContents.setColumns(40);

    scriptResults = new JTextArea();
    scriptResults.setEditable(false);
    scriptResults.setRows(8);
    scriptResults.setColumns(40);

    JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scriptContents, scriptResults);

    JFrame frame = new JFrame("Script Runner");
    frame.add(buttonBox, BorderLayout.NORTH);
    frame.add(jsp, BorderLayout.CENTER);

    frame.pack();
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    frame.setVisible(true);
}

From source file:de.uni_freiburg.informatik.ultimate.licence_manager.Main.java

private static CommandLine parseArguments(final String[] args, final Options cliOptions) {
    final CommandLineParser cliParser = new DefaultParser();
    try {/*  w ww  .  j a  v  a2  s . com*/
        final CommandLine cmds = cliParser.parse(cliOptions, args);
        if (!cmds.getArgList().isEmpty()) {
            System.err.print("Superfluous arguments: " + String.join(",", cmds.getArgList()));
            return null;
        }
        return cmds;
    } catch (ParseException e) {
        System.err.println("Exception while parsing command line arguments: " + e.getMessage());
        printHelp(cliOptions);
        return null;
    }
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.bake.debian.BakeDebianServiceProvider.java

@Override
public String getInstallCommand(GenerateService.ResolvedConfiguration resolvedConfiguration,
        Map<String, String> installCommands, String startupCommand) {
    Map<String, String> bindings = new HashMap<>();
    List<String> serviceNames = new ArrayList<>(installCommands.keySet());
    List<String> upstartNames = getPrioritizedBakeableServices(serviceNames).stream()
            .filter(i -> resolvedConfiguration.getServiceSettings(i.getService()).getEnabled())
            .map(i -> ((BakeDebianService) i).getUpstartServiceName()).filter(Objects::nonNull)
            .collect(Collectors.toList());
    List<String> serviceInstalls = serviceNames.stream().map(installCommands::get).collect(Collectors.toList());

    TemplatedResource resource = new JarResource("/debian/init.sh");
    bindings.put("services", Strings.join(upstartNames, " "));
    String upstartInit = resource.setBindings(bindings).toString();

    resource = new JarResource("/debian/pre-bake.sh");
    bindings = new HashMap<>();
    bindings.put("debian-repository", artifactSources.getDebianRepository());
    bindings.put("install-commands", String.join("\n", serviceInstalls));
    bindings.put("upstart-init", upstartInit);
    bindings.put("startup-file", Paths.get(startupScriptPath, "startup.sh").toString());
    bindings.put("startup-command", startupCommand);

    return resource.setBindings(bindings).toString();
}

From source file:ch.icclab.cyclops.persistence.orm.InstanceORM.java

private String getListAsString(Collection col) {
    List<String> list = new ArrayList<>();
    col.stream().forEach(elt -> list.add(elt.toString()));
    return String.join(",", list);
}

From source file:com.github.cc007.headsplacer.commands.HeadsPlacerCommand.java

private boolean search(Player player, String[] args) {
    if (args.length < 2) {
        player.sendMessage(ChatColor.RED
                + "You need to specify a head! Use: /heads (search|searchfirst|searchatindex <index>) <head name>");
        return false;
    }/*  w  ww .j  av  a 2  s.  co m*/

    String[] searchArgs = new String[args.length - 1];
    System.arraycopy(args, 1, searchArgs, 0, searchArgs.length);

    player.sendMessage(ChatColor.GREEN + "Placing heads...");
    try {
        List<ItemStack> heads = HeadCreator
                .getItemStacks(plugin.getHeadsUtils().getHeads(String.join(" ", searchArgs)));
        for (int i = 0; i < heads.size(); i++) {
            ItemStack head = heads.get(i);
            placeHeadAndGetInv(head, player, i);
        }
        player.sendMessage(ChatColor.GREEN + "Heads placed.");
        return true;
    } catch (NullPointerException ex) {
        player.sendMessage(ChatColor.RED + "No heads found!");
        return false;
    }
}