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

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

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

Function.apply介绍

[英]Applies this function to the given argument.
[中]将此函数应用于给定参数。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Adapt from the given Reactive Streams Publisher.
 * @param publisher the publisher to adapt from
 * @return the reactive type instance representing the adapted publisher
 */
public Object fromPublisher(Publisher<?> publisher) {
  return this.fromPublisherFunction.apply(publisher);
}

代码示例来源:origin: google/guava

static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
  Function<? super T, ? extends K> keyFunction,
  Function<? super T, ? extends V> valueFunction) {
 checkNotNull(keyFunction);
 checkNotNull(valueFunction);
 return Collector.of(
   ImmutableMap.Builder<K, V>::new,
   (builder, input) -> builder.put(keyFunction.apply(input), valueFunction.apply(input)),
   ImmutableMap.Builder::combine,
   ImmutableMap.Builder::build);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Adapt the given request processor function to a filter function that only operates
 * on the {@code ServerRequest}.
 * @param requestProcessor the request processor
 * @return the filter adaptation of the request processor
 */
static HandlerFilterFunction<?, ?> ofRequestProcessor(
    Function<ServerRequest, Mono<ServerRequest>> requestProcessor) {
  Assert.notNull(requestProcessor, "Function must not be null");
  return (request, next) -> requestProcessor.apply(request).flatMap(next::handle);
}

代码示例来源:origin: google/guava

static <T, K, V> Collector<T, ?, ImmutableBiMap<K, V>> toImmutableBiMap(
  Function<? super T, ? extends K> keyFunction,
  Function<? super T, ? extends V> valueFunction) {
 checkNotNull(keyFunction);
 checkNotNull(valueFunction);
 return Collector.of(
   ImmutableBiMap.Builder<K, V>::new,
   (builder, input) -> builder.put(keyFunction.apply(input), valueFunction.apply(input)),
   ImmutableBiMap.Builder::combine,
   ImmutableBiMap.Builder::build,
   new Collector.Characteristics[0]);
}

代码示例来源:origin: google/guava

@Override
public V computeIfAbsent(K key, Function<? super K, ? extends V> function) {
 checkNotNull(key);
 checkNotNull(function);
 return compute(key, (k, oldValue) -> (oldValue == null) ? function.apply(key) : oldValue);
}

代码示例来源:origin: google/guava

@Override
public boolean tryAdvance(Consumer<? super T> action) {
 return fromSpliterator.tryAdvance(
   fromElement -> action.accept(function.apply(fromElement)));
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
    this.savedRequest = request;
    return this.responseMonoFunction.apply(response);
  }
}

代码示例来源:origin: spring-projects/spring-framework

private Marshaller initMarshaller(Class<?> clazz) throws JAXBException {
  Marshaller marshaller = this.jaxbContexts.createMarshaller(clazz);
  marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name());
  marshaller = this.marshallerProcessor.apply(marshaller);
  return marshaller;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Default constructor. Initializes {@link HttpClient} via:
 * <pre class="code">
 * HttpClient.create().compress()
 * </pre>
 */
public ReactorClientHttpConnector() {
  this.httpClient = defaultInitializer.apply(HttpClient.create());
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Apply the exception handler and return the alternative result.
 * @param failure the exception
 * @return the new result or the same error if there is no exception handler
 */
public Mono<HandlerResult> applyExceptionHandler(Throwable failure) {
  return (this.exceptionHandler != null ? this.exceptionHandler.apply(failure) : Mono.error(failure));
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return a {@code RequestPredicate} that tests the request path
 * against the given path pattern.
 * @param pattern the pattern to match to
 * @return a predicate that tests against the given path pattern
 */
public static RequestPredicate path(String pattern) {
  Assert.notNull(pattern, "'pattern' must not be null");
  return pathPredicates(DEFAULT_PATTERN_PARSER).apply(pattern);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate,
    Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) {
  if (this.statusHandlers.size() == 1 && this.statusHandlers.get(0) == DEFAULT_STATUS_HANDLER) {
    this.statusHandlers.clear();
  }
  this.statusHandlers.add(new StatusHandler(statusPredicate,
      (clientResponse, request) -> exceptionFunction.apply(clientResponse)));
  return this;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public RouterFunctions.Builder before(Function<ServerRequest, ServerRequest> requestProcessor) {
  Assert.notNull(requestProcessor, "RequestProcessor must not be null");
  return filter((request, next) -> next.handle(requestProcessor.apply(request)));
}

代码示例来源:origin: spring-projects/spring-framework

@Override
protected Mono<Void> writeAndFlushWithInternal(
    Publisher<? extends Publisher<? extends DataBuffer>> body) {
  return this.writeHandler.apply(Flux.from(body).concatMap(Flux::from));
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public WebSocketMessage pingMessage(Function<DataBufferFactory, DataBuffer> payloadFactory) {
  DataBuffer payload = payloadFactory.apply(bufferFactory());
  return new WebSocketMessage(WebSocketMessage.Type.PING, payload);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public WebSocketMessage binaryMessage(Function<DataBufferFactory, DataBuffer> payloadFactory) {
  DataBuffer payload = payloadFactory.apply(bufferFactory());
  return new WebSocketMessage(WebSocketMessage.Type.BINARY, payload);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public WebSocketMessage pongMessage(Function<DataBufferFactory, DataBuffer> payloadFactory) {
  DataBuffer payload = payloadFactory.apply(bufferFactory());
  return new WebSocketMessage(WebSocketMessage.Type.PONG, payload);
}

代码示例来源:origin: spring-projects/spring-framework

@OnWebSocketConnect
public void onWebSocketConnect(Session session) {
  this.delegateSession = this.sessionFactory.apply(session);
  this.delegateHandler.handle(this.delegateSession).subscribe(this.delegateSession);
}

代码示例来源:origin: google/guava

private void doExpectCollects(@Nullable R expectedResult, List<T> inputs) {
 for (CollectStrategy scheme : EnumSet.allOf(CollectStrategy.class)) {
  A finalAccum = scheme.result(collector, inputs);
  if (collector.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {
   assertEquivalent(expectedResult, (R) finalAccum);
  }
  assertEquivalent(expectedResult, collector.finisher().apply(finalAccum));
 }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void pathPredicates() {
  PathPatternParser parser = new PathPatternParser();
  parser.setCaseSensitive(false);
  Function<String, RequestPredicate> pathPredicates = RequestPredicates.pathPredicates(parser);
  URI uri = URI.create("http://localhost/path");
  RequestPredicate predicate = pathPredicates.apply("/P*");
  MockServerRequest request = MockServerRequest.builder().uri(uri).build();
  assertTrue(predicate.test(request));
}

相关文章