下面列出了java.util.Collection#stream ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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();
}
/**
* 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();
}
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();
}
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));
}
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));
}
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));
}
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));
}
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;
}
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();
}
@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();
}
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;
}
public static <T> Stream<T> toStream(Collection<T> c) {
if (c != null){
return c.stream();
}
else {
return Stream.empty();
}
}
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();
}
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();
}
private static <T> Stream<T> toStream(@Nullable final Collection<T> messages) {
return messages == null ? Stream.empty() : messages.stream();
}
public TableDisplay(Collection<Map<String, Object>> v, BeakerObjectConverter serializer) {
this(v.stream(), serializer);
}
public static <T> Stream<T> nullableStreamOf(Collection<T> nullableCollection) {
if (nullableCollection == null) {
return Stream.empty();
}
return nullableCollection.stream();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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());
}