Refine search
Stream<String> streamFromValues = Stream.of("a1", "a2", "a3"); System.out.println("streamFromValues = " + streamFromValues.collect(Collectors.toList())); // print streamFromValues = [a1, a2, a3] System.out.println("streamFromArrays = " + streamFromArrays.collect(Collectors.toList())); // print streamFromArrays = [a1, a2, a3] Stream<String> streamFromArrays1 = Stream.of(array); Stream.Builder<String> builder = Stream.builder(); Stream<String> streamFromBuilder = builder.add("a1").add("a2").add("a3").build(); System.out.println("streamFromBuilder = " + streamFromBuilder.collect((Collectors.toList()))); // print streamFromFiles = [a1, a2, a3]
/** * Obtains a stream of resource URLs. * * @param path The path * @return A resource stream */ public Stream<URL> getResources(String path) { Enumeration<URL> all; try { all = classLoader.getResources(prefixPath(path)); } catch (IOException e) { return Stream.empty(); } Stream.Builder<URL> builder = Stream.builder(); while (all.hasMoreElements()) { URL url = all.nextElement(); builder.accept(url); } return builder.build(); }
private void collectGroupContent( ExplicitGroup eg, Stream.Builder<Group> out ) { eg.getContainedRoleAssgineeIdentifiers().stream() .map( idtf -> roleAssigneeSvc.getRoleAssignee(idtf) ) .filter( asn -> asn instanceof Group ) .forEach( group -> out.accept((Group)group) ); eg.getContainedExplicitGroups().forEach( meg -> { out.accept(meg); collectGroupContent(meg, out); }); }
private static <T> Stream.Builder<? extends T> traverseBredthFirst( T first, Function<T, Stream<? extends T>> traverser, Stream.Builder<T> builder) { requireNonNulls(first, traverser, builder); if (first == null) { return builder; } final Queue<T> q = new ArrayDeque<>(); q.add(first); while (!q.isEmpty()) { final T node = q.poll(); builder.add(node); traverser .apply(node) .filter(Objects::nonNull) .forEach(q::add); } return builder; }
private static Stream<Symbol> allSymbols(JavaScriptTree root) { Stream<JavaScriptTree> thisAndDescendants = Stream.concat(Stream.<JavaScriptTree>builder().add(root).build(), root.descendants()); return thisAndDescendants.filter(tree -> tree instanceof IdentifierTree) .map(tree -> (IdentifierTree) tree) .map(IdentifierTree::symbol) .filter(Optional::isPresent) .map(Optional::get); }
/** * Returns a {@link Stream} of the current mappings that are registered with * this class. Mappings that are not associated to any particular DbmsType * will have their {@code Optional<DbmsType>} set to * {@code Optional.empty()} whereas specific DbmsType mappings will have the * {@code Optional<DbmsType>} field set accordingly. * * @return a {@link Stream} of the current mappings that are registered with * this class */ public Stream<Tuple2<Optional<DbmsType>, ResultSetMapping<?>>> stream() { final Stream<Tuple2<Optional<DbmsType>, ResultSetMapping<?>>> s0 = map.values().stream().map(v -> Tuples.of(Optional.empty(), v)); final Stream.Builder<Stream<Tuple2<Optional<DbmsType>, ResultSetMapping<?>>>> sb = Stream.builder(); sb.add(s0); dbmsTypeMap.entrySet().forEach(e -> { final DbmsType dbmsType = e.getKey(); Stream<Tuple2<Optional<DbmsType>, ResultSetMapping<?>>> sn = e.getValue().values().stream().map(v -> Tuples.of(Optional.of(dbmsType), v)); sb.add(sn); }); return sb.build().flatMap(Function.identity()); }
public static <T> Stream<T> traverseOver(Table table, Class<T> clazz) { if (Column.class.isAssignableFrom(clazz)) { return table.columns().map(clazz::cast); } else if (PrimaryKeyColumn.class.isAssignableFrom(clazz)) { return table.primaryKeyColumns().map(clazz::cast); } else if (Index.class.isAssignableFrom(clazz)) { return table.indexes().map(clazz::cast); } else if (ForeignKey.class.isAssignableFrom(clazz)) { return table.foreignKeys().map(clazz::cast); } else { final Stream.Builder<T> sb = Stream.builder(); table.columns().flatMap(c -> traverseOver(c, clazz)).forEachOrdered(sb::accept); table.primaryKeyColumns().flatMap(c -> traverseOver(c, clazz)).forEachOrdered(sb::accept); table.indexes().flatMap(c -> traverseOver(c, clazz)).forEachOrdered(sb::accept); table.foreignKeys().flatMap(c -> traverseOver(c, clazz)).forEachOrdered(sb::accept); return sb.build(); } }
/** * Get an iterator on the list of project helpers configured. The iterator * will always return at least one element as there will always be the * default project helper configured. * * @return an iterator of {@link ProjectHelper} */ public Iterator<ProjectHelper> getHelpers() { Stream.Builder<Constructor<? extends ProjectHelper>> b = Stream.builder(); helpers.forEach(b::add); return b.add(PROJECTHELPER2_CONSTRUCTOR).build().map(c -> { try { return c.newInstance(); } catch (Exception e) { throw new BuildException("Failed to invoke no-arg constructor" + " on " + c.getName()); } }).map(ProjectHelper.class::cast).iterator(); } }
protected List<GrantedAuthority> createGrantedAuthorities(List<CustomerRole> customerRoles) { return customerRoles.stream() .flatMap(r -> { final Stream.Builder<SimpleGrantedAuthority> builder = Stream.<SimpleGrantedAuthority>builder().add(new SimpleGrantedAuthority(r.getRoleName())); if (r.getRoleName().equals("ROLE_USER")) { builder.add(new SimpleGrantedAuthority("ROLE_USER")); } return builder.build(); }).distinct() .collect(toList()); }
private Stream<Class<?>> walkHierarchy() { final TypeWrapper w = new TypeWrapper(Reflection.primitiveToWrapper(validatedType)); Stream.Builder<Class<?>> hierarchy = Stream.builder(); Reflection.hierarchy(w.componentType, Interfaces.INCLUDE).forEach(hierarchy); final Stream<Class<?>> result = hierarchy.build().map(w::unwrapArrayComponentType); if (validatedType.isInterface() || validatedType.isArray()) { return Stream.concat(result, Stream.of(Object.class)); } return result; }
@Override public <U> JinqStream<Pair<T, U>> crossJoin(JinqStream<U> join) { List<U> saved = join.toList(); // TODO: This stream should be constructed on the fly final Stream.Builder<Pair<T,U>> streamBuilder = Stream.builder(); forEach( left -> { saved.stream().forEach( right -> streamBuilder.accept(new Pair<>(left, right))); }); return wrap(streamBuilder.build()); }
public static String[] generateApplyResultSetBody( ReadFromResultSet readFromResultSet, TranslatorSupport<Table> support, File file, Supplier<Stream<? extends Column>> columnsSupplier) { file.add(Import.of(SQLException.class)); final List<String> rows = new LinkedList<>(); rows.add("return createEntity()"); final Stream.Builder<String> streamBuilder = Stream.builder(); final AtomicInteger position = new AtomicInteger(1); columnsSupplier.get() .filter(HasEnabled::isEnabled) .forEachOrdered(c -> streamBuilder.add(indent(".set" + support.namer().javaTypeName(c.getJavaName()) + "(\t " + readFromResultSet.readFromResultSet(file, c, position) + ")")) ); streamBuilder.add(indent(";")); streamBuilder.build().forEachOrdered(rows::add); return rows.toArray(new String[rows.size()]); }
private Stream<Triple> getRepositoryTriples() { LOGGER.trace("Creating RDF triples for repository description"); final Stream.Builder<Triple> b = Stream.builder(); of("RepositoryRoot", "Resource", "Container").forEach(x -> b.accept(create(subject(), type.asNode(), createURI(REPOSITORY_NAMESPACE + x)))); // offer all these accumulated triples return b.build(); } }
/** * Diff a graph against a stream of triples * * @param replacement the replacement * @param original the original */ public GraphDifferencer(final Graph replacement, final Stream<Triple> original) { notCommon = replacement; common = createDefaultGraph(); original.forEach(x -> { synchronized (this) { if (notCommon.contains(x)) { notCommon.remove(x.getSubject(), x.getPredicate(), x.getObject()); common.add(x); } else if (!common.contains(x)) { source.accept(x); } } }); }
Object createMultiGetResponse(Map<byte[], CacheEntry<byte[], byte[]>> pairs) { Stream.Builder<ByteBuf> elements = Stream.builder(); switch (header.operation) { case GetRequest: case GetWithVersionRequest: pairs.forEach((k, v) -> elements.add(buildGetResponse(k, v))); elements.add(wrappedBuffer(END)); return elements.build().toArray(ByteBuf[]::new); default: throw new IllegalArgumentException("Operation " + header.operation + " not supported!"); } }
/** * Collections of groups may include {@link ExplicitGroup}s, which have a * recursive structure (more precisely, a Composite Pattern}. This has many * advantages, but it makes answering the question "which groups are * contained in this group" non-trivial. This method deals with this issue by * providing a "flat list" of the groups contained in the groups at the * passed collection. * * The resultant stream is distinct - groups appear in it only once, even if * some of them are members of multiple groups. * * @param groups A collection of groups * @return A distinct stream of groups who are members of, or are * descendants of members of the groups in {@code groups}. */ public Stream<Group> flattenGroupsCollection( Collection<Group> groups ) { Stream.Builder<Group> out = Stream.builder(); groups.forEach( g -> { out.accept(g); if ( g instanceof ExplicitGroup ) { collectGroupContent((ExplicitGroup) g, out); } }); return out.build().distinct(); }