Java 类java.util.stream.Stream.Builder 实例源码

项目:BoneJ2    文件:LineGrid.java   
private Stream<ValuePair<Point3d, Vector3d>> lines(final long bins,
    final double sign)
{
    final Vector3d direction = getNormal(sign);
    final Vector3d t = new Vector3d(translation);
    t.scale(sign);
    final double range = 1.0 / bins;
    final Builder<ValuePair<Point3d, Vector3d>> builder = Stream.builder();
    for (int i = 0; i < bins; i++) {
        final double minC = i * range;
        for (int j = 0; j < bins; j++) {
            final double minD = j * range;
            final double c = (rng.nextDouble() * range + minC) * size - 0.5 *
                size;
            final double d = (rng.nextDouble() * range + minD) * size - 0.5 *
                size;
            final Point3d origin = createOrigin(c, d, t);
            builder.add(new ValuePair<>(origin, direction));
        }
    }
    return builder.build();
}
项目:powerunit    文件:FunctionTesterImpl.java   
@Parameters
public static <T, R> Stream<Object[]> getParameters(
        FunctionTester<T, R> input) {
    Builder<Object[]> b = Stream.builder();
    for (int i = 0; i < input.getInput().size(); i++) {
        Matcher<? super R> result = input.getResult().get(i).get();
        T param = input.getInput().get(i).get();
        String name = input.getName().get(i).get();
        if ("".equals(name)) {
            name = "Passing `" + param + "`" + " then " + result
                    + " is expected";
        }
        b.add(new Object[] { name, param, result, input.getUnderTest() });
    }
    return b.build();
}
项目:powerunit    文件:CollectorTesterImpl.java   
@Parameters
public static <T, A, R> Stream<Object[]> getDatas(
        CollectorTester<T, A, R> input) {
    StringDescription sdChar = new StringDescription();
    input.getExpectedCharacteristics().describeTo(sdChar);
    Builder<Object[]> builder = Stream.builder();
    for (int i = 0; i < input.getInputs().size(); i++) {
        StringDescription sd = new StringDescription();
        input.getResults().get(i).describeTo(sd);
        builder.add(new Object[] {
                input.getCollectorToTest(),
                i == 0,
                input.getInputs().get(i),
                input.getResults().get(i),
                sd.toString(),
                input.getExpectedCharacteristics(),
                sdChar.toString(),
                (BiFunction<String, Object[], Boolean>) CollectorTesterImpl::filter });
    }
    return builder.build();
}
项目:powerunit    文件:BiFunctionTesterImpl.java   
@Parameters
public static <T, U, R> Stream<Object[]> getParameters(
        BiFunctionTester<T, U, R> input) {
    Builder<Object[]> b = Stream.builder();
    for (int i = 0; i < input.getInput1().size(); i++) {
        Matcher<? super R> result = input.getResult().get(i).get();
        T param1 = input.getInput1().get(i).get();
        U param2 = input.getInput2().get(i).get();
        String name = input.getName().get(i).get();
        if ("".equals(name)) {
            name = "Passing `" + param1 + "` and `" + param2 + "`"
                    + " then " + result + " is expected";
        }
        b.add(new Object[] { name, param1, param2, result,
                input.getUnderTest() });
    }
    return b.build();
}
项目:druid-spring-boot    文件:DruidDataSourceConfiguration.java   
@Override
public String[] selectImports(AnnotationMetadata metadata) {
    Map<String, Object> properties = resolver.getSubProperties(EMPTY);
    Builder<Class<?>> imposts = Stream.<Class<?>>builder().add(DruidDataSourceBeanPostProcessor.class);
    imposts.add(properties.isEmpty() ? SingleDataSourceRegistrar.class : DynamicDataSourceRegistrar.class);
    return imposts.build().map(Class::getName).toArray(String[]::new);
}
项目:fpm    文件:PolygonsUtils.java   
public static Stream<Polygon> polygonsFrom(Geometry g) {
    if (g instanceof Polygon) {
        return Stream.of((Polygon) g);
    }
    else if (g instanceof MultiPolygon) {
        Builder<Polygon> builder = Stream.builder();
        for (int i = 0; i < g.getNumGeometries(); i++) {
            builder.add((Polygon) g.getGeometryN(i));
        }
        return builder.build();
    }
    return Stream.empty();
}
项目:BoneJ2    文件:HyperstackUtils.java   
/**
 * Recursively calls {@link #applySplit(ImgPlus, List)} to split the
 * hyperstack into subspaces.
 *
 * @param hyperstack an n-dimensional image
 * @param splitIndices the indices of the axes in the hyperstack used for
 *          splitting
 * @param splitIndex the i in splitIndices[i] currently used. Start from the
 *          last index
 * @param meta the metadata describing the position of the next subspace
 * @param splitCoordinates the (dimension, position) pairs describing the
 *          current split
 * @param subscripts the subscripts of the axes see
 * @param subspaces A builder for the stream of all the subspaces formed
 */
