List of usage examples for java.util.stream Collectors joining
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter)
From source file:waffle.spring.boot.demo.DemoController.java
@RequestMapping public String demo(Authentication auth) { return String.format("Hello, %s. You have authorities: %s", auth.getPrincipal(), auth.getAuthorities().stream().map(a -> a.getAuthority()).collect(Collectors.joining(", "))); }
From source file:fcl.rest.UploadResource.java
@POST @Consumes({ MediaType.MULTIPART_FORM_DATA }) @Path("file") public String uploadFile(@FormDataValues MultivaluedMap<String, String> formFields) { Map<String, String> data = new HashMap<>(); formFields.forEach((key, values) -> data.put(key, values.stream().collect(Collectors.joining(",")))); return data.toString(); }
From source file:ch.ethz.inf.vs.hypermedia.client.Utils.java
public static <T extends Enum<T>> T selectFromEnum(Class<T> enumType, Scanner scanner, String prompt) { T[] consts = enumType.getEnumConstants(); String options = Stream.of(consts).map(x -> x.ordinal() + ": " + x).collect(Collectors.joining(", ")); int index = -1; do {/*from www.j ava 2 s .c o m*/ System.out.printf("%s (%s): %n", prompt, options); String val = scanner.next().trim(); try { index = Integer.parseInt(val); } catch (NumberFormatException e) { } } while (!(index >= 0 && index < consts.length)); return consts[index]; }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpringServiceSettings.java
protected void setProfiles(List<String> profiles) { if (profiles == null || profiles.isEmpty()) { return;/* w w w. j a v a 2 s. c o m*/ } String key = "SPRING_PROFILES_ACTIVE"; String val = profiles.stream().collect(Collectors.joining(",")); getEnv().put(key, val); }
From source file:org.trustedanalytics.datasetpublisher.service.QueryBuilder.java
public String createTable(HiveTable table) { return String.format( "create external table if not exists %s (" + table.fields.stream().map(column -> column + " string").collect(Collectors.joining(",")) + ") row format delimited fields terminated by ',' stored as textfile location '%s'", table.getFullyQualifiedName(), table.location); }
From source file:fr.ybonnel.FruitShopTest.java
private void oneTest(int expectedResult, String... articles) { InputStream reader = new ReaderInputStream( new StringReader(Stream.of(articles).collect(Collectors.joining("\n")) + "\nexit\n")); ByteArrayOutputStream stream = new ByteArrayOutputStream(); new FruitShop().caisse(reader, new PrintStream(stream)); String result = new String(stream.toByteArray()); String[] lines = result.split("\\n"); String lastTotal = lines[lines.length - 2]; System.out.println(result);/*from w ww. ja v a 2 s . c o m*/ assertEquals(expectedResult, Integer.parseInt(lastTotal)); }
From source file:co.runrightfast.vertx.orientdb.config.ServerResource.java
/** * * @param user user name//w w w .ja v a 2s .co m * @param password user password * @param resources at least 1 is required * @return */ public static OServerUserConfiguration serverUserConfiguration(final String user, final String password, final ServerResource... resources) { checkArgument(isNotBlank(user), MUST_NOT_BE_BLANK, "user"); checkArgument(isNotBlank(password), MUST_NOT_BE_BLANK, "password"); checkArgument(ArrayUtils.isNotEmpty(resources), MUST_NOT_BE_EMPTY, "resources"); return new OServerUserConfiguration(user, password, Arrays.stream(resources).map(resource -> resource.resource).collect(Collectors.joining(","))); }
From source file:com.haulmont.cuba.gui.components.formatters.CollectionFormatter.java
@Override public String format(Collection value) { if (value == null) { return StringUtils.EMPTY; }/*ww w .j a va 2s . c o m*/ //noinspection unchecked return ((Collection<Object>) value).stream().map(metadataTools::format).collect(Collectors.joining(", ")); }
From source file:spring.travel.site.auth.CookieEncoder.java
public String encode(Map<String, String> values) throws AuthException { String encoded = values.entrySet().stream() .map((entry) -> urlEncode(entry.getKey()) + "=" + urlEncode(entry.getValue())) .collect(Collectors.joining("&")); String signature = signer.sign(encoded); return cookieName + "=" + signature + "-" + encoded; }
From source file:com.diversityarrays.kdxplore.vistool.VisToolData.java
static public String createReportText(Bag<String> missingOrBad, Bag<String> suppressed) { String fmt = Msg.raw_MSG_VALUE_COLON_VALUE_COUNT(); List<String> lines = new ArrayList<>(); if (!missingOrBad.isEmpty()) { lines.add(Msg.MSG_SOME_TRAIT_VALUES_NOT_PLOTTED()); lines.add("Missing or Invalid:"); appendLines(fmt, missingOrBad, lines); }//ww w .ja v a2s . co m if (!suppressed.isEmpty()) { if (missingOrBad.isEmpty()) { lines.add(Msg.MSG_SOME_TRAIT_VALUES_NOT_PLOTTED()); } lines.add("Suppressed:"); appendLines(fmt, suppressed, lines); } return lines.stream().collect(Collectors.joining("\n")); //$NON-NLS-1$ }