You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@griffin.apache.org by gu...@apache.org on 2018/07/30 01:00:50 UTC
incubator-griffin git commit: Fix code bug and improve code quality
Repository: incubator-griffin
Updated Branches:
refs/heads/master 1c4e8ca01 -> 1374427fb
Fix code bug and improve code quality
Author: Eugene <to...@163.com>
Closes #375 from toyboxman/measure/fix.
Project: http://git-wip-us.apache.org/repos/asf/incubator-griffin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-griffin/commit/1374427f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-griffin/tree/1374427f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-griffin/diff/1374427f
Branch: refs/heads/master
Commit: 1374427fb751561f9a543745f5dfb62c3bb8ebcd
Parents: 1c4e8ca
Author: Eugene <to...@163.com>
Authored: Mon Jul 30 09:00:34 2018 +0800
Committer: William Guo <gu...@apache.org>
Committed: Mon Jul 30 09:00:34 2018 +0800
----------------------------------------------------------------------
.../griffin/measure/utils/ParamUtil.scala | 64 ++++++++------------
1 file changed, 26 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/1374427f/measure/src/main/scala/org/apache/griffin/measure/utils/ParamUtil.scala
----------------------------------------------------------------------
diff --git a/measure/src/main/scala/org/apache/griffin/measure/utils/ParamUtil.scala b/measure/src/main/scala/org/apache/griffin/measure/utils/ParamUtil.scala
index 6f86e7d..fccbfb5 100644
--- a/measure/src/main/scala/org/apache/griffin/measure/utils/ParamUtil.scala
+++ b/measure/src/main/scala/org/apache/griffin/measure/utils/ParamUtil.scala
@@ -40,24 +40,24 @@ object ParamUtil {
def getString(key: String, defValue: String): String = {
try {
params.get(key) match {
- case Some(v: String) => v.toString
+ case Some(v: String) => v
case Some(v) => v.toString
case _ => defValue
}
} catch {
- case _: Throwable => defValue
+ case _: NumberFormatException => defValue
}
}
def getLazyString(key: String, defValue: () => String): String = {
try {
params.get(key) match {
- case Some(v: String) => v.toString
+ case Some(v: String) => v
case Some(v) => v.toString
case _ => defValue()
}
} catch {
- case _: Throwable => defValue()
+ case _: NumberFormatException => defValue()
}
}
@@ -67,7 +67,7 @@ object ParamUtil {
try {
params.get(key) match {
case Some(v: String) => v.toByte
- case Some(v: Byte) => v.toByte
+ case Some(v: Byte) => v
case Some(v: Short) => v.toByte
case Some(v: Int) => v.toByte
case Some(v: Long) => v.toByte
@@ -76,7 +76,7 @@ object ParamUtil {
case _ => defValue
}
} catch {
- case _: Throwable => defValue
+ case _: NumberFormatException => defValue
}
}
@@ -85,7 +85,7 @@ object ParamUtil {
params.get(key) match {
case Some(v: String) => v.toShort
case Some(v: Byte) => v.toShort
- case Some(v: Short) => v.toShort
+ case Some(v: Short) => v
case Some(v: Int) => v.toShort
case Some(v: Long) => v.toShort
case Some(v: Float) => v.toShort
@@ -93,7 +93,7 @@ object ParamUtil {
case _ => defValue
}
} catch {
- case _: Throwable => defValue
+ case _: NumberFormatException => defValue
}
}
@@ -103,14 +103,14 @@ object ParamUtil {
case Some(v: String) => v.toInt
case Some(v: Byte) => v.toInt
case Some(v: Short) => v.toInt
- case Some(v: Int) => v.toInt
+ case Some(v: Int) => v
case Some(v: Long) => v.toInt
case Some(v: Float) => v.toInt
case Some(v: Double) => v.toInt
case _ => defValue
}
} catch {
- case _: Throwable => defValue
+ case _: NumberFormatException => defValue
}
}
@@ -121,13 +121,13 @@ object ParamUtil {
case Some(v: Byte) => v.toLong
case Some(v: Short) => v.toLong
case Some(v: Int) => v.toLong
- case Some(v: Long) => v.toLong
+ case Some(v: Long) => v
case Some(v: Float) => v.toLong
case Some(v: Double) => v.toLong
case _ => defValue
}
} catch {
- case _: Throwable => defValue
+ case _: NumberFormatException => defValue
}
}
@@ -139,12 +139,12 @@ object ParamUtil {
case Some(v: Short) => v.toFloat
case Some(v: Int) => v.toFloat
case Some(v: Long) => v.toFloat
- case Some(v: Float) => v.toFloat
+ case Some(v: Float) => v
case Some(v: Double) => v.toFloat
case _ => defValue
}
} catch {
- case _: Throwable => defValue
+ case _: NumberFormatException => defValue
}
}
@@ -157,11 +157,11 @@ object ParamUtil {
case Some(v: Int) => v.toDouble
case Some(v: Long) => v.toDouble
case Some(v: Float) => v.toDouble
- case Some(v: Double) => v.toDouble
+ case Some(v: Double) => v
case _ => defValue
}
} catch {
- case _: Throwable => defValue
+ case _: NumberFormatException => defValue
}
}
@@ -173,42 +173,30 @@ object ParamUtil {
case _ => defValue
}
} catch {
- case _: Throwable => defValue
+ case _: NumberFormatException => defValue
}
}
case class StringAnyMap(values:Map[String,Any])
def getParamMap(key: String, defValue: Map[String, Any] = Map[String, Any]()): Map[String, Any] = {
- try {
- params.get(key) match {
- case Some(v: StringAnyMap) => v.values
- case _ => defValue
- }
- } catch {
- case _: Throwable => defValue
+ params.get(key) match {
+ case Some(v: StringAnyMap) => v.values
+ case _ => defValue
}
}
def getParamMapOpt(key: String): Option[Map[String, Any]] = {
- try {
- params.get(key) match {
- case Some(v: StringAnyMap) => Some(v.values)
- case _ => None
- }
- } catch {
- case _: Throwable => None
+ params.get(key) match {
+ case Some(v: StringAnyMap) => Some(v.values)
+ case _ => None
}
}
def getArr[T](key: String): Seq[T] = {
case class TSeqs(values:Seq[T])
- try {
- params.get(key) match {
- case Some(seq: TSeqs) => seq.values
- case _ => Nil
- }
- } catch {
- case _: Throwable => Nil
+ params.get(key) match {
+ case Some(seq: TSeqs) => seq.values
+ case _ => Nil
}
}