play.libs.Scala类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(315)

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

Scala介绍

[英]Class that contains useful java <-> scala conversion helpers.
[中]类,该类包含有用的java<->scala转换帮助程序。

代码示例

代码示例来源:origin: com.typesafe.play/play-test_2.12

/**
 * Constructs a in-memory (h2) database configuration to add to a fake application.
 *
 * @param name       the database name.
 * @param options the database options.
 * @return a map of String containing database config info.
 */
public static Map<String, String> inMemoryDatabase(String name, Map<String, String> options) {
  return Scala.asJava(play.api.test.Helpers.inMemoryDatabase(name, Scala.asScala(options)));
}

代码示例来源:origin: com.typesafe.play/play-test_2.10

@Deprecated
public static Result route(Application app, RequestBuilder requestBuilder, byte[] body, long timeout) {
 return wrapScalaResult(Scala.orNull(play.api.test.Helpers.jRoute(app.getWrappedApplication(), requestBuilder.build()._underlyingRequest(), body)), timeout);
}

代码示例来源:origin: com.typesafe.play/play-test_2.10

path,
  classloader,
  Scala.toSeq(additionalPlugins),
  Scala.toSeq(withoutPlugins),
  Scala.asScala((Map<String, Object>) additionalConfiguration),
  scala.Option.apply(scalaGlobal),
  scala.PartialFunction$.MODULE$.<scala.Tuple2<String, String>, Handler>empty()
);

代码示例来源:origin: com.typesafe.play/play-test_2.10

/**
 * A test Netty web server with HTTPS support
 * @param port HTTP port to bind on
 * @param application The Application to load in this server
 * @param sslPort HTTPS port to bind on
 */
public TestServer(int port, Application application, int sslPort) {
  super(port, application.getWrappedApplication(), Option.<Object>apply(sslPort), play.libs.Scala.<ServerProvider>None());
}

代码示例来源:origin: play/play-test

/**
 * A Fake application.
 *
 * @param path The application path
 * @param classloader The application classloader
 * @param additionalConfiguration Additional configuration
 * @param additionalPlugins Additional plugins
 */
@SuppressWarnings("unchecked")
public FakeApplication(File path, ClassLoader classloader, Map<String, ? extends Object> additionalConfiguration, List<String> additionalPlugins, play.GlobalSettings global) {
  play.api.GlobalSettings g = null;
  if(global != null)
   g = new play.core.j.JavaGlobalSettingsAdapter(global);
  wrappedApplication = new play.api.test.FakeApplication(
      path,
      classloader,
      Scala.toSeq(additionalPlugins),
      Scala.<String>emptySeq(),
      Scala.asScala((Map<String, Object>)additionalConfiguration),
      scala.Option.apply(g)
      );
}

代码示例来源:origin: com.typesafe.play/play_2.10

/**
 * The context for loading an application.
 *
 * @param environment the application environment
 * @param initialSettings the initial settings. These settings are merged with the settings from the loaded
 *                        configuration files, and together form the initialConfiguration provided by the context.  It
 *                        is intended for use in dev mode, to allow the build system to pass additional configuration
 *                        into the application.
 */
 public Context(Environment environment, Map<String,Object> initialSettings) {
   this.underlying = new play.api.ApplicationLoader.Context(
     environment.underlying(),
     scala.Option.empty(),
     new play.core.DefaultWebCommands(),
     play.api.Configuration.load(environment.underlying(), play.libs.Scala.asScala(initialSettings)));
 }

代码示例来源:origin: com.typesafe.play/play

/**
 * An alias for futures(stage, delay, unit) that uses a java.time.Duration.
 *
 * @param stage the input completion stage that may time out.
 * @param duration The duration after which there is a timeout.
 * @param <A> the completion stage that should be wrapped with a future.
 * @return the completion stage, or a completion stage that failed with futures.
 */
@Override
public <A> CompletionStage<A> timeout(final CompletionStage<A> stage, final Duration duration) {
  requireNonNull(stage, "Null stage");
  requireNonNull(duration, "Null duration");
  FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS);
  return toJava(delegate.timeout(finiteDuration, Scala.asScalaWithFuture(() -> stage)));
}

代码示例来源:origin: com.typesafe.play/play_2.10

/**
 * Retrieves a configuration value as a <code>String</code>.
 *
 * @param key configuration key (relative to configuration root key)
 * @return a configuration value or <code>null</code>
 */
public String getString(String key) {
  return Scala.orNull(conf.getString(key, scala.Option.<scala.collection.immutable.Set<java.lang.String>>empty()));
}

代码示例来源:origin: com.typesafe.play/play_2.12

/**
 * Returns a new flash with the given keys removed.
 */
public Flash removing(String... keys) {
  return new play.api.mvc.Flash(Scala.asScala(this)).$minus$minus(Scala.toSeq(keys)).asJava();
}

代码示例来源:origin: com.typesafe.play/play-cache_2.11

@Override
public <T> CompletionStage<T> getOrElseUpdate(String key, Callable<CompletionStage<T>> block, int expiration) {
  return toJava(
    asyncCacheApi.getOrElseUpdate(key, intToDuration(expiration), Scala.asScalaWithFuture(block), Scala.<T>classTag()));
}

