ratpack.func.Action类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(134)

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

Action介绍

[英]A generic type for an object that does some work with a thing.

This type serves the same purpose as the JDK's java.util.function.Consumer, but allows throwing checked exceptions. It contains methods for bridging to and from the JDK type.
[中]对某个对象执行某些操作的对象的泛型类型。
这种类型的用途与JDK的java相同。util。作用消费者,但允许抛出已检查的异常。它包含与JDK类型之间的桥接方法。

代码示例

代码示例来源:origin: io.ratpack/ratpack-exec

/**
 * Creates a block that executes this action with the given value when called.
 *
 * @param value the value to execute this action with when the block is executed
 * @return a new block
 */
default Block curry(T value) {
 return () -> execute(value);
}

代码示例来源:origin: io.ratpack/ratpack-test

@Override
public void resetRequest() {
 request = Action.noop();
 cookies.clear();
}

代码示例来源:origin: io.ratpack/ratpack-exec

/**
 * Executes the given action with {@code this}.
 *
 * @param action the action
 * @return {@code this}
 * @throws Exception any thrown by {@code action}
 */
default RegistrySpec with(Action<? super RegistrySpec> action) throws Exception {
 return action.with(this);
}

代码示例来源:origin: io.ratpack/ratpack-exec

/**
 * Creates an action that delegates to the given action if the given predicate applies, else delegates to {@link #noop()}.
 * <p>
 * This is equivalent to {@link #when(Predicate, Action, Action) when(predicate, action, noop())}.
 *
 * @param predicate the condition for the argument
 * @param action the action to execute if the predicate applies
 * @param <I> the type of argument
 * @return an action that delegates to the given action if the predicate applies, else noops
 * @see #when(Predicate, Action, Action)
 * @see #conditional(Action, Action)
 * @since 1.5
 */
static <I> Action<I> when(Predicate<? super I> predicate, Action<? super I> action) {
 return when(predicate, action, Action.noop());
}

代码示例来源:origin: io.ratpack/ratpack-groovy

/**
 * Creates a {@link ratpack.handling.Context#render(Object) renderable} Groovy based markup template.
 *
 * @param id the id/name of the template
 * @param type The content type of template
 * @param modelBuilder an action the builds a model map
 * @return a template
 */
public static MarkupTemplate groovyMarkupTemplate(String id, String type, Action<? super ImmutableMap.Builder<String, Object>> modelBuilder) {
 ImmutableMap<String, Object> model = uncheck(() -> Action.with(ImmutableMap.<String, Object>builder(), Action.noopIfNull(modelBuilder)).build());
 return groovyMarkupTemplate(model, id, type);
}

代码示例来源:origin: io.ratpack/ratpack-core

@Override
public HttpClientSpec requestIntercept(Action<? super RequestSpec> interceptor) {
 requestInterceptor = requestInterceptor.append(interceptor);
 return this;
}

代码示例来源:origin: io.ratpack/ratpack-core

private void finalizeResponse(Iterator<Action<? super Response>> finalizers, Runnable then) {
 if (finalizers.hasNext()) {
  finalizers
   .next()
   .curry(this)
   .map(Operation::of)
   .then(() ->
    finalizeResponse(finalizers, then)
   );
 } else {
  finalizeResponse(then);
 }
}

代码示例来源:origin: io.ratpack/ratpack-core

@Override
public Promise<ReceivedResponse> post(URI uri, Action<? super RequestSpec> action) {
 return request(uri, action.prepend(RequestSpec::post));
}

代码示例来源:origin: io.ratpack/ratpack-test

/**
 * A method to create an instance of the default implementation of TestHttpClient.
 * <p>
 * The settings provided can be overridden on a per request basis via {@link ratpack.test.http.TestHttpClient#requestSpec}.
 *
 * @param applicationUnderTest the Ratpack application to make requests against
 * @param requestConfigurer a {@link ratpack.func.Action} that will set up the {@link ratpack.http.client.RequestSpec} for all requests made through this instance of TestHttpClient
 * @return a http client which is configured to make requests against the provided ApplicationUnderTest
 */
static TestHttpClient testHttpClient(ApplicationUnderTest applicationUnderTest, @Nullable Action<? super RequestSpec> requestConfigurer) {
 return new DefaultTestHttpClient(applicationUnderTest, Action.noopIfNull(requestConfigurer));
}

