如何在多个完成阶段获得切换条件下的结果

时间:2019-03-30 11:06:05

标签: java-8 completable-future completion-stage

我想在开关案例中调用不同的CompletionStage,我还有其他条件,这些条件将作为案例不断添加,我想获得该特定案例的结果。

下面是代码。

public CompletionStage<HashMap<String,Object>> verifyDetails(Argument1, Argumnet2) {

        CompletionStage<JsonNode> js = new CompletableFuture<>();

    if(true) {

        switch(Expression) {
            case "1":
             js.thenCompose(cs1 -> {return GetCase1Details()});
            break;
            case "2":
             js.thenCompose(cs1 -> {return getCase2Details()});
            break;

            }
        }

   return js.thenApply(fn ->{
      System.out.println(fn);
   })
}

private CompletionStage<HashMap<String, Object>> GetCase1Details(){
   HashMap<String, Object> map = new HashMap<String, Object>();
   //Some stuff
   return map;
}

private CompletionStage<HashMap<String, Object>> GetCase2Details(){
   HashMap<String, Object> map = new HashMap<String, Object>();
   //Some stuff
   return map;
}


0 个答案:

没有答案