本文整理了Java中scala.Option.getOrElse()
方法的一些代码示例,展示了Option.getOrElse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.getOrElse()
方法的具体详情如下:
包路径:scala.Option
类名称:Option
方法名:getOrElse
暂无
代码示例来源:origin: apache/servicemix-bundles
@Nullable
@Override
public Object convert(Object source) {
return source instanceof Option ? ((Option<?>) source).getOrElse(alternative) : source;
}
}
代码示例来源:origin: com.davidbracewell/mango
@Override
public Optional<String> name() {
try {
return Optional.ofNullable(accumulatorV2.name().getOrElse(new AbstractFunction0<String>() {
@Override
public String apply() {
return null;
}
}));
} catch (IllegalAccessError e) {
return Optional.empty();
}
}
代码示例来源:origin: traneio/ndbc
private final io.trane.ndbc.DataSource<P, R> current() {
return currentTransaction.apply().getOrElse(() -> underlying);
}
代码示例来源:origin: play/play-test
public static Result route(Application app, FakeRequest fakeRequest) {
final scala.Option<play.api.mvc.Result> opt = play.api.test.Helpers.jRoute(app.getWrappedApplication(), fakeRequest.fake);
final play.api.mvc.Result r = opt.getOrElse(null);
if(r != null){
return new Result() {
public play.api.mvc.Result getWrappedResult(){
return r;
}
};
}
return null;
}
代码示例来源:origin: apache/samza
retryBackoff.run(fetchMetadataOperation, onExceptionRetryOperation).getOrElse(fallbackOperation);
return result;
代码示例来源:origin: kframework/k
@Override
public void apply(KToken k) {
sb.append("\\dv{");
convert(k.sort(), false);
sb.append("}(");
if (module.sortAttributesFor().get(k.sort()).getOrElse(() -> Att.empty()).getOptional("hook").orElse("").equals("STRING.String")) {
sb.append(k.s());
} else {
sb.append(StringUtil.enquoteKString(k.s()));
}
sb.append(")");
}
代码示例来源:origin: org.cogchar/org.cogchar.bundle.bind.mechio
public void fastCueAndPlayFromMediaHandle(MediaHandle<Animation> handle) {
Animation anim = null;
try{
anim = handle.getMedia().getOrElse(null);
}catch(Exception ex){}
// TODO: Get a proper performance set up for monitor + cancel, possibly based on the Media.Framed type.handle
if(anim == null){
// anim = new Animation();
// Channel c = new Channel(100, "waist");
// MotionPath mp = new MotionPath();
// mp.addPoint(0, 0.5);
// mp.addPoint(1500, 1.0);
// mp.addPoint(3000, 0.5);
// mp.addPoint(4500, 0.0);
// mp.addPoint(6000, 0.5);
// c.addPath(mp);
// anim.addChannel(c);
return;
}
FancyPerformance perf = null;
launchFullAnimJobNow(anim, perf);
}
代码示例来源:origin: play/play-test
public static <T> Result route(Application app, FakeRequest fakeRequest, byte[] body) {
final play.api.mvc.Result r = play.api.test.Helpers.jRoute(app.getWrappedApplication(), fakeRequest.getWrappedRequest(), body).getOrElse(null);
if(r != null){
return new Result() {
public play.api.mvc.Result getWrappedResult(){
return r;
}
};
}
return null;
}
代码示例来源:origin: com.lightbend.akka.grpc/akka-grpc-play-testkit
/** Creates a GrpcClientSettings from the given HTTP/2 endpoint and ActorSystem. */
public static GrpcClientSettings grpcClientSettings(
final ServerEndpoint http2Endpoint,
final ActorSystem actorSystem
) {
final ServerEndpoint.ClientSsl clientSsl = http2Endpoint.ssl().getOrElse(func(() -> {
throw new IllegalArgumentException(
"GrpcClientSettings requires a server endpoint with ssl, but non provided");
}));
return grpcClientSettings(http2Endpoint, clientSsl.sslContext(), actorSystem);
}
代码示例来源:origin: org.cogchar/org.cogchar.bundle.bind.robokind
public void fastCueAndPlayFromMediaHandle(MediaHandle<Animation> handle) {
Animation anim = null;
try{
anim = handle.getMedia().getOrElse(null);
}catch(Exception ex){}
// TODO: Get a proper performance set up for monitor + cancel, possibly based on the Media.Framed type.handle
if(anim == null){
// anim = new Animation();
// Channel c = new Channel(100, "waist");
// MotionPath mp = new MotionPath();
// mp.addPoint(0, 0.5);
// mp.addPoint(1500, 1.0);
// mp.addPoint(3000, 0.5);
// mp.addPoint(4500, 0.0);
// mp.addPoint(6000, 0.5);
// c.addPath(mp);
// anim.addChannel(c);
return;
}
FancyPerformance perf = null;
launchFullAnimJobNow(anim, perf);
}
代码示例来源:origin: kframework/k
@Override
public void apply(KApply k) {
String hook = module.attributesFor().get(k.klabel()).getOrElse(() -> Att.empty()).getOptional("hook").orElse("");
if (hook.equals("SET.element")
|| hook.equals("LIST.element")
|| hook.equals("LIST.concat")
|| hook.equals("MAP.concat")
|| hook.equals("SET.concat")) {
return;
}
if (hook.equals("MAP.element")) {
apply(k.items().get(1));
return;
}
super.apply(k);
}
}.apply(term);
代码示例来源:origin: com.lightbend.play/play-grpc-testkit
/** Creates a GrpcClientSettings from the given HTTP/2 endpoint and ActorSystem. */
public static GrpcClientSettings grpcClientSettings(
final ServerEndpoint http2Endpoint,
final ActorSystem actorSystem
) {
final ServerEndpoint.ClientSsl clientSsl = http2Endpoint.ssl().getOrElse(func(() -> {
throw new IllegalArgumentException(
"GrpcClientSettings requires a server endpoint with ssl, but non provided");
}));
return grpcClientSettings(http2Endpoint, clientSsl.sslContext(), actorSystem);
}
代码示例来源:origin: apache/samza
/**
* Creates the {@link SamzaApplication} object from the task or application class name specified in {@code config}
*
* @param config the configuration of the application
* @return the {@link SamzaApplication} object
*/
public static SamzaApplication fromConfig(Config config) {
String appClassName = new ApplicationConfig(config).getAppClass();
if (StringUtils.isNotBlank(appClassName)) {
// app.class is configured
try {
Class<SamzaApplication> appClass = (Class<SamzaApplication>) Class.forName(appClassName);
if (StreamApplication.class.isAssignableFrom(appClass) || TaskApplication.class.isAssignableFrom(appClass)) {
return appClass.newInstance();
}
} catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
throw new ConfigException(String.format("Loading app.class %s failed. The user application has to implement "
+ "StreamApplication or TaskApplication.", appClassName), e);
}
}
// no app.class defined. It has to be a legacy application with task.class configuration
Option<String> taskClassOption = new TaskConfig(config).getTaskClass();
if (!taskClassOption.isDefined() || !StringUtils.isNotBlank(taskClassOption.getOrElse(null))) {
// no task.class defined either. This is wrong.
throw new ConfigException("Legacy task applications must set a non-empty task.class in configuration.");
}
return new LegacyTaskApplication(taskClassOption.get());
}
}
代码示例来源:origin: org.apache.samza/samza-core_2.11
/**
* Creates the {@link SamzaApplication} object from the task or application class name specified in {@code config}
*
* @param config the configuration of the application
* @return the {@link SamzaApplication} object
*/
public static SamzaApplication fromConfig(Config config) {
String appClassName = new ApplicationConfig(config).getAppClass();
if (StringUtils.isNotBlank(appClassName)) {
// app.class is configured
try {
Class<SamzaApplication> appClass = (Class<SamzaApplication>) Class.forName(appClassName);
if (StreamApplication.class.isAssignableFrom(appClass) || TaskApplication.class.isAssignableFrom(appClass)) {
return appClass.newInstance();
}
} catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
throw new ConfigException(String.format("Loading app.class %s failed. The user application has to implement "
+ "StreamApplication or TaskApplication.", appClassName), e);
}
}
// no app.class defined. It has to be a legacy application with task.class configuration
Option<String> taskClassOption = new TaskConfig(config).getTaskClass();
if (!taskClassOption.isDefined() || !StringUtils.isNotBlank(taskClassOption.getOrElse(null))) {
// no task.class defined either. This is wrong.
throw new ConfigException("Legacy task applications must set a non-empty task.class in configuration.");
}
return new LegacyTaskApplication(taskClassOption.get());
}
}
代码示例来源:origin: org.apache.samza/samza-core
/**
* Creates the {@link SamzaApplication} object from the task or application class name specified in {@code config}
*
* @param config the configuration of the application
* @return the {@link SamzaApplication} object
*/
public static SamzaApplication fromConfig(Config config) {
String appClassName = new ApplicationConfig(config).getAppClass();
if (StringUtils.isNotBlank(appClassName)) {
// app.class is configured
try {
Class<SamzaApplication> appClass = (Class<SamzaApplication>) Class.forName(appClassName);
if (StreamApplication.class.isAssignableFrom(appClass) || TaskApplication.class.isAssignableFrom(appClass)) {
return appClass.newInstance();
}
} catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
throw new ConfigException(String.format("Loading app.class %s failed. The user application has to implement "
+ "StreamApplication or TaskApplication.", appClassName), e);
}
}
// no app.class defined. It has to be a legacy application with task.class configuration
Option<String> taskClassOption = new TaskConfig(config).getTaskClass();
if (!taskClassOption.isDefined() || !StringUtils.isNotBlank(taskClassOption.getOrElse(null))) {
// no task.class defined either. This is wrong.
throw new ConfigException("Legacy task applications must set a non-empty task.class in configuration.");
}
return new LegacyTaskApplication(taskClassOption.get());
}
}
代码示例来源:origin: org.apache.samza/samza-core_2.12
/**
* Creates the {@link SamzaApplication} object from the task or application class name specified in {@code config}
*
* @param config the configuration of the application
* @return the {@link SamzaApplication} object
*/
public static SamzaApplication fromConfig(Config config) {
String appClassName = new ApplicationConfig(config).getAppClass();
if (StringUtils.isNotBlank(appClassName)) {
// app.class is configured
try {
Class<SamzaApplication> appClass = (Class<SamzaApplication>) Class.forName(appClassName);
if (StreamApplication.class.isAssignableFrom(appClass) || TaskApplication.class.isAssignableFrom(appClass)) {
return appClass.newInstance();
}
} catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
throw new ConfigException(String.format("Loading app.class %s failed. The user application has to implement "
+ "StreamApplication or TaskApplication.", appClassName), e);
}
}
// no app.class defined. It has to be a legacy application with task.class configuration
Option<String> taskClassOption = new TaskConfig(config).getTaskClass();
if (!taskClassOption.isDefined() || !StringUtils.isNotBlank(taskClassOption.getOrElse(null))) {
// no task.class defined either. This is wrong.
throw new ConfigException("Legacy task applications must set a non-empty task.class in configuration.");
}
return new LegacyTaskApplication(taskClassOption.get());
}
}
代码示例来源:origin: org.apache.samza/samza-core_2.10
/**
* Creates the {@link SamzaApplication} object from the task or application class name specified in {@code config}
*
* @param config the configuration of the application
* @return the {@link SamzaApplication} object
*/
public static SamzaApplication fromConfig(Config config) {
String appClassName = new ApplicationConfig(config).getAppClass();
if (StringUtils.isNotBlank(appClassName)) {
// app.class is configured
try {
Class<SamzaApplication> appClass = (Class<SamzaApplication>) Class.forName(appClassName);
if (StreamApplication.class.isAssignableFrom(appClass) || TaskApplication.class.isAssignableFrom(appClass)) {
return appClass.newInstance();
}
} catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
throw new ConfigException(String.format("Loading app.class %s failed. The user application has to implement "
+ "StreamApplication or TaskApplication.", appClassName), e);
}
}
// no app.class defined. It has to be a legacy application with task.class configuration
Option<String> taskClassOption = new TaskConfig(config).getTaskClass();
if (!taskClassOption.isDefined() || !StringUtils.isNotBlank(taskClassOption.getOrElse(null))) {
// no task.class defined either. This is wrong.
throw new ConfigException("Legacy task applications must set a non-empty task.class in configuration.");
}
return new LegacyTaskApplication(taskClassOption.get());
}
}
代码示例来源:origin: com.criteo.java/garmadon-frameworks-spark
@Override
public void onApplicationStart(SparkListenerApplicationStart applicationStart) {
try {
header = header.cloneAndOverride(Header.newBuilder()
.withApplicationID(applicationStart.appId().getOrElse(emptyStringScala))
.withAttemptID(applicationStart.appAttemptId().getOrElse(emptyStringScala))
.withApplicationName(applicationStart.appName())
.build())
.toSerializeHeader();
} catch (Throwable t) {
LOGGER.warn("Failed to send event for onApplicationStart", t);
}
}
代码示例来源:origin: com.criteo.java/garmadon-frameworks-spark
@Override
public void onStageSubmitted(SparkListenerStageSubmitted stageSubmitted) {
try {
long submissionTime = stageSubmitted.stageInfo().submissionTime().getOrElse(currentTimeLongScala);
String name = stageSubmitted.stageInfo().name();
String stageId = String.valueOf(stageSubmitted.stageInfo().stageId());
String attemptId = String.valueOf(stageSubmitted.stageInfo().attemptId());
int numTasks = stageSubmitted.stageInfo().numTasks();
sendStageStateEvent(submissionTime, State.BEGIN, name, stageId, attemptId, numTasks);
} catch (Throwable t) {
LOGGER.warn("Failed to send event for onStageSubmitted", t);
}
}
代码示例来源:origin: kframework/k
String hookAtt = mod.sortAttributesFor().get(expectedSort).getOrElse(() -> Att()).getOptional("hook").orElse("");
if (hookAtt.equals("MAP.Map") || hookAtt.equals("SET.Set") || hookAtt.equals("LIST.List")) {
for (KLabel collectionLabel : collectionFor.keySet()) {
内容来源于网络,如有侵权,请联系作者删除!