java.util.stream.Stream.toArray()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(237)

本文整理了Java中java.util.stream.Stream.toArray()方法的一些代码示例,展示了Stream.toArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stream.toArray()方法的具体详情如下:
包路径:java.util.stream.Stream
类名称:Stream
方法名:toArray

Stream.toArray介绍

[英]Returns an array containing the elements of this stream.

This is a terminal operation.
[中]返回包含此流元素的数组。
这是一个terminal operation

代码示例

代码示例来源:origin: apache/incubator-druid

private static AggregatorFactory[] convertToCombiningFactories(AggregatorFactory[] metricsSpec)
{
 return Arrays.stream(metricsSpec)
        .map(AggregatorFactory::getCombiningFactory)
        .toArray(AggregatorFactory[]::new);
}

代码示例来源:origin: prestodb/presto

public Factory(List<Supplier<LookupSource>> partitions)
{
  this.lookupSources = partitions.stream()
      .map(Supplier::get)
      .toArray(LookupSource[]::new);
  visitedPositions = Arrays.stream(this.lookupSources)
      .map(LookupSource::getJoinPositionCount)
      .map(Math::toIntExact)
      .map(boolean[]::new)
      .toArray(boolean[][]::new);
}

代码示例来源:origin: apache/incubator-druid

protected static String[] extractFactoryName(final List<AggregatorFactory> aggregatorFactories)
{
 return aggregatorFactories.stream().map(AggregatorFactory::getName).toArray(String[]::new);
}

代码示例来源:origin: neo4j/neo4j

private static String[] getJarsFullPaths( String... jars )
{
  return Stream.of( jars )
      .map( LuceneExplicitIndexUpgrader::getJarPath ).toArray( String[]::new );
}

代码示例来源:origin: neo4j/neo4j

public static ValueType[] typesOfGroup( ValueGroup valueGroup )
{
  return Arrays.stream( ValueType.values() )
      .filter( t -> t.valueGroup == valueGroup )
      .toArray( ValueType[]::new );
}

代码示例来源:origin: neo4j/neo4j

@Override
public File[] listFiles( File directory, final FilenameFilter filter )
{
  try ( Stream<Path> listing = Files.list( path( directory ) ) )
  {
    return listing
        .filter( entry -> filter.accept( entry.getParent().toFile(), entry.getFileName().toString() ) )
        .map( Path::toFile )
        .toArray( File[]::new );
  }
  catch ( IOException e )
  {
    return null;
  }
}

代码示例来源:origin: ethereum/ethereumj

@Autowired
public VM(SystemProperties config, VMHook hook) {
  this.config = config;
  this.vmTrace = config.vmTrace();
  this.dumpBlock = config.dumpBlock();
  this.hooks = Stream.of(deprecatedHook, hook)
      .filter(h -> !h.isEmpty())
      .toArray(VMHook[]::new);
  this.hasHooks = this.hooks.length > 0;
}

代码示例来源:origin: robolectric/robolectric

public static Path[] listFiles(Path path, final Predicate<Path> filter) throws IOException {
 try (Stream<Path> list = Files.list(path)) {
  return list.filter(filter).toArray(Path[]::new);
 }
}

代码示例来源:origin: SonarSource/sonarqube

public DbTesterMyBatisConfExtension(Class<?> firstMapperClass, Class<?>... otherMapperClasses) {
 this.mapperClasses = Stream.concat(
  Stream.of(firstMapperClass),
  Arrays.stream(otherMapperClasses))
  .sorted(Comparator.comparing(Class::getName))
  .toArray(Class<?>[]::new);
}

代码示例来源:origin: prestodb/presto

public Type[] getRelationCoercion(Relation relation)
{
  return Optional.ofNullable(relationCoercions.get(NodeRef.of(relation)))
      .map(types -> types.stream().toArray(Type[]::new))
      .orElse(null);
}

代码示例来源:origin: prestodb/presto

@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
    throws SQLException
{
  Properties properties = new PrestoDriverUri(url, info).getProperties();
  return ConnectionProperties.allProperties().stream()
      .map(property -> property.getDriverPropertyInfo(properties))
      .toArray(DriverPropertyInfo[]::new);
}

代码示例来源:origin: prestodb/presto

@Override
public Page getNextPage()
{
  Page nextPage = delegate.getNextPage();
  if (nextPage == null) {
    return null;
  }
  Block[] blocks = Arrays.stream(delegateFieldIndex)
      .mapToObj(nextPage::getBlock)
      .toArray(Block[]::new);
  return new Page(nextPage.getPositionCount(), blocks);
}

代码示例来源: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: SonarSource/sonarqube

private String[] inclusions(Function<String, String[]> configProvider, String propertyKey) {
 return Arrays.stream(configProvider.apply(propertyKey))
  .map(StringUtils::trim)
  .filter(s -> !"**/*".equals(s))
  .filter(s -> !"file:**/*".equals(s))
  .toArray(String[]::new);
}

代码示例来源:origin: eclipse-vertx/vert.x

/**
 * Creates a classloader respecting the classpath option.
 *
 * @return the classloader.
 */
protected synchronized ClassLoader createClassloader() {
 URL[] urls = classpath.stream().map(path -> {
  File file = new File(path);
  try {
   return file.toURI().toURL();
  } catch (MalformedURLException e) {
   throw new IllegalStateException(e);
  }
 }).toArray(URL[]::new);
 return new URLClassLoader(urls, this.getClass().getClassLoader());
}

代码示例来源:origin: apache/flink

private static TypeSerializer<?>[] snapshotsToRestoreSerializers(TypeSerializerSnapshot<?>... snapshots) {
    return Arrays.stream(snapshots)
        .map(TypeSerializerSnapshot::restoreSerializer)
        .toArray(TypeSerializer[]::new);
  }
}

代码示例来源:origin: org.assertj/assertj-core

public static String extractedDescriptionOf(Object... items) {
 String[] itemsDescription = Stream.of(items).map(Object::toString).toArray(String[]::new);
 return extractedDescriptionOf(itemsDescription);
}

代码示例来源:origin: neo4j/neo4j

public static ValueType[] including( Predicate<ValueType> include )
{
  return Arrays.stream( ValueType.values() )
      .filter( include )
      .toArray( ValueType[]::new );
}

代码示例来源:origin: neo4j/neo4j

private StoreType[] relevantRecordStores()
{
  return Stream.of( StoreType.values() )
      .filter( type -> type.isRecordStore() && type != StoreType.META_DATA ).toArray( StoreType[]::new );
}

代码示例来源:origin: apache/incubator-dubbo

private static String[] getFilteredKeys(URL url) {
  Map<String, String> params = url.getParameters();
  if (CollectionUtils.isNotEmptyMap(params)) {
    return params.keySet().stream()
        .filter(k -> k.startsWith(HIDE_KEY_PREFIX))
        .toArray(String[]::new);
  } else {
    return new String[0];
  }
}

相关文章