代码示例来源:origin: io.ratpack/ratpack-exec

/**
 * Returns a new action that executes the given action and then this action.
 *
 * @param action the action to execute before this action
 * @param <O> the type of object the action accepts
 * @return the newly created aggregate action
 */
default <O extends T> Action<O> prepend(Action<? super O> action) {
 return action.append(this);
}

代码示例来源:origin: io.ratpack/ratpack-exec

/**
 * Executes the given action with the promise value, on a blocking thread.
 * <p>
 * Similar to {@link #blockingMap(Function)}, but does not provide a new value.
 * This can be used to do something with the value, without terminating the promise.
 *
 * @param action the action to to perform with the value, on a blocking thread
 * @return a promise for the same value given to the action
 */
default Promise<T> blockingOp(Action<? super T> action) {
 return flatMap(t -> Blocking.op(action.curry(t)).map(() -> t));
}

代码示例来源:origin: io.ratpack/ratpack-test

httpClient.request(uri, action.prepend(s -> s.readTimeout(Duration.ofHours(1))))
 .map(response -> {
  TypedData responseBody = response.getBody();

代码示例来源:origin: io.ratpack/ratpack-core

@Override
 public void onStart(StartEvent event) throws Exception {
  action.execute(event);
 }
};

代码示例来源:origin: io.ratpack/ratpack-exec

/**
 * Consumes the given publisher eagerly in a forked execution, buffering results until ready to be consumed by this execution.
 * <p>
 * This method is identical to {@link #fork(Action, Action)}, but uses {@link Action#noop()} for both arguments.
 *
 * @return an execution bound publisher that propagates the items of the given publisher
 * @see Streams#fork(Publisher, Action, Action)
 * @since 1.5
 */
default TransformablePublisher<T> fork() {
 return Streams.fork(this, Action.noop(), Action.noop());
}

代码示例来源:origin: io.ratpack/ratpack-exec

/**
 * Executes the action with the given argument, then returns the argument.
 * <pre class="java">{@code
 * import ratpack.func.Action;
 * import java.util.ArrayList;
 *
 * import static org.junit.Assert.assertEquals;
 *
 * public class Example {
 *   public static void main(String... args) throws Exception {
 *     assertEquals("foo", Action.with(new ArrayList<>(), list -> list.add("foo")).get(0));
 *   }
 * }
 * }</pre>
 * @param t the argument to execute the given action with
 * @param action the action to execute with the given argument
 * @param <T> the type of the argument
 * @return the given argument (i.e. {@code t})
 * @throws Exception any thrown by {@code action}
 */
static <T> T with(T t, Action<? super T> action) throws Exception {
 return action.with(t);
}

代码示例来源:origin: io.ratpack/ratpack-core

@Override
public HttpClientSpec responseIntercept(Action<? super HttpResponse> interceptor) {
 responseInterceptor = responseInterceptor.append(interceptor);
 return this;
}

代码示例来源:origin: io.ratpack/ratpack-test

@Override
public RequestFixture registry(Action<? super RegistrySpec> action) throws Exception {
 action.execute(registryBuilder);
 return this;
}

代码示例来源:origin: io.ratpack/ratpack-exec

public PeriodicPublisher(ScheduledExecutorService executorService, Function<? super Integer, ? extends T> producer, Duration duration) {
 super(Action.noop(), write -> {
  return new Subscription() {
   private volatile int counter;

代码示例来源:origin: io.ratpack/ratpack-core

/**
 * Add some query params to the URL.
 * <p>
 * The given action will be supplied with a multi map builder, to which it can contribute query params.
 * <p>
 * This method is additive with regard to the query params of this builder.
 *
 * @param params an action that contributes query params
 * @return {@code this}
 * @throws Exception any thrown by {@code params}
 */
default HttpUrlBuilder params(Action<? super ImmutableMultimap.Builder<String, Object>> params) throws Exception {
 return params(Action.with(ImmutableMultimap.builder(), params).build());
}

代码示例来源:origin: io.ratpack/ratpack-core

@Override
public HttpClientSpec errorIntercept(Action<? super Throwable> interceptor) {
 errorInterceptor = errorInterceptor.append(interceptor);
 return this;
}

相关文章