Java Code Examples for java.util.Collection#stream()

The following examples show how to use java.util.Collection#stream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConcatTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public ConcatTest(String scenario, Collection<Integer> c1, Collection<Integer> c2, Collection<Integer> expected) {
    this.scenario = scenario;
    this.c1 = c1;
    this.c2 = c2;
    this.expected = expected;

    // verify prerequisite
    Stream<Integer> s1s = c1.stream();
    Stream<Integer> s2s = c2.stream();
    Stream<Integer> s1p = c1.parallelStream();
    Stream<Integer> s2p = c2.parallelStream();
    assertTrue(s1p.isParallel());
    assertTrue(s2p.isParallel());
    assertFalse(s1s.isParallel());
    assertFalse(s2s.isParallel());

    assertTrue(s1s.spliterator().hasCharacteristics(Spliterator.ORDERED));
    assertTrue(s1p.spliterator().hasCharacteristics(Spliterator.ORDERED));
    assertTrue(s2s.spliterator().hasCharacteristics(Spliterator.ORDERED));
    assertTrue(s2p.spliterator().hasCharacteristics(Spliterator.ORDERED));
}
 
Example 2
Source File: DataLoadTest.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Build the list of sources to be checked. Also initialises the plugins and 
 * loads the game mode and campaign files.
 */
public static Stream<Object[]> data()
{
	// Set things up
	loadGameModes();
	SettingsHandler.setOutputDeprecationMessages(false);
	SettingsHandler.setInputUnconstructedMessages(false);
	PCGenSettings.OPTIONS_CONTEXT.setBoolean(
		PCGenSettings.OPTION_ALLOW_OVERRIDE_DUPLICATES, true);

	List<SourceSelectionFacade> basicSources = getBasicSources();
	assertFalse(basicSources.isEmpty(), "No sources found");
	Collection<Object[]> params = new ArrayList<>();
	basicSources.forEach(ssf -> {
		String testName = ssf.toString().replaceAll("[(\\)]", "_");
		params.add(new Object[]{ssf, testName});
	});
	return params.stream();
}
 
Example 3
Source File: DataLoadTest.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Build the list of sources to be checked. Also initialises the plugins and 
 * loads the game mode and campaign files.
 */
public static Stream<Object[]> data()
{
	// Set things up
	loadGameModes();
	SettingsHandler.setOutputDeprecationMessages(false);
	SettingsHandler.setInputUnconstructedMessages(false);
	PCGenSettings.OPTIONS_CONTEXT.setBoolean(
		PCGenSettings.OPTION_ALLOW_OVERRIDE_DUPLICATES, true);

	List<SourceSelectionFacade> basicSources = getBasicSources();
	assertFalse(basicSources.isEmpty(), "No sources found");
	Collection<Object[]> params = new ArrayList<>();
	basicSources.forEach(ssf -> {
		String testName = ssf.toString().replaceAll("[(\\)]", "_");
		params.add(new Object[]{ssf, testName});
	});
	return params.stream();
}
 
Example 4
Source File: ConcatTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public ConcatTest(String scenario, Collection<Integer> c1, Collection<Integer> c2, Collection<Integer> expected) {
    this.scenario = scenario;
    this.c1 = c1;
    this.c2 = c2;
    this.expected = expected;

    // verify prerequisite
    Stream<Integer> s1s = c1.stream();
    Stream<Integer> s2s = c2.stream();
    Stream<Integer> s1p = c1.parallelStream();
    Stream<Integer> s2p = c2.parallelStream();
    assertTrue(s1p.isParallel());
    assertTrue(s2p.isParallel());
    assertFalse(s1s.isParallel());
    assertFalse(s2s.isParallel());

    assertTrue(s1s.spliterator().hasCharacteristics(Spliterator.ORDERED));
    assertTrue(s1p.spliterator().hasCharacteristics(Spliterator.ORDERED));
    assertTrue(s2s.spliterator().hasCharacteristics(Spliterator.ORDERED));
    assertTrue(s2p.spliterator().hasCharacteristics(Spliterator.ORDERED));
}
 