代码示例来源:origin: com.typesafe.play/play_2.10

/**
 * Create an application loading context.
 *
 * Locates and loads the necessary configuration files for the application.
 *
 * @param environment The application environment.
 * @param initialSettings The initial settings. These settings are merged with the settings from the loaded
 *                        configuration files, and together form the initialConfiguration provided by the context.  It
 *                        is intended for use in dev mode, to allow the build system to pass additional configuration
 *                        into the application.
 */
public static Context create(Environment environment, Map<String, Object> initialSettings) {
  play.api.ApplicationLoader.Context scalaContext = play.api.ApplicationLoader$.MODULE$.createContext(
    environment.underlying(),
    Scala.asScala(initialSettings),
    Scala.<SourceMapper>None(),
    new DefaultWebCommands());
  return new Context(scalaContext);
}

代码示例来源:origin: com.typesafe.play/play_2.11

@Inject
public Langs(play.api.i18n.Langs langs) {
  this.langs = langs;
  List<Lang> availables = new ArrayList<>();
  for (play.api.i18n.Lang lang : Scala.asJava(langs.availables())) {
    availables.add(new Lang(lang));
  }
  this.availables = Collections.unmodifiableList(availables);
}

代码示例来源:origin: com.typesafe.play/play_2.12

/**
 * Generates a JavaScript reverse router.
 *
 * @param name the router's name
 * @param ajaxMethod which asynchronous call method the user's browser will use (e.g. "jQuery.ajax")
 * @param host the host to use for the reverse route
 * @param routes the reverse routes for this router
 * @return the router
 */
public static JavaScript create(String name, String ajaxMethod, String host, JavaScriptReverseRoute... routes) {
  return play.api.routing.JavaScriptReverseRouter.apply(
    name, Scala.Option(ajaxMethod), host, Scala.varargs(routes)
  );
}

代码示例来源:origin: com.typesafe.play/play-java-ws

/**
 * Retrieve the URL where the user should be redirected to start the OpenID authentication process
 */
@Override
public CompletionStage<String> redirectURL(
    String openID, String callbackURL, Map<String, String> axRequired, Map<String, String> axOptional, String realm) {
  if (axRequired == null) axRequired = new HashMap<>();
  if (axOptional == null) axOptional = new HashMap<>();
  return FutureConverters.toJava(client.redirectURL(openID,
      callbackURL,
      JavaConversions.mapAsScalaMap(axRequired).toSeq(),
      JavaConversions.mapAsScalaMap(axOptional).toSeq(),
      Scala.Option(realm)));
}

代码示例来源:origin: com.typesafe.play/play_2.12

/**
 * Retrieve Lang availables from the application configuration.
 *
 * @param app the current application.
 * @return the list of available Lang.
 */
public static List<Lang> availables(Application app) {
  play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class);
  List<play.api.i18n.Lang> availableLangs = Scala.asJava(langs.availables());
  return availableLangs.stream().map(Lang::new).collect(toList());
}

代码示例来源:origin: com.typesafe.play/play_2.11

/**
   * Convert this result to a Scala result.
   *
   * @return the Scala result.
   */
  public play.api.mvc.Result asScala() {
    return new play.api.mvc.Result(
      header.asScala(),
      body.asScala(),
      session == null ? Scala.None() : Scala.Option(play.api.mvc.Session.fromJavaSession(session)),
      flash == null ? Scala.None() : Scala.Option(play.api.mvc.Flash.fromJavaFlash(flash)),
      JavaHelpers$.MODULE$.cookiesToScalaCookies(cookies)
    );
  }
}

代码示例来源:origin: com.typesafe.play/play

protected HttpErrorHandler preferred(Http.RequestHeader request) {
  String preferredContentType = Scala.orNull(MediaRange.preferred(
      Scala.toSeq(request.acceptedTypes()),
      Scala.toSeq(errorHandlerMap.keySet().toArray(new String[]{}))
  ));
  if (preferredContentType == null) {
    return errorHandlerMap.values().iterator().next();
  } else {
    return errorHandlerMap.get(preferredContentType);
  }
}

代码示例来源:origin: com.typesafe.play/play_2.10

/**
 * Retrieves a resource from the classpath.
 *
 * @param relativePath relative path of the resource to fetch
 * @return URL to the resource (may be null)
 */
public URL resource(String relativePath) {
  return Scala.orNull(env.resource(relativePath));
}

代码示例来源:origin: com.typesafe.play/play-test_2.12

/**
 * Executes a block of code in a running application.
 *
 * @param application the application context.
 * @param block       the block to run after the Play app is started.
 */
public static void running(Application application, final Runnable block) {
  Helpers$.MODULE$.running(application.asScala(), asScala(() -> { block.run(); return null; }));
}

代码示例来源:origin: com.typesafe.play/play-test_2.11

/**
 * Executes a block of code in a running server.
 * @param server    the server to start.
 * @param block  the block of code to run after the server starts.
 */
public static void running(TestServer server, final Runnable block) {
  Helpers$.MODULE$.running(server, asScala(() -> { block.run(); return null; }));
}

相关文章