本文整理了Java中java.util.stream.Stream.of()
方法的一些代码示例,展示了Stream.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stream.of()
方法的具体详情如下:
包路径:java.util.stream.Stream
类名称:Stream
方法名:of
暂无
代码示例来源:origin: neo4j/neo4j
private String addressConfigurationDescription()
{
return Stream.of( httpAddress, httpsAddress )
.filter( Objects::nonNull )
.map( Object::toString )
.collect( joining( ", " ) );
}
代码示例来源:origin: lets-blade/blade
private static void cacheMethod(Map<Class<? extends Annotation>, Method> cache, Method[] methods, Class<? extends Annotation> filter) {
List<Method> methodList = Stream.of(methods)
.filter(method -> method.isAnnotationPresent(filter))
.collect(Collectors.toList());
if (methodList.size() == 1) {
cache.put(filter, methodList.get(0));
} else if (methodList.size() > 1) {
throw new RuntimeException("Duplicate annotation @" + filter.getSimpleName() + " in class: " + methodList.get(0).getDeclaringClass().getName());
}
}
代码示例来源:origin: org.apache.ant/ant
/**
* Returns the topmost interface that extends Remote for a given
* class - if one exists.
* @param testClass the class to be tested
* @return the topmost interface that extends Remote, or null if there
* is none.
*/
public Class<?> getRemoteInterface(Class<?> testClass) {
return Stream.of(testClass.getInterfaces())
.filter(Remote.class::isAssignableFrom).findFirst().orElse(null);
}
代码示例来源:origin: SonarSource/sonarqube
private static Set<String> getPossibleOperators() {
return Stream.of(Condition.Operator.values())
.map(Condition.Operator::getDbValue)
.collect(Collectors.toSet());
}
}
代码示例来源:origin: google/guava
public void testToOptionalNull() {
Stream<Object> stream = Stream.of((Object) null);
try {
stream.collect(MoreCollectors.toOptional());
fail("Expected NullPointerException");
} catch (NullPointerException expected) {
}
}
代码示例来源:origin: baomidou/mybatis-plus
@Override
protected List<String> list(URL url, String path) throws IOException {
Resource[] resources = resourceResolver.getResources("classpath*:" + path + "/**/*.class");
return Stream.of(resources)
.map(resource -> preserveSubpackageName(resource, path))
.collect(Collectors.toList());
}
代码示例来源:origin: micronaut-projects/micronaut-core
@SuppressWarnings("unchecked")
@Override
public Optional<? extends ExecutableMethod<?, ?>> findFirst() {
return Stream.of(functions, suppliers, consumers, biFunctions)
.map(all -> {
Collection<ExecutableMethod<?, ?>> values = all.values();
return values.stream().findFirst();
}).filter(Optional::isPresent)
.map(Optional::get)
.findFirst();
}
代码示例来源:origin: speedment/speedment
public static <T> Stream<T> streamOfOptional(@SuppressWarnings("OptionalUsedAsFieldOrParameterType") Optional<T> element) {
return Stream.of(element.orElse(null)).filter(Objects::nonNull);
}
代码示例来源:origin: sqshq/piggymetrics
public static Frequency withDays(int days) {
return Stream.of(Frequency.values())
.filter(f -> f.getDays() == days)
.findFirst()
.orElseThrow(IllegalArgumentException::new);
}
}
代码示例来源:origin: prestodb/presto
@Override
public Result apply(SemiJoinNode semiJoinNode, Captures captures, Context context)
{
Set<Symbol> requiredFilteringSourceInputs = Streams.concat(
Stream.of(semiJoinNode.getFilteringSourceJoinSymbol()),
semiJoinNode.getFilteringSourceHashSymbol().map(Stream::of).orElse(Stream.empty()))
.collect(toImmutableSet());
return restrictOutputs(context.getIdAllocator(), semiJoinNode.getFilteringSource(), requiredFilteringSourceInputs)
.map(newFilteringSource ->
semiJoinNode.replaceChildren(ImmutableList.of(semiJoinNode.getSource(), newFilteringSource)))
.map(Result::ofPlanNode)
.orElse(Result.empty());
}
}
代码示例来源:origin: neo4j/neo4j
private StoreType[] relevantRecordStores()
{
return Stream.of( StoreType.values() )
.filter( type -> type.isRecordStore() && type != StoreType.META_DATA ).toArray( StoreType[]::new );
}
代码示例来源:origin: baomidou/mybatis-plus
public Resource[] resolveMapperLocations() {
return Stream.of(Optional.ofNullable(this.mapperLocations).orElse(new String[0]))
.flatMap(location -> Stream.of(getResources(location)))
.toArray(Resource[]::new);
}
代码示例来源:origin: lets-blade/blade
private static void cacheMethod(Map<Class<? extends Annotation>, Method> cache, Method[] methods, Class<? extends Annotation> filter) {
List<Method> methodList = Stream.of(methods)
.filter(method -> method.isAnnotationPresent(filter))
.collect(Collectors.toList());
if (methodList.size() == 1) {
cache.put(filter, methodList.get(0));
} else if (methodList.size() > 1) {
throw new RuntimeException("Duplicate annotation @" + filter.getSimpleName() + " in class: " + methodList.get(0).getDeclaringClass().getName());
}
}
代码示例来源:origin: SonarSource/sonarqube
private static File locateHomeDir(Configuration configuration) {
return Stream.of(
configuration.get("sonar.userHome").orElse(null),
System.getenv("SONAR_USER_HOME"),
System.getProperty("user.home") + File.separator + ".sonar")
.filter(Objects::nonNull)
.findFirst()
.map(File::new)
.get();
}
}
代码示例来源:origin: SonarSource/sonarqube
static Set<Metric> extractMetrics(List<IssueMetricFormula> formulas) {
return formulas.stream()
.flatMap(f -> Stream.concat(Stream.of(f.getMetric()), f.getDependentMetrics().stream()))
.collect(Collectors.toSet());
}
}
代码示例来源:origin: google/guava
public void testOnlyElementMultiple() {
try {
Stream.of(1, 2).collect(MoreCollectors.onlyElement());
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
assertThat(expected.getMessage()).contains("1, 2");
}
}
代码示例来源:origin: prestodb/presto
@Override
public List<SchemaTableName> listTables(ConnectorSession session, String schemaNameOrNull)
{
if (schemaNameOrNull == null) {
return Stream.of(AtopTable.values())
.map(table -> new SchemaTableName(environment, table.getName()))
.collect(Collectors.toList());
}
if (!listSchemaNames(session).contains(schemaNameOrNull)) {
return ImmutableList.of();
}
return Stream.of(AtopTable.values())
.map(table -> new SchemaTableName(schemaNameOrNull, table.getName()))
.collect(Collectors.toList());
}
代码示例来源:origin: SonarSource/sonarqube
private static String buildDirectoryProjectRelativePath(Map<String, String> pathByModuleKey, ComponentDto c, ComponentDto parentModule) {
String moduleProjectRelativePath = buildModuleProjectRelativePath(pathByModuleKey, parentModule);
return Stream.of(moduleProjectRelativePath, c.path())
.map(StringUtils::trimToNull)
.filter(s -> s != null && !"/".equals(s))
.collect(Collectors.joining("/"));
}
代码示例来源:origin: neo4j/neo4j
private Stream<CompilationMessage> validateConstructor( Element extensionClass )
{
Optional<ExecutableElement> publicNoArgConstructor =
constructorsIn( extensionClass.getEnclosedElements() ).stream()
.filter( c -> c.getModifiers().contains( Modifier.PUBLIC ) )
.filter( c -> c.getParameters().isEmpty() ).findFirst();
if ( !publicNoArgConstructor.isPresent() )
{
return Stream.of( new ExtensionMissingPublicNoArgConstructor( extensionClass,
"Extension class %s should contain a public no-arg constructor, none found.", extensionClass ) );
}
return Stream.empty();
}
}
代码示例来源:origin: SonarSource/sonarqube
private void validatePullRequestParamsWhenPluginAbsent(List<String> validationMessages) {
Stream.of(PULL_REQUEST_KEY, PULL_REQUEST_BRANCH, PULL_REQUEST_BASE)
.filter(param -> nonNull(settings.get(param).orElse(null)))
.forEach(param -> validationMessages.add(format("To use the property \"%s\", the branch plugin is required but not installed. "
+ "See the documentation of branch support: %s.", param, BRANCHES_DOC_LINK)));
}
内容来源于网络,如有侵权,请联系作者删除!