Example 5
Source File: ExecuteDifferentPoliciesTest.java    From dss with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Stream<Arguments> data() throws Exception {
	File folderPolicy = new File("src/test/resources/policy");
	File[] policyFiles = folderPolicy.listFiles();
	File folderDiagnosticData = new File("src/test/resources");
	File[] diagDataFiles = folderDiagnosticData.listFiles();
	Collection<Arguments> dataToRun = new ArrayList<>();
	for (File diagData : diagDataFiles) {
		if (diagData.isFile()) {
			XmlDiagnosticData diagnosticData = DiagnosticDataFacade.newFacade().unmarshall(diagData);
			for (File policyFile : policyFiles) {
				if (policyFile.isFile()) {
					ConstraintsParameters validationPolicy = ValidationPolicyFacade.newFacade().unmarshall(policyFile);
					dataToRun.add(Arguments.of( diagnosticData, new EtsiValidationPolicy(validationPolicy) ));
				}
			}

			dataToRun.add(Arguments.of(diagnosticData, ValidationPolicyFacade.newFacade().getDefaultValidationPolicy() ));
			dataToRun.add(Arguments.of(diagnosticData, ValidationPolicyFacade.newFacade().getTrustedListValidationPolicy() ));

		}
	}
	return dataToRun.stream();
}
 
Example 6
Source File: ConcatTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public ConcatTest(String scenario, Collection<Integer> c1, Collection<Integer> c2, Collection<Integer> expected) {
    this.scenario = scenario;
    this.c1 = c1;
    this.c2 = c2;
    this.expected = expected;

    // verify prerequisite
    Stream<Integer> s1s = c1.stream();
    Stream<Integer> s2s = c2.stream();
    Stream<Integer> s1p = c1.parallelStream();
    Stream<Integer> s2p = c2.parallelStream();
    assertTrue(s1p.isParallel());
    assertTrue(s2p.isParallel());
    assertFalse(s1s.isParallel());
    assertFalse(s2s.isParallel());

    assertTrue(s1s.spliterator().hasCharacteristics(Spliterator.ORDERED));
    assertTrue(s1p.spliterator().hasCharacteristics(Spliterator.ORDERED));
    assertTrue(s2s.spliterator().hasCharacteristics(Spliterator.ORDERED));
    assertTrue(s2p.spliterator().hasCharacteristics(Spliterator.ORDERED));
}
 
Example 7
Source File: ConcatTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public ConcatTest(String scenario, Collection<Integer> c1, Collection<Integer> c2, Collection<Integer> expected) {
    this.scenario = scenario;
    this.c1 = c1;
    this.c2 = c2;
    this.expected = expected;

    // verify prerequisite
    Stream<Integer> s1s = c1.stream();
    Stream<Integer> s2s = c2.stream();
    Stream<Integer> s1p = c1.parallelStream();
    Stream<Integer> s2p = c2.parallelStream();
    assertTrue(s1p.isParallel());
    assertTrue(s2p.isParallel());
    assertFalse(s1s.isParallel());
    assertFalse(s2s.isParallel());

    assertTrue(s1s.spliterator().hasCharacteristics(Spliterator.ORDERED));
    assertTrue(s1p.spliterator().hasCharacteristics(Spliterator.ORDERED));
    assertTrue(s2s.spliterator().hasCharacteristics(Spliterator.ORDERED));
    assertTrue(s2p.spliterator().hasCharacteristics(Spliterator.ORDERED));
}
 
Example 8
Source File: IncrementalReducer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
public <U> U reduceResults(final Collection<FastFuture<T>> results, final Function<FastFuture, T> safeJoin, final U identity,
        final BiFunction<U, ? super T, U> accumulator) {
    final Stream<FastFuture<T>> streamToUse = results.stream();

    final U result = ReactiveSeq.fromStream(streamToUse)
                        .map(safeJoin)
                        .filter(v -> v != MissingValue.MISSING_VALUE)
                        .foldLeft(identity, accumulator);
    consumer.getResults()
            .clear();
    return result;
}
 
Example 9
Source File: SignaturePoolTest.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Stream<Arguments> data() throws IOException {

		// -Dsignature.pool.folder=...

		String signaturePoolFolder = System.getProperty("signature.pool.folder", "src/test/resources/signature-pool");
		File folder = new File(signaturePoolFolder);
		Collection<File> listFiles = Utils.listFiles(folder, new String[] { "asice", "asics", "bdoc", "csig", "ddoc",
				"es3", "p7", "p7b", "p7m", "p7s", "pdf", "pkcs7", "xml", "xsig" }, true);
		Collection<Arguments> dataToRun = new ArrayList<>();
		for (File file : listFiles) {
			dataToRun.add(Arguments.of(file));
		}
		return dataToRun.stream();
	}
 
