Example usage for java.util.stream Collectors joining

List of usage examples for java.util.stream Collectors joining

Introduction

In this page you can find the example usage for java.util.stream Collectors joining.

Prototype

public static Collector<CharSequence, ?, String> joining() 

Source Link

Document

Returns a Collector that concatenates the input elements into a String , in encounter order.

Usage

From source file:Main.java

public static void main(String[] args) {
    Stream<String> s = Stream.of("a", "b", "c");

    String names = s.collect(Collectors.joining());

    System.out.println(names);/*from  w  w w . j av a2  s .  c om*/
}

From source file:Main.java

public static void main(String... args) {
    String n = Food.menu.stream().map(Food::getName).collect(Collectors.joining());
    System.out.println(n);

}

From source file:Main.java

public static void main(String[] args) {
    List<Employee> persons = Employee.persons();
    String names = persons.stream().map(Employee::getName).collect(Collectors.joining());

    String delimitedNames = persons.stream().map(Employee::getName).collect(Collectors.joining(", "));

    String prefixedNames = persons.stream().map(Employee::getName)
            .collect(Collectors.joining(", ", "Hello ", ".  Goodbye."));

    System.out.println("Joined names:  " + names);
    System.out.println("Joined,  delimited names:  " + delimitedNames);
    System.out.println(prefixedNames);
}

From source file:com.hubrick.raml.mojo.util.JavaNames.java

public static String toJavaName(String string) {
    checkArgument(!Strings.isNullOrEmpty(string), "Input string cannot be null or empty");
    final String[] elements = string.split("(?i:[^a-z0-9]+)");
    return stream(spliterator(elements), false).map(indexed())
            .map(element -> element.index() > 0 ? StringUtils.capitalize(element.value()) : element.value())
            .collect(Collectors.joining());
}

From source file:br.com.Summoner.core.base.cartas.monk.MonkCard.java

@Override
public long CalculaBonus(Jogada jogada, List<Card> listaMonstrosAdversarios) {
    List<Card> cartasUtilizadasCombo = jogada.CartasUtilizadas.stream()
            .filter(carta -> carta.TipoCarta == TipoCarta.Item && carta.TipoMonstro == TipoMonstro.Monk)
            .collect(Collectors.toList());
    MonkComboResult comboResult = new MonkComboResult();
    long forcaBonus = 0;

    if (cartasUtilizadasCombo.size() > 0) {
        String[] golpesCombo = cartasUtilizadasCombo
                .stream().map(carta -> ((MonkItemCard) carta).Golpes.stream()
                        .map(golpe -> golpe.tipoGolpe.toString()).collect(Collectors.joining()))
                .collect(Collectors.joining()).split("");
        Arrays.sort(golpesCombo);
        String comboRealizado = StringUtils.join(Arrays.asList(golpesCombo), "");
        comboResult.ComboRealizado = comboRealizado;
        //          comboResult.CombosCarta.addAll(this.Combos);

        for (int i = 0; i < this.Combos.size(); i++) {
            MonkMonsterCombo combo = this.Combos.get(i);

            char[] criaturaCombo = combo.CombinacaoCombo.toCharArray();
            Arrays.sort(criaturaCombo);
            String comboDaCriatura = new String(criaturaCombo);

            boolean encontrou = comboRealizado.contains(comboDaCriatura);

            if (encontrou && forcaBonus < combo.DanoCombo) {

                forcaBonus = combo.DanoCombo;
                comboResult.ValorComboRealizado = forcaBonus;
                comboResult.ComboCriatura = comboDaCriatura;

            }//from   w ww  .  j a va  2s.c  o  m
        }

        CombosRealizados.add(comboResult);
    }

    return forcaBonus;
}

From source file:com.github.robozonky.common.remote.InterceptingInputStreamTest.java

