List of usage examples for java.util Collection stream
default Stream<E> stream()
From source file:com.github.horrorho.liquiddonkey.util.Bytes.java
public static String hex(Collection<ByteString> byteStrings) { return byteStrings == null ? "null" : byteStrings.stream().map(Bytes::hex).collect(Collectors.toList()).toString(); }
From source file:fi.luontola.cqrshotel.JsonSerializationTest.java
private static <T> T pickRandom(Collection<T> values) { ThreadLocalRandom random = ThreadLocalRandom.current(); return values.stream().skip(random.nextInt(values.size())).findFirst().get(); }
From source file:de.javagl.jgltf.model.io.JsonError.java
/** * Create a list of strings describing the JSON path for the given * stream context//from w w w . jav a 2s .c om * * @param streamContext The stream context * @return The string list */ private static List<String> createJsonPath(JsonStreamContext streamContext) { Collection<JsonStreamContext> list = expand(streamContext); return list.stream().map(c -> c.getCurrentName() == null ? "" : c.getCurrentName()) .collect(Collectors.toList()); }
From source file:it.ozimov.springboot.templating.mail.utils.EmailToMimeMessageTest.java
private static List<Address> toAddress(final Collection<InternetAddress> internetAddresses) { return internetAddresses.stream().map(internetAddress -> (Address) internetAddress).collect(toList()); }
From source file:org.lightjason.agentspeak.action.buildin.rest.IBaseRest.java
/** * * transforms a collection into a term stream * * @param p_collection collection/*w w w. j a v a 2 s .c om*/ * @return term stream */ private static Stream<ITerm> flatcollection(final Collection<?> p_collection) { return p_collection.stream().flatMap(IBaseRest::flatterm); }
From source file:com.hortonworks.registries.storage.util.StorageUtils.java
public static void ensureUnique(Storable storable, Function<List<QueryParam>, Collection<? extends Storable>> listFn, List<QueryParam> queryParams) { Collection<? extends Storable> storables = listFn.apply(queryParams); Optional<Long> entities = storables.stream().map(Storable::getId).filter(x -> !x.equals(storable.getId())) .findAny();/*ww w .j a v a2 s .co m*/ if (entities.isPresent()) { throw new DuplicateEntityException("Entity with '" + queryParams + "' already exists"); } }
From source file:com.liferay.ide.core.util.FileListing.java
public static List<IPath> getFileListing(File dir, String fileType) { Collection<File> files = FileUtils.listFiles(dir, new String[] { fileType }, true); Stream<File> stream = files.stream(); return stream.filter(file -> file.exists()).map(file -> new Path(file.getPath())) .collect(Collectors.toList()); }
From source file:ch.rasc.edsutil.PropertyComparatorFactory.java
@SuppressWarnings("unchecked") public static <T> Comparator<T> createComparatorFromSorters(Collection<SortInfo> sortInfos) { Comparator<T> comparator = null; if (sortInfos != null) { comparator = sortInfos.stream() .map(a -> (Comparator<T>) createComparator(a.getProperty(), a.getDirection())) .reduce(comparator, (a, b) -> a != null ? a.thenComparing(b) : b); }//from ww w .j a v a2 s . co m return comparator; }
From source file:ch.rasc.edsutil.PropertyComparatorFactory.java
@SuppressWarnings("unchecked") public static <T> Comparator<T> createComparatorFromGroups(Collection<GroupInfo> groupInfos) { Comparator<T> comparator = null; if (groupInfos != null) { comparator = groupInfos.stream() .map(a -> (Comparator<T>) createComparator(a.getProperty(), a.getDirection())) .reduce(comparator, (a, b) -> a != null ? a.thenComparing(b) : b); }//w w w .j ava2 s. c o m return comparator; }
From source file:com.github.erchu.beancp.MapperExecutorSelector.java
/** * Returns first value in {@code collection} which is not equal to null and matches filter. If * there is not such element then will return null. * * @param <T> result type.// ww w.j a v a 2 s. c om * @param collection collection to search in. * @param filter filter predicate. * @return first value in {@code collection} which is not equal to null and matches filter, if * there is not such element then will return null. */ private static <T> T firstOrNull(final Collection<T> collection, final Predicate<T> filter) { Optional<T> findFirst = collection.stream().filter(filter).findFirst(); return (findFirst.isPresent() ? findFirst.get() : null); }