List of usage examples for java.util Collection stream
default Stream<E> stream()
From source file:com.example.user.UserEndpoint.java
public static void main(String[] args) { final ObjectMapper objectMapper = new ObjectMapper().registerModule(new Jackson2HalModule()) .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper); converter.setSupportedMediaTypes(Collections.singletonList(MediaTypes.HAL_JSON)); final RestTemplate restTemplate = new RestTemplate(Collections.singletonList(converter)); final ResponseEntity<PagedResources<Resource<UserEntity>>> entity = restTemplate.exchange( "http://localhost:5000/db-app/users", HttpMethod.GET, null, new ParameterizedTypeReference<PagedResources<Resource<UserEntity>>>() { });/*from w w w .j a v a 2s.co m*/ System.out.println(entity.getStatusCode()); final PagedResources<Resource<UserEntity>> body = entity.getBody(); System.out.println(body); final Collection<Resource<UserEntity>> contents = body.getContent(); final List<UserEntity> userEntities = contents.stream().map(Resource::getContent).collect(toList()); }
From source file:Main.java
public static String saveIntegerListToXml(Collection<Integer> list) { return list.stream().map(String::valueOf).collect(Collectors.joining(" ")); }
From source file:Main.java
public static <T> Stream<T> stream(Collection<T> collection) { return collection.stream(); }
From source file:Main.java
/** * Returns true if any element of {@code items} is null. * @throws NullPointerException if {@code items} itself is null. *//*from ww w. j a v a 2 s . c o m*/ public static boolean isAnyNull(Collection<?> items) { return items.stream().anyMatch(Objects::isNull); }
From source file:Main.java
static List<File> exists(Collection<File> files) { return files.stream().filter(File::exists).collect(Collectors.toList()); }
From source file:Main.java
public static void anyMatch(Collection<String> strings, Predicate<String> string) { strings.stream().anyMatch(string); }
From source file:Main.java
public static <T> T find(Collection<T> collection, Predicate<T> predicate) { return collection.stream().filter(predicate).findFirst().orElse(null); }
From source file:Main.java
/** * Applies the given consumer to each item in the given collection after filtering * out null items./*w w w .j a v a 2 s .c o m*/ * * @param collection the collection. * @param consumer the consumer. */ public static <E> void nullSafeForEach(Collection<E> collection, Consumer<E> consumer) { collection.stream().filter(Objects::nonNull).forEach(consumer); }
From source file:Main.java
public static <T> List<T> filter(Collection<T> toFilter, Predicate<T> predicate) { return toFilter.stream().filter(predicate).collect(Collectors.toList()); }
From source file:Main.java
/** * Joins the items of the specified collection using a delimited. * * @param list List of items to join, cannot be null * @param delimiter Delimiter used to join the items, cannot be null *//*from w ww . ja v a 2 s . c om*/ public static <T> String join(Collection<T> list, String delimiter) { return list.stream().map(Object::toString).collect(Collectors.joining(delimiter)); }