java.util.function.Function.identity()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(489)

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

Function.identity介绍

[英]Returns a function that always returns its input argument.
[中]返回始终返回其输入参数的函数。

代码示例

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

protected BoltRequestMessageReader( BoltConnection connection, BoltResponseHandler externalErrorResponseHandler,
    List<RequestMessageDecoder> decoders )
{
  this.connection = connection;
  this.externalErrorResponseHandler = externalErrorResponseHandler;
  this.decoders = decoders.stream().collect( toMap( RequestMessageDecoder::signature, identity() ) );
}

代码示例来源:origin: codecentric/spring-boot-admin

private Endpoints(Collection<Endpoint> endpoints) {
  if (endpoints.isEmpty()) {
    this.endpoints = Collections.emptyMap();
  } else {
    this.endpoints = endpoints.stream().collect(toMap(Endpoint::getId, Function.identity()));
  }
}

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

@Override
  public Map<Symbol, Symbol> visitIndexSource(IndexSourceNode node, Set<Symbol> lookupSymbols)
  {
    checkState(node.getLookupSymbols().equals(lookupSymbols), "lookupSymbols must be the same as IndexSource lookup symbols");
    return lookupSymbols.stream().collect(toImmutableMap(identity(), identity()));
  }
}

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

public Map<EntityChangeType, List<AtlasEntity>> getChangedDataSetEntities() {
  final Map<EntityChangeType, List<AtlasEntity>> changedEntities = Stream
      .of(rootInputPortEntities.values().stream(), rootOutputPortEntities.values().stream(), queues.values().stream())
      .flatMap(Function.identity())
      .collect(Collectors.groupingBy(entity -> getEntityChangeType(entity.getGuid())));
  updateAudit.add("CREATED DataSet entities=" + changedEntities.get(EntityChangeType.CREATED));
  updateAudit.add("UPDATED DataSet entities=" + changedEntities.get(EntityChangeType.UPDATED));
  updateAudit.add("DELETED DataSet entities=" + changedEntities.get(EntityChangeType.DELETED));
  return changedEntities;
}

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

@Override
public FinalizingFieldAccessPostAggregator decorate(final Map<String, AggregatorFactory> aggregators)
{
 final Comparator<Object> theComparator;
 final Function<Object, Object> theFinalizer;
 if (aggregators != null && aggregators.containsKey(fieldName)) {
  //noinspection unchecked
  theComparator = aggregators.get(fieldName).getComparator();
 } else {
  //noinspection unchecked
  theComparator = (Comparator) Comparators.naturalNullsFirst();
 }
 if (aggregators != null && aggregators.containsKey(fieldName)) {
  theFinalizer = aggregators.get(fieldName)::finalizeComputation;
 } else {
  theFinalizer = Function.identity();
 }
 return new FinalizingFieldAccessPostAggregator(
   name,
   fieldName,
   theComparator,
   theFinalizer
 );
}

代码示例来源:origin: AsyncHttpClient/async-http-client

public ClientStats getClientStats() {
 Map<String, Long> totalConnectionsPerHost = openChannels.stream().map(Channel::remoteAddress).filter(a -> a.getClass() == InetSocketAddress.class)
     .map(a -> (InetSocketAddress) a).map(InetSocketAddress::getHostName).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
 Map<String, Long> idleConnectionsPerHost = channelPool.getIdleChannelCountPerHost();
 Map<String, HostStats> statsPerHost = totalConnectionsPerHost.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> {
  final long totalConnectionCount = entry.getValue();
  final long idleConnectionCount = idleConnectionsPerHost.getOrDefault(entry.getKey(), 0L);
  final long activeConnectionCount = totalConnectionCount - idleConnectionCount;
  return new HostStats(activeConnectionCount, idleConnectionCount);
 }));
 return new ClientStats(statsPerHost);
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Override
public Map<String, Long> getIdleChannelCountPerHost() {
 return partitions
     .values()
     .stream()
     .flatMap(ConcurrentLinkedDeque::stream)
     .map(idle -> idle.getChannel().remoteAddress())
     .filter(a -> a.getClass() == InetSocketAddress.class)
     .map(a -> (InetSocketAddress) a)
     .map(InetSocketAddress::getHostName)
     .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
}

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

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
{
  return listTables(session, prefix.getSchemaName()).stream().collect(toImmutableMap(identity(), schemaTableName -> getRequiredTableMetadata(schemaTableName).getColumns()));
}

