scala match的运用

来源:互联网 发布:三国志11全人物数据 编辑:程序博客网 时间:2024/06/04 22:30

单个变量

        var clusterManager: Int = arg match {            case "yarn" => YARN            case "yarn-client" | "yarn-cluster" =>                println(s"Master ${arg} is deprecated since 2.0." +                    " Please use master \"yarn\" with specified deploy mode instead.")                YARN            case m if m.startsWith("spark") => STANDALONE            case m if m.startsWith("mesos") => MESOS            case m if m.startsWith("local") => LOCAL            case _ =>                println("Master must either be yarn or start with spark, mesos, local")                -1        }

多个变量

      (args.master, args.deployMode) match {        case ("yarn-cluster", null) =>          deployMode = CLUSTER          args.master = "yarn"        case ("yarn-cluster", "client") =>          printErrorAndExit("Client deploy mode is not compatible with master \"yarn-cluster\"")        case ("yarn-client", "cluster") =>          printErrorAndExit("Cluster deploy mode is not compatible with master \"yarn-client\"")        case (_, mode) =>          args.master = "yarn"      }
0 0