@Test
void tooLong() throws IOException {
    final int maxLength = 1024;
    final int uuidLength = UUID.randomUUID().toString().length();
    final String contents = IntStream.range(0, (maxLength / uuidLength) + 2)
            .mapToObj(i -> UUID.randomUUID().toString()).collect(Collectors.joining());
    final InputStream s = new ByteArrayInputStream(contents.getBytes());
    try (final InterceptingInputStream s2 = new InterceptingInputStream(s)) {
        assertThat(s2.getContents()).endsWith("...more...");
    }/*from w  ww.j a  v  a2s .c o  m*/
}

From source file:io.knotx.knot.assembler.impl.FragmentAssemblerKnotProxyImpl.java

@Override
protected Single<KnotContext> processRequest(KnotContext knotContext) {
    if (hasFragments(knotContext)) {
        try {//from   w  w  w  .  j a  va 2 s.c om
            String joinedFragments = knotContext.getFragments().stream()
                    .map(configuration.unprocessedFragmentStrategy()::get).collect(Collectors.joining());

            return Single.just(createSuccessResponse(knotContext, joinedFragments));
        } catch (Exception ex) {
            LOGGER.error("Exception happened during Fragment assembly.", ex);
            return Single.just(processError(knotContext, ex));
        }
    } else {
        LOGGER.error("Fragments are empty or not exists in KnotContext.");
        return Single.just(processError(knotContext, null));
    }
}

From source file:de.bund.bfr.math.MultivariateOptimization.java

public static MultivariateOptimization createLodOptimizer(String formula, List<String> parameters,
        List<Double> targetValues, Map<String, List<Double>> variableValues, double levelOfDetection)
        throws ParseException {
    String sdParam = parameters.stream().collect(Collectors.joining());
    List<String> params = Stream.concat(parameters.stream(), Stream.of(sdParam)).collect(Collectors.toList());

    return new MultivariateOptimization(params, sdParam,
            new LodFunction(formula, params, variableValues, targetValues, levelOfDetection, sdParam));
}

From source file:com.formkiq.core.service.generator.pdfbox.TextToPDFieldMapper.java

/**
* Override the default functionality of PDFTextStripper.
*///from  ww w  .j  av  a  2  s  .c o m
@Override
protected void writeString(final String o, final List<TextPosition> textPositions) throws IOException {

    Integer page = Integer.valueOf(getCurrentPageNo() - 1);

    if (!this.textLocations.containsKey(page)) {
        this.textLocations.put(page, new ArrayList<>());
    }

    // TODO replace with CollectionUtil.groupBy
    List<List<TextPosition>> splits = split(removeNonPrintableAndExtraSpaces(textPositions));

    for (List<TextPosition> tps : splits) {

        String text = tps.stream().map(s -> s.getUnicode()).collect(Collectors.joining());

        if (text.matches(".*[a-zA-Z0-9/]+.*")) {

            PDRectangle rect = calculateTextPosition(tps);

            PDFont font = tps.get(0).getFont();
            float fontSize = tps.stream().map(s -> Float.valueOf(s.getFontSizeInPt())).max(Float::compare)
                    .orElse(Float.valueOf(0)).floatValue();

            PdfTextField tf = new PdfTextField();
            tf.setText(text.replaceAll("\t", " "));
            tf.setRectangle(rect);
            tf.setFontSize(fontSize);
            tf.setFontName(font.getName());

            LOG.log(Level.FINE, "page=" + page + ",rect=" + rect + ",fontsize=" + fontSize + ",font=" + font
                    + ",text=" + text);
            this.textLocations.get(page).add(tf);
        }
    }
}

From source file:fi.helsinki.opintoni.config.http.converter.CsvHttpMessageConverter.java

private String getCsv(CsvResponse<T> response) {
    CsvMapper csvMapper = new CsvMapper();
    CsvSchema csvSchema = csvMapper.schemaFor(response.getType());
    return response.entries.stream().map(entry -> toCsvRow(csvMapper, csvSchema, entry))
            .collect(Collectors.joining());
}