本文整理了Java中ratpack.func.Action.with()
方法的一些代码示例,展示了Action.with()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Action.with()
方法的具体详情如下:
包路径:ratpack.func.Action
类名称:Action
方法名:with
[英]Executes with the given argument, then returns the argument.
import ratpack.func.Action;private static List run(Action> action) throws Exception
return action.with(new ArrayList<>());
}
}
}
[中]使用给定参数执行,然后返回参数
import ratpack.func.Action;private static List run(Action> action) throws Exception
return action.with(new ArrayList<>());
}
}
}
代码示例来源: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
/**
* 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
/**
* 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
/**
* Creates a URL by building a URL based on the public address.
*
* @param ctx the handling context at the time the public address is needed
* @param action the additions to the public address
* @return the built url
* @throws Exception any thrown by {@code action}
* @deprecated since 1.2, use {@link #get(Action)}
*/
@Deprecated
default URI get(@SuppressWarnings("UnusedParameters") Context ctx, Action<? super HttpUrlBuilder> action) throws Exception {
return action.with(builder()).build();
}
代码示例来源:origin: io.ratpack/ratpack-core
/**
* Creates a URL by building a URL based on the public address.
*
* @param action the additions to the public address
* @return the built url
* @throws Exception any thrown by {@code action}
* @since 1.2
*/
default URI get(Action<? super HttpUrlBuilder> action) throws Exception {
return action.with(builder()).build();
}
代码示例来源: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 RatpackServerSpec serverConfig(Action<? super ServerConfigBuilder> action) throws Exception {
return super.serverConfig(action.with(ServerConfig.embedded()));
}
}
代码示例来源:origin: io.ratpack/ratpack-core
/**
* Builds a path binder programmatically.
*
* @param exhaustive whether the binder must match the entire unbound path (false for a prefix match)
* @param action the binder definition
* @return a path binder
* @throws Exception any thrown by {@code action}
*/
static PathBinder of(boolean exhaustive, Action<? super PathBinderBuilder> action) throws Exception {
return action.with(builder()).build(exhaustive);
}
代码示例来源:origin: io.ratpack/ratpack-core
/**
* Builds a new config data with the specified object mapper, from the given definition.
* <p>
* The {@link #of(Action)} method should be favoured, as it applies useful default configuration to the object mapper used.
*
* @param objectMapper the object mapper to use for configuration purposes
* @param definition the config data definition
* @return a config data
* @throws Exception any thrown by building the config data
*/
static ConfigData of(ObjectMapper objectMapper, Action<? super ConfigDataBuilder> definition) throws Exception {
return definition.with(builder(objectMapper)).build();
}
代码示例来源:origin: io.ratpack/ratpack-core
static ServerConfig of(Action<? super ServerConfigBuilder> action) throws Exception {
return action.with(builder()).build();
}
代码示例来源:origin: io.ratpack/ratpack-core
/**
* Builds a new config data with the default object mapper, from the given definition.
* <p>
* The default object mapper is constructed without argument.
* It then has the following Jackson modules applied implicitly:
* <ul>
* <li>{@link com.fasterxml.jackson.datatype.jdk8.Jdk8Module}</li>
* <li>{@link com.fasterxml.jackson.datatype.guava.GuavaModule}</li>
* <li>{@link com.fasterxml.jackson.datatype.jsr310.JavaTimeModule}</li>
* </ul>
* <p>
* The {@link com.fasterxml.jackson.databind.DeserializationFeature#FAIL_ON_UNKNOWN_PROPERTIES} feature is disabled.
* <p>
* The following features of the JSON factory are enabled:
* <ul>
* <li>{@link com.fasterxml.jackson.core.JsonParser.Feature#ALLOW_UNQUOTED_FIELD_NAMES}</li>
* <li>{@link com.fasterxml.jackson.core.JsonParser.Feature#ALLOW_SINGLE_QUOTES}</li>
* </ul>
*
* @param definition the config data definition
* @return a config data
* @throws Exception any thrown by building the config data
*/
static ConfigData of(Action<? super ConfigDataBuilder> definition) throws Exception {
return definition.with(builder()).build();
}
代码示例来源:origin: beryx/text-io
@Override
public void init() {
try {
RatpackServer.start(server -> {
server.serverConfig(c -> {
for(Action<ServerConfigBuilder> cfg : getConfigurators()) {
c = cfg.with(c);
}
});
server.registry(Guice.registry(b -> {
for(Action<BindingsSpec> binding : getBindings()) {
b = binding.with(b);
}
}));
server.handlers(chain -> {
for(Action<Chain> handler : getHandlers()) {
// chain = chain.insert(handler);
chain = handler.with(chain);
}
});
});
} catch (Exception e) {
logger.error("Ratpack failure", e);
}
}
代码示例来源:origin: io.ratpack/ratpack-core
/**
* Creates a new renderable object wrapping the event stream.
* <p>
* Takes a publisher of any type, and an action that mutates a created {@link Event} object for each stream item.
* The action is executed for each item in the stream as it is emitted before being sent as a server sent event.
* The state of the event object when the action completes will be used as the event.
* <p>
* The action <b>MUST</b> set one of {@code id}, {@code event}, {@code data} or {@code comment}.
*
* @param publisher the event stream
* @param action the conversion of stream items to event objects
* @param <T> the type of object in the event stream
* @return a {@link ratpack.handling.Context#render(Object) renderable} object
*/
public static <T> ServerSentEvents serverSentEvents(Publisher<T> publisher, Action<? super Event<T>> action) {
return new ServerSentEvents(Streams.map(publisher, item -> {
Event<T> event = action.with(new DefaultEvent<>(item));
if (event.getData() == null && event.getId() == null && event.getEvent() == null && event.getComment() == null) {
throw new IllegalArgumentException("You must supply at least one of data, event, id or comment");
}
return event;
}));
}
代码示例来源:origin: io.ratpack/ratpack-exec
started = true;
try {
execConfig.with(Execution.fork())
.start(e ->
publisher.subscribe(new Subscriber<T>() {
代码示例来源:origin: io.ratpack/ratpack-exec
execSpec.with(Execution.fork()).start(e -> connect(promised));
return promised.promise();
内容来源于网络,如有侵权,请联系作者删除!