From 8d1e80ff34836308a0b0331b012d961d4f08db28 Mon Sep 17 00:00:00 2001 From: Rocky Madden Date: Mon, 5 Nov 2012 18:49:06 -0700 Subject: Added overloaded methods for long and short. --- .../hashtree/stringmetric/cli/ParseUtility.scala | 4 ++++ .../stringmetric/cli/ParseUtilitySpec.scala | 24 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'cli/source') diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/ParseUtility.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/ParseUtility.scala index 94f22c6..f2975d9 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/ParseUtility.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/ParseUtility.scala @@ -11,4 +11,8 @@ object ParseUtility { def parseFloat(string: String): Option[Float] = try { Some(string.toFloat) } catch { case _ => None } def parseInt(string: String): Option[Int] = try { Some(string.toInt) } catch { case _ => None } + + def parseLong(string: String): Option[Long] = try { Some(string.toLong) } catch { case _ => None } + + def parseShort(string: String): Option[Short] = try { Some(string.toShort) } catch { case _ => None } } \ No newline at end of file diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/ParseUtilitySpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/ParseUtilitySpec.scala index 686f3da..f265c54 100755 --- a/cli/source/test/scala/org/hashtree/stringmetric/cli/ParseUtilitySpec.scala +++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/ParseUtilitySpec.scala @@ -56,5 +56,29 @@ final class ParseUtilitySpec extends ScalaTest { } } } + "parseLong method" when passed { + "invalid argument" should returns { + "None" in { + ParseUtility.parseLong("one").isDefined should be (false) + } + } + "valid argument" should returns { + "Some(Long)" in { + ParseUtility.parseLong("1").get should be (1l) + } + } + } + "parseShort method" when passed { + "invalid argument" should returns { + "None" in { + ParseUtility.parseShort("one").isDefined should be (false) + } + } + "valid argument" should returns { + "Some(Short)" in { + ParseUtility.parseShort("1").get should equal (1: Short) + } + } + } } } \ No newline at end of file -- cgit v1.2.3