Example 10
Source File: DynamicNodeVisitor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public Stream<MethodCallExpr> visitCustomFields(DynamicNode node, VariableScope variableScope) {
    Collection<MethodCallExpr> methods = new ArrayList<>();
    methods.add(getFactoryMethod(getNodeId(node), METHOD_LANGUAGE, getOrNullExpr(node.getLanguage())));
    if (node.getActivationCondition() != null && !node.getActivationCondition().trim().isEmpty()) {
        methods.add(getActivationConditionStatement(node, variableScope));
    }
    if (node.getCompletionCondition() != null && !node.getCompletionCondition().trim().isEmpty()) {
        methods.add(getCompletionConditionStatement(node, variableScope));
    }
    return methods.stream();
}
 
Example 11
Source File: IncrementalReducer.java    From cyclops with Apache License 2.0 5 votes vote down vote up
public T reduceResults(final Collection<FastFuture<T>> results, final Function<FastFuture, T> safeJoin, final T identity,
        final BinaryOperator<T> accumulator) {
    final Stream<FastFuture<T>> streamToUse = results.stream();

    final T result = streamToUse.map(safeJoin)
                                .filter(v -> v != MissingValue.MISSING_VALUE)
                                .reduce(identity, accumulator);
    consumer.getResults()
            .clear();
    return result;
}
 
Example 12
Source File: Lambdas.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static <T> Stream<T> toStream(Collection<T> c) {
	if (c != null){
		return c.stream();
	}
	else {
		return Stream.empty();
	}
}
 
Example 13
Source File: CAdESWithPemEncodedCrlTest.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Stream<Arguments> data() {
	Object[] objects = { SignatureLevel.CAdES_BASELINE_B, SignatureLevel.CAdES_BASELINE_T, 
			SignatureLevel.CAdES_BASELINE_LT, SignatureLevel.CAdES_BASELINE_LTA };

	Collection<Arguments> dataToRun = new ArrayList<>();
	for (Object obj : objects) {
		dataToRun.add(Arguments.of(obj));
	}
	return dataToRun.stream();
}
 
Example 14
Source File: InlineRProcessor.java    From shrinker with Apache License 2.0 5 votes vote down vote up
private static <T extends QualifiedContent> Stream<T> streamOf(
        Collection<TransformInput> inputs,
        Function<TransformInput, Collection<T>> mapping) {
    Collection<T> list = inputs.stream()
            .map(mapping)
            .flatMap(Collection::stream)
            .collect(Collectors.toList());
    if (list.size() >= Runtime.getRuntime().availableProcessors())
        return list.parallelStream();
    else
        return list.stream();
}
 
Example 15
Source File: TableDisplay.java    From beakerx with Apache License 2.0 4 votes vote down vote up
public TableDisplay(Collection<Map<String, Object>> v, BeakerObjectConverter serializer) {
  this(v.stream(), serializer);
}
 
Example 16
Source File: StreamHelper.java    From pnc with Apache License 2.0 4 votes vote down vote up
public static <T> Stream<T> nullableStreamOf(Collection<T> nullableCollection) {
    if (nullableCollection == null) {
        return Stream.empty();
    }
    return nullableCollection.stream();
}
 
Example 17
Source File: MessageMappingProcessor.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private static <T> Stream<T> toStream(@Nullable final Collection<T> messages) {
    return messages == null ? Stream.empty() : messages.stream();
}
 
Example 18
Source File: Streams.java    From arctic-sea with Apache License 2.0 3 votes vote down vote up
/**
 * Factory function for creating a {@code Stream} from a {@code Collection}.
 *
 * @param <T>        the element type
 * @param collection the collection
 * @return the stream
 */
public static <T> Stream<T> stream(Collection<T> collection) {
    if (collection == null) {
        return Stream.empty();
    }
    return collection.stream();
}
 
Example 19
Source File: NullSafeCollectionStreamsUsingNullDereferenceCheck.java    From tutorials with MIT License 2 votes vote down vote up
/**
 * This method shows how to make a null safe stream from a collection through the use of a check
 * to prevent null dereferences
 *
 * @param collection The collection that is to be converted into a stream
 * @return The stream that has been created from the collection or an empty stream if the collection is null
 */
public Stream<String> collectionAsStream(Collection<String> collection) {
    return collection == null ? Stream.empty() : collection.stream();
}
 
Example 20
Source File: SimpleTimeSeriesCollection.java    From monsoon with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Construct a time series collection.
 *
 * @param timestamp The timestamp of the collection.
 * @param tsv A collection of values for the collection. The values stream
 * may not have duplicate group names.
 * @throws IllegalArgumentException if the time series values contain
 * duplicate group names.
 */
public SimpleTimeSeriesCollection(@NonNull DateTime timestamp, @NonNull Collection<? extends TimeSeriesValue> tsv) {
    this(timestamp, tsv.stream());
}