当前位置: 首页>>代码示例>>Java>>正文


Java Try类代码示例

本文整理汇总了Java中scala.util.Try的典型用法代码示例。如果您正苦于以下问题:Java Try类的具体用法?Java Try怎么用?Java Try使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Try类属于scala.util包,在下文中一共展示了Try类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNow

import scala.util.Try; //导入依赖的package包/类
@Override
public T getNow(T valueIfAbsent) throws ExecutionException {
	Preconditions.checkNotNull(scalaFuture);

	Option<Try<T>> value = scalaFuture.value();

	if (value.isDefined()) {
		Try<T> tri = value.get();

		if (tri instanceof Success) {
			return ((Success<T>)tri).value();
		} else {
			throw new ExecutionException(((Failure<T>)tri).exception());
		}
	} else {
		return valueIfAbsent;
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:19,代码来源:FlinkFuture.java

示例2: schemaCheck

import scala.util.Try; //导入依赖的package包/类
@RequestMapping(SCHEMA_CHECK_URI)
public SchemaCheckResult schemaCheck(@RequestParam(value="schema") String schema,
                                     @RequestParam(value="schemaFormat") String schemaFormat,
                                     @RequestParam(value="schemaEngine") String schemaEngine,
                                     @RequestParam(value="resultFormat") String resultFormat) {
    Option<String> base = Option.apply(null);
    Try<Schema> t = Schemas.fromString(schema,schemaFormat, schemaEngine, base);
    if (t.isSuccess()) {
        Schema s = t.get();
        Try<String> tstr = s.serialize(resultFormat);
        if (tstr.isSuccess()) {
          return new SchemaCheckResult(schema,schemaFormat,resultFormat,tstr.get());
        } else {
           return new SchemaCheckResult(schema,schemaFormat,resultFormat,
                   "Error: " + tstr);

        }
    } else
        return new SchemaCheckResult(schema,schemaFormat,resultFormat,
                "Error: " + t);

}
 
开发者ID:labra,项目名称:apiShaclex,代码行数:23,代码来源:SchemaCheckController.java

示例3: getInputFields

import scala.util.Try; //导入依赖的package包/类
private List<Object> getInputFields(IndexedRecord inputRecord, String columnName) {
    // Adapt non-avpath syntax to avpath.
    // TODO: This should probably not be automatic, use the actual syntax.
    if (!columnName.startsWith("."))
        columnName = "." + columnName;
    Try<scala.collection.immutable.List<Evaluator.Ctx>> result = wandou.avpath.package$.MODULE$.select(inputRecord,
            columnName);
    List<Object> values = new ArrayList<Object>();
    if (result.isSuccess()) {
        for (Evaluator.Ctx ctx : JavaConversions.asJavaCollection(result.get())) {
            values.add(ctx.value());
        }
    } else {
        // Evaluating the expression failed, and we can handle the exception.
        Throwable t = result.failed().get();
        throw ProcessingErrorCode.createAvpathSyntaxError(t, columnName, -1);
    }
    return values;
}
 
开发者ID:Talend,项目名称:components,代码行数:20,代码来源:FilterRowDoFn.java

示例4: from

import scala.util.Try; //导入依赖的package包/类
public static <T> ComposableFuture<T> from(final FutureProvider<T> source) {
  return ComposableFutures.build(consumer -> {
    final Future<T> future = source.provide();
    future.onComplete(new AbstractFunction1<Try<T>, Void>() {
      @Override public Void apply(final Try<T> res) {
        if (res.isSuccess()) {
          consumer.consume(com.outbrain.ob1k.concurrent.Try.fromValue(res.get()));
        } else {
          consumer.consume(com.outbrain.ob1k.concurrent.Try.fromError(res.failed().get()));
        }

        return null;
      }
    }, ctx);
  });
}
 
开发者ID:outbrain,项目名称:ob1k,代码行数:17,代码来源:ScalaFutureHelper.java

示例5: detectValueCastFromCall

import scala.util.Try; //导入依赖的package包/类
@Override
public Try<Option<ValueCast<Level>>> detectValueCastFromCall(StaticInvokeExpr e) {
    SootMethod m = e.getMethod();
    BiFunction<TypeView<Level>, TypeView<Level>, Try<Option<ValueCast<Level>>>>
            makeCast =
            (t1, t2) -> {
                Optional<ValueCast<Level>> result = Interop.asJavaStream(Vars.getAll(e.getArg(0))).findFirst().map(value -> makeValueCast(t1, t2, Option.apply(value)));
                return new Success<>(Interop.asScalaOption(result));
            };
    if (castEquals(castHighToDyn, m)) {
        return makeCast.apply(THIGH, DYN);
    } else if (castEquals(castLowToDyn, m)) {
        return makeCast.apply(TLOW, DYN);
    } else if (castEquals(castDynToLow, m)) {
        return makeCast.apply(DYN, TLOW);
    } else if (castEquals(castDynToHigh, m)) {
        return makeCast.apply(DYN, THIGH);
    } else {
        return new Success<>(Option.empty());
    }
}
 
开发者ID:proglang,项目名称:jgs,代码行数:22,代码来源:TestDomain.java

示例6: save

import scala.util.Try; //导入依赖的package包/类
@Override
public void save(List<User> users) {
  List<Pair<User, Try<String>>> result = writeUsersWithExceptions(users);
  int errors = 0;
  for (Pair<User, Try<String>> pair : result) {
    logger.info("For user " + pair.getLeft() + " operation got " + pair.getRight());
    if (pair.getRight().isFailure())
      errors += 1;
  }
  if (errors != 0) {
    throw new IllegalStateException("The write operation thrown at least one exception" + result);
  }
}
 
开发者ID:raisercostin,项目名称:dcsi,代码行数:14,代码来源:ForgerockUserDao2.java

示例7: newTransactionContextWrapper

import scala.util.Try; //导入依赖的package包/类
final TransactionContextWrapper newTransactionContextWrapper(final TransactionProxy parent,
        final String shardName) {
    final TransactionContextWrapper transactionContextWrapper =
            new TransactionContextWrapper(parent.getIdentifier(), actorContext);

    Future<PrimaryShardInfo> findPrimaryFuture = findPrimaryShard(shardName, parent.getIdentifier());
    if (findPrimaryFuture.isCompleted()) {
        Try<PrimaryShardInfo> maybe = findPrimaryFuture.value().get();
        if (maybe.isSuccess()) {
            onFindPrimaryShardSuccess(maybe.get(), parent, shardName, transactionContextWrapper);
        } else {
            onFindPrimaryShardFailure(maybe.failed().get(), parent, shardName, transactionContextWrapper);
        }
    } else {
        findPrimaryFuture.onComplete(new OnComplete<PrimaryShardInfo>() {
            @Override
            public void onComplete(final Throwable failure, final PrimaryShardInfo primaryShardInfo) {
                if (failure == null) {
                    onFindPrimaryShardSuccess(primaryShardInfo, parent, shardName, transactionContextWrapper);
                } else {
                    onFindPrimaryShardFailure(failure, parent, shardName, transactionContextWrapper);
                }
            }
        }, actorContext.getClientDispatcher());
    }

    return transactionContextWrapper;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:29,代码来源:AbstractTransactionContextFactory.java

示例8: hostLevel

import scala.util.Try; //导入依赖的package包/类
public <U> CompletionStage<U> hostLevel(Optional<String> s,
                      Function<Pair<Try<HttpResponse>, Integer>, CompletionStage<U>> responseHandler) {
    return Source.single(Pair.create(HttpRequest.create().withUri(getUri(s)), 42))
            .via(poolClientFlow)
            .runWith(Sink.head(), materializer)
            .thenComposeAsync(responseHandler);
}
 
开发者ID:ferhtaydn,项目名称:akka-http-java-client,代码行数:8,代码来源:AkkaHttpJavaClient.java

示例9: dataCheck

import scala.util.Try; //导入依赖的package包/类
@RequestMapping(DATA_CHECK_URI)
public DataCheckResult dataCheck(@RequestParam(value="data") String data,
                         @RequestParam(value="dataFormat") String dataFormat,
                         @RequestParam(value="resultFormat") String resultFormat) {
    Option<String> base = Option.apply(null);
    Try<RDFAsJenaModel> t = RDFAsJenaModel.fromChars(data,dataFormat, base);
    if (t.isSuccess()) {
        RDFReader s = t.get();
        String tstr = s.serialize(resultFormat);
          return new DataCheckResult(data,dataFormat,resultFormat,tstr);
    } else
        return new DataCheckResult(data,dataFormat,resultFormat,"Error: " + t);
}
 
开发者ID:labra,项目名称:apiShaclex,代码行数:14,代码来源:DataCheckController.java

示例10: validate

import scala.util.Try; //导入依赖的package包/类
@RequestMapping(VALIDATE_URI)
public ValidateResult validate(
        @RequestParam(value="schema") String schema,
        @RequestParam(value="schemaFormat") String schemaFormat,
        @RequestParam(value="schemaEngine") String schemaEngine,
        @RequestParam(value="data") String data,
        @RequestParam(value="dataFormat") String dataFormat,
        @RequestParam(value="resultFormat") String resultFormat) {
    Option<String> base = Option.apply(null);
    List<String> emptyErrors = new ArrayList<String>();
    Try<Schema> t = Schemas.fromString(schema,schemaFormat, schemaEngine, base);
    if (t.isSuccess()) {
        Schema s = t.get();
        Try<String> tstr = s.serialize(resultFormat);
        if (tstr.isSuccess()) {
            Try<RDFAsJenaModel> trdf = RDFAsJenaModel.fromChars(data,dataFormat,base);
            if (trdf.isSuccess()) {
                Result r = s.validate(trdf.get());
                String strResult = r.serialize(resultFormat);
                // TODO: Populate errors and solutions...
                new ValidateResult(schema,schemaFormat,schemaEngine,data,dataFormat,emptyErrors,r.isValid(),
                        strResult, resultFormat);
            } else
                new ValidateResult(schema,schemaFormat,schemaEngine,data,dataFormat,emptyErrors,false,
                        "Error: " + trdf, resultFormat);
          return new ValidateResult(schema,schemaFormat,schemaEngine,data,dataFormat,emptyErrors,false,
                  "Error: " + t,resultFormat);
        } else {
           return new ValidateResult(schema,schemaFormat,schemaEngine,data,dataFormat,emptyErrors,false,
                   "Error: " + tstr,resultFormat);

        }
    } else {
        return new ValidateResult(schema,schemaFormat,schemaEngine,data,dataFormat,emptyErrors,false,
                "Error: " + t,resultFormat);
    }
}
 
开发者ID:labra,项目名称:apiShaclex,代码行数:38,代码来源:ValidateController.java

示例11: MyJavaSingleSessionSerializer

import scala.util.Try; //导入依赖的package包/类
public MyJavaSingleSessionSerializer(
    Function1<SomeJavaComplexObject, String> toValue,
    Function1<String, Try<SomeJavaComplexObject>> fromValue,
    SessionSerializer<String, String> valueSerializer
) {
    super(toValue, fromValue, valueSerializer);
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:8,代码来源:MyJavaSingleSessionSerializer.java

示例12: main

import scala.util.Try; //导入依赖的package包/类
public static void main(String[] args) {
    new MyJavaSingleSessionSerializer(
        (JFunction1<SomeJavaComplexObject, String>) SomeJavaComplexObject::getValue,
        (JFunction1<String, Try<SomeJavaComplexObject>>) value -> Try.apply((JFunction0<SomeJavaComplexObject>) () -> new SomeJavaComplexObject(value)),
        SessionSerializers.StringToStringSessionSerializer
    );
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:8,代码来源:MyJavaSingleSessionSerializer.java

示例13: main

import scala.util.Try; //导入依赖的package包/类
public static void main(String[] args) {
    new MyJavaMultiValueSessionSerializer(
        (JFunction1<SomeJavaComplexObject, Map<String, String>>) sjco -> {
            final java.util.Map<String, String> m = new HashMap<>();
            m.put("value", sjco.getValue());
            return MapConverters.toImmutableMap(m);
        },
        (JFunction1<Map<String, String>, Try<SomeJavaComplexObject>>) value ->
            Try.apply((JFunction0<SomeJavaComplexObject>) () -> new SomeJavaComplexObject(value.get("value").get()))
    );
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:12,代码来源:MyJavaMultiValueSessionSerializer.java

示例14: validate

import scala.util.Try; //导入依赖的package包/类
@Override
public Try<MySQLConnection> validate(final MySQLConnection item) {
  if (!item.isConnected()) {
    return new Failure<>(new ConnectionNotConnectedException(item));
  }

  if (item.isQuerying()) {
    return new Failure<>(new ConnectionStillRunningQueryException(item.count(), false));
  }

  return new Success<>(item);
}
 
开发者ID:outbrain,项目名称:ob1k,代码行数:13,代码来源:BasicTestingDao.java

示例15: scalaToVertx

import scala.util.Try; //导入依赖的package包/类
public static <T> Future<T> scalaToVertx(scala.concurrent.Future<T> future, ExecutionContext ec) {
  Future<T> fut = Future.future();
  future.onComplete(new AbstractFunction1<Try<T>, Void>() {
    @Override
    public Void apply(Try<T> v1) {
      if (v1.isSuccess()) {
        fut.complete(v1.get());
      } else {
        fut.fail(v1.failed().get());
      }
      return null;
    }
  }, ec);
  return fut;
}
 
开发者ID:vert-x3,项目名称:vertx-mysql-postgresql-client,代码行数:16,代码来源:ScalaUtils.java


注:本文中的scala.util.Try类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。