代码示例来源:origin: aws/aws-sdk-java

@Override
public String apply(String content) {
  return findUnusedImports(content).stream().map(this::removeImportFunction).reduce(Function.identity(), Function::andThen).apply(content);
}

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

public Visitor(Collection<PlanFragment> fragments, DirectedGraph<PlanFragmentId, DefaultEdge> graph)
{
  this.fragments = fragments.stream()
      .collect(toImmutableMap(PlanFragment::getId, identity()));
  this.graph = graph;
}

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

private static Function<Page, Page> enforceLayoutProcessor(List<Symbol> expectedLayout, Map<Symbol, Integer> inputLayout)
{
  int[] channels = expectedLayout.stream()
      .peek(symbol -> checkArgument(inputLayout.containsKey(symbol), "channel not found for symbol: %s", symbol))
      .mapToInt(inputLayout::get)
      .toArray();
  if (Arrays.equals(channels, range(0, inputLayout.size()).toArray())) {
    // this is an identity mapping
    return Function.identity();
  }
  return new PageChannelSelector(channels);
}

代码示例来源:origin: aws/aws-sdk-java

static ContentProcessor chain(ContentProcessor...processors) {
    return input -> Stream.of(processors).map(p -> (Function<String, String>) p).reduce(Function.identity(), Function::andThen).apply(input);
  }
}

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

AtopTable(String name, String atopLabel, List<AtopColumn> columns)
{
  this.atopLabel = atopLabel;
  this.name = requireNonNull(name, "name is null");
  this.columns = ImmutableList.copyOf(requireNonNull(columns, "columns is null"));
  columnIndex = this.columns.stream().collect(Collectors.toMap(AtopColumn::getName, Function.identity()));
}

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

throws OrcCorruptionException
List<RowGroupStatistics> rowGroups = rowGroupStatistics.get(stripeOffset);
if (rowGroups == null) {
  throw new OrcCorruptionException(orcDataSourceId, "Unexpected stripe at offset %s", stripeOffset);
RowGroupStatistics actualRowGroup = new RowGroupStatistics(BOTH, IntStream.range(1, actual.size()).boxed().collect(toImmutableMap(identity(), actual::get)));
      .collect(toImmutableList());
  actual = actual.subList(1, actual.size());

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

private Map<DecoderColumnHandle, RedisFieldDecoder<String>> chooseFieldDecoders(Set<DecoderColumnHandle> columns)
{
  return columns.stream()
      .collect(ImmutableMap.toImmutableMap(identity(), this::chooseFieldDecoder));
}

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

public StageInfo getStageInfo()
{
  Map<StageId, StageInfo> stageInfos = stages.values().stream()
      .map(SqlStageExecution::getStageInfo)
      .collect(toImmutableMap(StageInfo::getStageId, identity()));
  return buildStageInfo(rootStageId, stageInfos);
}

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

private <E extends TpchEntity> Map<TpchColumn<E>, ColumnStatisticsRecorder> createStatisticsRecorders(List<TpchColumn<E>> columns)
{
  return columns.stream()
      .collect(toImmutableMap(identity(), (column) -> new ColumnStatisticsRecorder(column.getType())));
}

代码示例来源:origin: ben-manes/caffeine

@Override
 public Map<Integer, Integer> loadAll(Iterable<? extends Integer> keys) {
  return Streams.stream(keys).collect(toMap(identity(), this::load));
 }
}

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

public Visitor(Collection<PlanFragment> fragments)
{
  this.fragments = fragments.stream()
      .collect(toImmutableMap(PlanFragment::getId, identity()));
}

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

public static Stream<? extends Document> typedChildrenOf(Table table) {
  return Stream.of(
    table.columns().map(Document.class::cast),
    table.primaryKeyColumns().map(Document.class::cast),
    table.indexes().map(Document.class::cast),
    table.foreignKeys().map(Document.class::cast)
  ).flatMap(Function.identity());
}

相关文章