java.util.stream.Stream.builder()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(229)

本文整理了Java中java.util.stream.Stream.builder()方法的一些代码示例,展示了Stream.builder()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stream.builder()方法的具体详情如下:
包路径:java.util.stream.Stream
类名称:Stream
方法名:builder

Stream.builder介绍

暂无

代码示例

代码示例来源:origin: neo4j/neo4j

@Override
Stream<ExecutingQuery> queries()
{
  Stream.Builder<ExecutingQuery> builder = Stream.builder();
  ExecutingQueryList entry = this;
  while ( entry != EMPTY )
  {
    Entry current = (Entry) entry;
    builder.accept( current.query );
    entry = current.next;
  }
  return builder.build();
}

代码示例来源:origin: org.apache.ant/ant

/**
   * 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();
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Return a {@link Stream} over this {@link ResourceCollection}.
 * @return {@link Stream} of {@link Resource}
 * @since Ant 1.10.2
 */
default Stream<? extends Resource> stream() {
  final Stream.Builder<Resource> b = Stream.builder();
  forEach(b);
  return b.build();
}

代码示例来源:origin: speedment/speedment

/**
 * 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());
}

代码示例来源:origin: AxonFramework/AxonFramework

public Stream<Event> listAggregateSnapshots(GetAggregateSnapshotsRequest request)
    throws ExecutionException, InterruptedException {
  CompletableFuture<Stream<Event>> stream = new CompletableFuture<>();
  long before = System.currentTimeMillis();
  eventStoreStub().listAggregateSnapshots(request, new StreamObserver<Event>() {
    Stream.Builder<Event> eventStream = Stream.builder();
    int count;
    @Override
    public void onNext(Event event) {
      eventStream.accept(eventCipher.decrypt(event));
      count++;
    }
    @Override
    public void onError(Throwable throwable) {
      checkConnectionException(throwable);
      stream.completeExceptionally(GrpcExceptionParser.parse(throwable));
    }
    @Override
    public void onCompleted() {
      stream.complete(eventStream.build());
      if (logger.isDebugEnabled()) {
        logger.debug("Done request for {}: {}ms, {} events", request.getAggregateId(), System.currentTimeMillis() - before, count);
      }
    }
  });
  return stream.get();
}

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * 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();
}

代码示例来源:origin: Vedenin/useful-java-links

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]

代码示例来源:origin: AxonFramework/AxonFramework

Stream.Builder<Event> eventStream = Stream.builder();
int count;

代码示例来源:origin: speedment/speedment

public static <T> Stream<? extends T> walk(
    T first, 
    Function<T, T> traverser, 
    WalkingOrder order) {
  
  requireNonNulls(first, traverser, order);
  return walk(first, traverser, order, Stream.builder()).build();
}

代码示例来源:origin: speedment/speedment

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();
  }
}

代码示例来源:origin: speedment/speedment

public static <T> Stream<? extends T> walkOptional(
    T first, 
    Function<T, Optional<T>> traverser) {
  
  requireNonNulls(first, traverser);
  return walkOptional(
    first, 
    traverser, 
    WalkingOrder.FORWARD, 
    Stream.builder()
  ).build();
}

代码示例来源:origin: speedment/speedment

public static <T> Stream<? extends T> walkOptional(
    T first, 
    Function<T, Optional<T>> traverser,
    WalkingOrder order) {
  
  requireNonNulls(first, traverser, order);
  return walkOptional(first, traverser, order, Stream.builder()).build();
}

代码示例来源:origin: speedment/speedment

public static <T> Stream<? extends T> walk(
    T first, 
    Function<T, T> traverser) {
  
  requireNonNulls(first, traverser);
  
  return walk(
    first, 
    traverser, 
    WalkingOrder.FORWARD, 
    Stream.builder()
  ).build();
}

代码示例来源:origin: speedment/speedment

public static <T> Stream<? extends T> traverse(
    T first, 
    Function<T, Stream<? extends T>> traverser, 
    TraversalOrder traversalOrder) {
  
  requireNonNulls(first, traverser, traversalOrder);
  
  if (traversalOrder == TraversalOrder.BREADTH_FIRST) {
    return traverseBredthFirst(
      first, 
      traverser, 
      Stream.builder()
    ).build();
  } else {
    return traverse(
      first, 
      traverser, 
      traversalOrder, 
      Stream.builder()
    ).build();
  }
}

代码示例来源:origin: speedment/speedment

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()]);
}

代码示例来源:origin: wildfly/wildfly

private static <A extends Attribute> void writeAttributes(XMLExtendedStreamWriter writer, ModelNode model, Stream<A> stream) throws XMLStreamException {
  // Write attributes before elements
  Stream.Builder<Attribute> objectAttributes = Stream.builder();
  Iterable<A> attributes = stream::iterator;
  for (Attribute attribute : attributes) {
    if (attribute.getDefinition().getType() == ModelType.OBJECT) {
      objectAttributes.add(attribute);
    } else {
      writeAttribute(writer, model, attribute);
    }
  }
  Iterable<Attribute> elementAttributes = objectAttributes.build()::iterator;
  for (Attribute attribute : elementAttributes) {
    writeElement(writer, model, attribute);
  }
}

代码示例来源:origin: speedment/speedment

final Stream.Builder<T> streamBuilder = Stream.builder();
while (rs.next()) {
  streamBuilder.add(rsMapper.apply(rs));

代码示例来源:origin: google/bundletool

public static Stream<ResourceTableEntry> entries(ResourceTable resourceTable) {
 Stream.Builder<ResourceTableEntry> stream = Stream.builder();
 for (Package pkg : resourceTable.getPackageList()) {
  for (Type type : pkg.getTypeList()) {
   for (Entry entry : type.getEntryList()) {
    stream.add(ResourceTableEntry.create(pkg, type, entry));
   }
  }
 }
 return stream.build();
}

代码示例来源:origin: my2iu/Jinq

@Override
public <U> JinqStream<Pair<T, U>> joinList(
   org.jinq.orm.stream.JinqStream.JoinToIterable<T, U> join)
{
 // TODO: This stream should be constructed on the fly
 final Stream.Builder<Pair<T,U>> streamBuilder = Stream.builder();
 forEach( left -> {
   for (U right: join.join(left)) {
     streamBuilder.accept(new Pair<>(left, right)); 
   }});
 return wrap(streamBuilder.build());
}

代码示例来源:origin: my2iu/Jinq

@Override
public <U> JinqStream<Pair<T, U>> join(Join<T,U> join)
{
 // TODO: This stream should be constructed on the fly
 final Stream.Builder<Pair<T,U>> streamBuilder = Stream.builder();
 forEach( left -> {
   join.join(left).forEach( right -> 
    { streamBuilder.accept(new Pair<>(left, right)); });
   });
 return wrap(streamBuilder.build());
}

相关文章