private static <T extends RealType<T> & NativeType<T>> void splitDims(
    final ImgPlus<T> hyperstack, final int[] splitIndices, final int splitIndex,
    final HyperAxisMeta[] meta,
    final List<ValuePair<IntType, LongType>> splitCoordinates,
    final long[] subscripts, final Builder<Subspace<T>> subspaces)
{
    if (splitIndex < 0) {
        final RandomAccessibleInterval<T> subspace = applySplit(hyperstack,
            splitCoordinates);
        if (!isEmptySubspace(subspace)) {
            subspaces.add(new Subspace<>(subspace, meta));
        }
    }
    else {
        final int splitDimension = splitIndices[splitIndex];
        final AxisType type = hyperstack.axis(splitDimension).type();
        final long subscript = subscripts[splitIndex];
        final long size = hyperstack.dimension(splitDimension);
        final ValuePair<IntType, LongType> pair = new ValuePair<>(new IntType(
            splitDimension), new LongType());
        for (long position = 0; position < size; position++) {
            pair.b.set(position);
            splitCoordinates.add(pair);
            meta[splitIndex] = new HyperAxisMeta(type, position, subscript);
            splitDims(hyperstack, splitIndices, splitIndex - 1, meta,
                splitCoordinates, subscripts, subspaces);
            splitCoordinates.remove(pair);
        }
    }
}
项目:parallel-stream-support    文件:ParallelStreamSupportTest.java   
@Test
public void parallelStreamWithBuilder() {
  Builder<String> builder = Stream.builder();
  builder.accept("a");
  Stream<String> stream = ParallelStreamSupport.parallelStream(builder, this.workerPool);

  assertThat(stream, instanceOf(ParallelStreamSupport.class));
  assertTrue(stream.isParallel());
  assertEquals(Optional.of("a"), stream.findAny());
}
项目:sdcct    文件:AbstractResourceParamProcessor.java   
@SuppressWarnings({ CompilerWarnings.UNCHECKED })
protected static Map<MultiKey<Serializable>, ResourceParam<?>> mapExistingResourceParams(SdcctResource entity) {
    Map<MultiKey<Serializable>, ResourceParam<?>> existingResourceParams = new LinkedHashMap<>();
    Builder<Serializable> existingResourceParamKeyStreamBuilder;
    TermResourceParam<?> existingTermResourceParam;

    for (ResourceParam<?> existingResourceParam : IteratorUtils.asIterable(iterateExistingResourceParams(entity))) {
        if (existingResourceParam.isMeta()) {
            continue;
        }

        (existingResourceParamKeyStreamBuilder = Stream.builder()).add(existingResourceParam.getName());

        if (existingResourceParam instanceof TermResourceParam) {
            existingResourceParamKeyStreamBuilder.add((existingTermResourceParam = ((TermResourceParam<?>) existingResourceParam)).getCodeSystemUri());
            existingResourceParamKeyStreamBuilder.add(existingTermResourceParam.getCodeSystemVersion());

            if (existingResourceParam instanceof QuantityResourceParam) {
                existingResourceParamKeyStreamBuilder.add(((QuantityResourceParam) existingTermResourceParam).getUnits());
            }

            existingResourceParamKeyStreamBuilder.add(existingTermResourceParam.getDisplayName());
        }

        existingResourceParamKeyStreamBuilder.add(existingResourceParam.getValue());

        existingResourceParams.put(new MultiKey<>(existingResourceParamKeyStreamBuilder.build().toArray(Serializable[]::new)), existingResourceParam);
    }

    return existingResourceParams;
}
项目:songbook    文件:Song.java   
public Stream<String> findAuthors() {
    final Builder<String> authors = Stream.builder();
    for (PositionedData<Directive> directive : directives) {
        if ( "author".equals(directive.data.name.toLowerCase()) ) {
            authors.add(directive.data.value);
        }
    }
    return authors.build();
}
项目:powerunit    文件:PatternTesterImpl.java   
@Parameters
public static Stream<Object[]> getParameters(PatternTester input) {
    Builder<Object[]> builder = Stream.builder();
    for (int i = 0; i < input.getInputs().size(); i++) {
        builder.add(new Object[] { input.getUnderTest(),
                input.getInputs().get(i), input.getExpectedResult().get(i),
                input.getHavingGroup().get(i),
                input.getExpectedGroup().get(i),
                input.getUnderTest().pattern() });
    }
    return builder.build();
}
项目:powerunit    文件:MatcherTesterImpl.java   
@Parameters
public static Stream<Object[]> getParameter(MatcherTester input) {
    Builder<Object[]> builder = Stream.builder();
    for (int i = 0; i < input.getExpectedGroup().size(); i++) {
        StringDescription sd = new StringDescription();
        input.getExpectedGroup().get(i).describeTo(sd);
        builder.add(new Object[] { input.getMatcher(),
                input.getMatcher().pattern().pattern(), input.getInput(),
                input.getHavingGroup().get(i),
                input.getExpectedGroup().get(i), sd.toString() });
    }
    return builder.build();
}
项目:openjdk-jdk10    文件:HotSpotCompiledCodeBuilder.java   
public static HotSpotCompiledCode createCompiledCode(CodeCacheProvider codeCache, ResolvedJavaMethod method, HotSpotCompilationRequest compRequest, CompilationResult compResult) {
    String name = compResult.getName();

    byte[] targetCode = compResult.getTargetCode();
    int targetCodeSize = compResult.getTargetCodeSize();

    Site[] sites = getSortedSites(codeCache, compResult);

    Assumption[] assumptions = compResult.getAssumptions();

    ResolvedJavaMethod[] methods = compResult.getMethods();

    List<CodeAnnotation> annotations = compResult.getAnnotations();
    Comment[] comments = new Comment[annotations.size()];
    if (!annotations.isEmpty()) {
        for (int i = 0; i < comments.length; i++) {
            CodeAnnotation annotation = annotations.get(i);
            String text;
            if (annotation instanceof CodeComment) {
                CodeComment codeComment = (CodeComment) annotation;
                text = codeComment.value;
            } else if (annotation instanceof JumpTable) {
                JumpTable jumpTable = (JumpTable) annotation;
                text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]";
            } else {
                text = annotation.toString();
            }
            comments[i] = new Comment(annotation.position, text);
        }
    }

    DataSection data = compResult.getDataSection();
    byte[] dataSection = new byte[data.getSectionSize()];

    ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder());
    Builder<DataPatch> patchBuilder = Stream.builder();
    data.buildDataSection(buffer, vmConstant -> {
        patchBuilder.accept(new DataPatch(buffer.position(), new ConstantReference(vmConstant)));
    });

    int dataSectionAlignment = data.getSectionAlignment();
    DataPatch[] dataSectionPatches = patchBuilder.build().toArray(len -> new DataPatch[len]);

    int totalFrameSize = compResult.getTotalFrameSize();
    StackSlot customStackArea = compResult.getCustomStackArea();
    boolean isImmutablePIC = compResult.isImmutablePIC();

    if (method instanceof HotSpotResolvedJavaMethod) {
        HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method;
        int entryBCI = compResult.getEntryBCI();
        boolean hasUnsafeAccess = compResult.hasUnsafeAccess();

        int id;
        long jvmciEnv;
        if (compRequest != null) {
            id = compRequest.getId();
            jvmciEnv = compRequest.getJvmciEnv();
        } else {
            id = hsMethod.allocateCompileId(entryBCI);
            jvmciEnv = 0L;
        }
        return new HotSpotCompiledNmethod(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC,
                        totalFrameSize, customStackArea, hsMethod, entryBCI, id, jvmciEnv, hasUnsafeAccess);
    } else {
        return new HotSpotCompiledCode(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC,
                        totalFrameSize, customStackArea);
    }
}
项目:graal-core    文件:HotSpotCompiledCodeBuilder.java   
public static HotSpotCompiledCode createCompiledCode(CodeCacheProvider codeCache, ResolvedJavaMethod method, HotSpotCompilationRequest compRequest, CompilationResult compResult) {
    String name = compResult.getName();

    byte[] targetCode = compResult.getTargetCode();
    int targetCodeSize = compResult.getTargetCodeSize();

    Site[] sites = getSortedSites(codeCache, compResult);

    Assumption[] assumptions = compResult.getAssumptions();

    ResolvedJavaMethod[] methods = compResult.getMethods();

    List<CodeAnnotation> annotations = compResult.getAnnotations();
    Comment[] comments = new Comment[annotations.size()];
    if (!annotations.isEmpty()) {
        for (int i = 0; i < comments.length; i++) {
            CodeAnnotation annotation = annotations.get(i);
            String text;
            if (annotation instanceof CodeComment) {
                CodeComment codeComment = (CodeComment) annotation;
                text = codeComment.value;
            } else if (annotation instanceof JumpTable) {
                JumpTable jumpTable = (JumpTable) annotation;
                text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]";
            } else {
                text = annotation.toString();
            }
            comments[i] = new Comment(annotation.position, text);
        }
    }

    DataSection data = compResult.getDataSection();
    byte[] dataSection = new byte[data.getSectionSize()];

    ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder());
    Builder<DataPatch> patchBuilder = Stream.builder();
    data.buildDataSection(buffer, vmConstant -> {
        patchBuilder.accept(new DataPatch(buffer.position(), new ConstantReference(vmConstant)));
    });

    int dataSectionAlignment = data.getSectionAlignment();
    DataPatch[] dataSectionPatches = patchBuilder.build().toArray(len -> new DataPatch[len]);

    int totalFrameSize = compResult.getTotalFrameSize();
    StackSlot customStackArea = compResult.getCustomStackArea();
    boolean isImmutablePIC = compResult.isImmutablePIC();

    if (method instanceof HotSpotResolvedJavaMethod) {
        HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method;
        int entryBCI = compResult.getEntryBCI();
        boolean hasUnsafeAccess = compResult.hasUnsafeAccess();

        int id;
        long jvmciEnv;
        if (compRequest != null) {
            id = compRequest.getId();
            jvmciEnv = compRequest.getJvmciEnv();
        } else {
            id = hsMethod.allocateCompileId(entryBCI);
            jvmciEnv = 0L;
        }
        return new HotSpotCompiledNmethod(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC,
                        totalFrameSize, customStackArea, hsMethod, entryBCI, id, jvmciEnv, hasUnsafeAccess);
    } else {
        return new HotSpotCompiledCode(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC,
                        totalFrameSize, customStackArea);
    }
}
项目:BoneJ2    文件:HyperstackUtils.java   
/**
 * Splits the hyperstack into subspaces defined by the given axes.
 * <p>
 * If all the given axis types are not found in the hyperstack, gives
 * subspaces of the found types. If none of the types are found, returns an
 * empty stream. For example, if you want to split a {X, Y, C, T} hyperstack
 * into {X, Y, Z}, returns all the {X, Y} subspaces.
 * </p>
 * <p>
 * NB Assumes that the given {@link ImgPlus} has the necessary metadata, i.e.
 * its {@link CalibratedAxis} have {@link AxisType}.
 * </p>
 *
 * @param hyperStack an N-dimensional image.
 * @param <T> type of the elements in the image.
 * @param subspaceTypes the types of the axis in the desired subspace.
 * @return a stream of all the subspaces found.
 */
public static <T extends RealType<T> & NativeType<T>> Stream<Subspace<T>>
    splitSubspaces(final ImgPlus<T> hyperStack, List<AxisType> subspaceTypes)
{
    if (subspaceTypes == null || subspaceTypes.isEmpty()) {
        return Stream.empty();
    }
    final Builder<Subspace<T>> builder = Stream.builder();
    final int[] splitIndices = findSplitAxisIndices(hyperStack, subspaceTypes);
    final long[] typeSubscripts = mapTypeSubscripts(hyperStack, splitIndices);
    final int numSplits = splitIndices.length;
    final HyperAxisMeta[] subspaceMeta = new HyperAxisMeta[numSplits];
    final List<ValuePair<IntType, LongType>> split = new ArrayList<>();
    splitDims(hyperStack, splitIndices, numSplits - 1, subspaceMeta, split,
        typeSubscripts, builder);
    return builder.build();
}
项目:parallel-stream-support    文件:ParallelStreamSupportTest.java   
@Test(expected = NullPointerException.class)
public void parallelStreamWithNullBuilder() {
  Builder<String> builder = null;
  ParallelStreamSupport.parallelStream(builder, this.workerPool);
}