本文整理了Java中java.util.Arrays.stream()
方法的一些代码示例,展示了Arrays.stream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Arrays.stream()
方法的具体详情如下:
包路径:java.util.Arrays
类名称:Arrays
方法名:stream
暂无
canonical example by Tabnine
public long getDirectorySize(File file) {
if (!file.exists()) {
return 0;
}
if (file.isFile()) {
return file.length();
}
File[] files;
if (!file.isDirectory() || (files = file.listFiles()) == null) {
return 0;
}
return Arrays.stream(files).mapToLong(f -> getDirectorySize(f)).sum();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Match handlers declared under a base package, e.g. "org.example".
* @param packages one or more base package classes
*/
public Builder basePackage(String... packages) {
Arrays.stream(packages).filter(StringUtils::hasText).forEach(this::addBasePackage);
return this;
}
代码示例来源:origin: stackoverflow.com
Stream<String> streamString = Stream.of("a", "b", "c");
String[] stringArray = streamString.toArray(size -> new String[size]);
Arrays.stream(stringArray).forEach(System.out::println);
代码示例来源:origin: apache/incubator-dubbo
/**
* get routed invokers from result of script rule evaluation
*/
@SuppressWarnings("unchecked")
protected <T> List<Invoker<T>> getRoutedInvokers(Object obj) {
if (obj instanceof Invoker[]) {
return Arrays.asList((Invoker<T>[]) obj);
} else if (obj instanceof Object[]) {
return Arrays.stream((Object[]) obj).map(item -> (Invoker<T>) item).collect(Collectors.toList());
} else {
return (List<Invoker<T>>) obj;
}
}
代码示例来源:origin: prestodb/presto
private void printPlanNodesStatsAndCost(int indent, PlanNode... nodes)
{
if (stream(nodes).allMatch(this::isPlanNodeStatsAndCostsUnknown)) {
return;
}
print(indent, "Cost: %s", stream(nodes).map(this::formatPlanNodeStatsAndCost).collect(joining("/")));
}
代码示例来源:origin: apache/incubator-druid
private static AggregatorFactory[] convertToCombiningFactories(AggregatorFactory[] metricsSpec)
{
return Arrays.stream(metricsSpec)
.map(AggregatorFactory::getCombiningFactory)
.toArray(AggregatorFactory[]::new);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Stream<T> stream() {
return Arrays.stream(getBeanNamesForTypedStream(requiredType))
.map(name -> (T) getBean(name))
.filter(bean -> !(bean instanceof NullBean));
}
@Override
代码示例来源:origin: spring-projects/spring-framework
public void setCookies(@Nullable Cookie... cookies) {
this.cookies = (ObjectUtils.isEmpty(cookies) ? null : cookies);
this.headers.remove(HttpHeaders.COOKIE);
if (this.cookies != null) {
Arrays.stream(this.cookies)
.map(c -> c.getName() + '=' + (c.getValue() == null ? "" : c.getValue()))
.forEach(value -> doAddHeaderValue(HttpHeaders.COOKIE, value, false));
}
}
代码示例来源:origin: prestodb/presto
private static Method getSingleApplyMethod(Class lambdaFunctionInterface)
{
checkCondition(lambdaFunctionInterface.isAnnotationPresent(FunctionalInterface.class), COMPILER_ERROR, "Lambda function interface is required to be annotated with FunctionalInterface");
List<Method> applyMethods = Arrays.stream(lambdaFunctionInterface.getMethods())
.filter(method -> method.getName().equals("apply"))
.collect(toImmutableList());
checkCondition(applyMethods.size() == 1, COMPILER_ERROR, "Expect to have exactly 1 method with name 'apply' in interface " + lambdaFunctionInterface.getName());
return applyMethods.get(0);
}
代码示例来源:origin: apache/incubator-druid
private static String concat(FlatTextFormat format, String... values)
{
return Arrays.stream(values).collect(Collectors.joining(format.getDefaultDelimiter()));
}
}
代码示例来源:origin: spring-projects/spring-framework
private static Method getMethodForReturnType(Class<?> returnType) {
return Arrays.stream(TestBean.class.getMethods())
.filter(method -> method.getReturnType().equals(returnType))
.findFirst()
.orElseThrow(() ->
new IllegalArgumentException("Unique return type not found: " + returnType));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public DefaultDataBuffer write(ByteBuffer... buffers) {
if (!ObjectUtils.isEmpty(buffers)) {
int capacity = Arrays.stream(buffers).mapToInt(ByteBuffer::remaining).sum();
ensureCapacity(capacity);
Arrays.stream(buffers).forEach(this::write);
}
return this;
}
代码示例来源:origin: apache/incubator-dubbo
/**
* get routed invokers from result of script rule evaluation
*/
@SuppressWarnings("unchecked")
protected <T> List<Invoker<T>> getRoutedInvokers(Object obj) {
if (obj instanceof Invoker[]) {
return Arrays.asList((Invoker<T>[]) obj);
} else if (obj instanceof Object[]) {
return Arrays.stream((Object[]) obj).map(item -> (Invoker<T>) item).collect(Collectors.toList());
} else {
return (List<Invoker<T>>) obj;
}
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
private String getContentCodingKey(HttpServletRequest request) {
String header = request.getHeader(HttpHeaders.ACCEPT_ENCODING);
if (!StringUtils.hasText(header)) {
return null;
}
return Arrays.stream(StringUtils.tokenizeToStringArray(header, ","))
.map(token -> {
int index = token.indexOf(';');
return (index >= 0 ? token.substring(0, index) : token).trim().toLowerCase();
})
.filter(this.contentCodings::contains)
.sorted()
.collect(Collectors.joining(","));
}
代码示例来源:origin: apache/flink
private static TypeSerializer<?>[] snapshotsToRestoreSerializers(TypeSerializerSnapshot<?>... snapshots) {
return Arrays.stream(snapshots)
.map(TypeSerializerSnapshot::restoreSerializer)
.toArray(TypeSerializer[]::new);
}
}
代码示例来源:origin: codecentric/spring-boot-admin
@Nullable
@SafeVarargs
private final BuildVersion updateBuildVersion(Map<String, ?>... sources) {
return Arrays.stream(sources).map(BuildVersion::from).filter(Objects::nonNull).findFirst().orElse(null);
}
代码示例来源:origin: apache/incubator-dubbo
public CompositeConfiguration(Configuration... configurations) {
if (configurations != null && configurations.length > 0) {
Arrays.stream(configurations).filter(config -> !configList.contains(config)).forEach(configList::add);
}
}
代码示例来源:origin: spring-projects/spring-framework
public void setCookies(@Nullable Cookie... cookies) {
this.cookies = (ObjectUtils.isEmpty(cookies) ? null : cookies);
this.headers.remove(HttpHeaders.COOKIE);
if (this.cookies != null) {
Arrays.stream(this.cookies)
.map(c -> c.getName() + '=' + (c.getValue() == null ? "" : c.getValue()))
.forEach(value -> doAddHeaderValue(HttpHeaders.COOKIE, value, false));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Builder cookie(HttpCookie... cookies) {
Arrays.stream(cookies).forEach(cookie -> this.cookies.add(cookie.getName(), cookie));
return this;
}
代码示例来源:origin: prestodb/presto
public List<String> getIndices(ElasticsearchTableDescription tableDescription)
{
if (tableDescription.getIndexExactMatch()) {
return ImmutableList.of(tableDescription.getIndex());
}
TransportClient client = clients.get(tableDescription.getClusterName());
verify(client != null, "client is null");
String[] indices = getIndices(client, new GetIndexRequest());
return Arrays.stream(indices)
.filter(index -> index.startsWith(tableDescription.getIndex()))
.collect(toImmutableList());
}
内容来源于网络,如有侵权,请联系作者删除!