From 3145e7e6f7ef496b27c9ed87cfd716cd23bf7291 Mon Sep 17 00:00:00 2001 From: Rocky Madden Date: Fri, 26 Oct 2012 19:50:43 -0600 Subject: Code formatting tweaks. --- .../stringmetric/cli/OptionMapUtility.scala | 27 +++++++--------------- .../stringmetric/cli/command/Command.scala | 20 ++++++---------- .../cli/command/diceSorensenMetric.scala | 4 +--- .../stringmetric/cli/command/hammingMetric.scala | 4 +--- .../stringmetric/cli/command/jaroMetric.scala | 4 +--- .../cli/command/jaroWinklerMetric.scala | 4 +--- .../cli/command/levenshteinMetric.scala | 4 +--- .../stringmetric/cli/command/metaphoneMetric.scala | 4 +--- .../stringmetric/cli/command/nysiisMetric.scala | 4 +--- .../stringmetric/cli/command/soundexMetric.scala | 4 +--- 10 files changed, 23 insertions(+), 56 deletions(-) (limited to 'cli/source') diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapUtility.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapUtility.scala index cb13617..0086f84 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapUtility.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapUtility.scala @@ -5,13 +5,9 @@ import scala.collection.immutable.HashMap /** Utility standalone for OptionMap based operations. */ object OptionMapUtility { - def toOptionMap(arguments: Array[String]): OptionMap = { - toOptionMap(arguments.toList) - } + def toOptionMap(arguments: Array[String]): OptionMap = toOptionMap(arguments.toList) - def toOptionMap(arguments: List[String]): OptionMap = { - next(HashMap.empty[Symbol, String], arguments) - } + def toOptionMap(arguments: List[String]): OptionMap = next(HashMap.empty[Symbol, String], arguments) @tailrec private[this] def next(optionMap: OptionMap, arguments: List[String]): OptionMap = { @@ -23,35 +19,28 @@ object OptionMapUtility { // Empty List, return OptionMap. case Nil => optionMap // Double dash options, without value. - case double(name, null) :: tail => { + case double(name, null) :: tail => next(optionMap + (Symbol(name.tail.tail) -> ""), tail) - } // Double dash options, with value. - case double(name, value) :: tail => { + case double(name, value) :: tail => next(optionMap + (Symbol(name.tail.tail) -> value.tail), tail) - } // Single dash options, without value. - case single(name, null) :: tail => { + case single(name, null) :: tail => next(optionMap + (Symbol(name.tail) -> ""), tail) - } // Single dash options, with value. Value is discarded. - case single(name, value) :: tail => { + case single(name, value) :: tail => next(optionMap + (Symbol(name.tail) -> ""), tail) - } // Dashless options. case less(value) :: tail if value.head != '-' => { if (optionMap.contains('dashless)) { val dashless = optionMap('dashless) + " " + value.trim next((optionMap - 'dashless) + ('dashless -> dashless), tail) - } else { + } else next(optionMap + ('dashless -> value.trim), tail) - } } // Invalid option, ignore. - case _ :: tail => { - next(optionMap, tail) - } + case _ :: tail => next(optionMap, tail) } } } \ No newline at end of file diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/Command.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/Command.scala index bac7786..77324b8 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/Command.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/Command.scala @@ -9,26 +9,20 @@ trait Command { def help(): Unit final def error(error: Throwable)(implicit options: OptionMap): Unit = { - if (! isUnitTest(options)) { + if (!isUnitTest(options)) { println(error.getMessage) sys.exit(1) - } else { - throw error - } + } else throw error } def execute(options: OptionMap): Unit - final def exit(implicit options: OptionMap): Unit = { - if (! isUnitTest(options)) sys.exit(0) - } + final def exit(implicit options: OptionMap): Unit = + if (!isUnitTest(options)) sys.exit(0) - protected[this] def isUnitTest(options: OptionMap): Boolean = { + protected[this] def isUnitTest(options: OptionMap): Boolean = (options.contains('ut) || (options.contains('unitTest) && options.get('unitTest) != "false")) - } - protected[this] def isDebug(options: OptionMap): Boolean = { + protected[this] def isDebug(options: OptionMap): Boolean = (options.contains('d) || (options.contains('debug) && options.get('debug) != "false")) - } -} - +} \ No newline at end of file diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/diceSorensenMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/diceSorensenMetric.scala index bddae46..d1e7d32 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/diceSorensenMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/diceSorensenMetric.scala @@ -23,9 +23,7 @@ object diceSorensenMetric extends Command { execute(options) exit(options) // Invalid syntax. - } else { - throw new IllegalArgumentException("Expected valid syntax. See --help.") - } + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") } catch { case e => error(e)(options) } diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/hammingMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/hammingMetric.scala index cdb1864..b336cf5 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/hammingMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/hammingMetric.scala @@ -23,9 +23,7 @@ object hammingMetric extends Command { execute(options) exit(options) // Invalid syntax. - } else { - throw new IllegalArgumentException("Expected valid syntax. See --help.") - } + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") } catch { case e => error(e)(options) } diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala index 7e9fa07..cb12910 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala @@ -23,9 +23,7 @@ object jaroMetric extends Command { execute(options) exit(options) // Invalid syntax. - } else { - throw new IllegalArgumentException("Expected valid syntax. See --help.") - } + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") } catch { case e => error(e)(options) } diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala index bfaa7e9..75ddc8b 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala @@ -23,9 +23,7 @@ object jaroWinklerMetric extends Command { execute(options) exit(options) // Invalid syntax. - } else { - throw new IllegalArgumentException("Expected valid syntax. See --help.") - } + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") } catch { case e => error(e)(options) } diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/levenshteinMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/levenshteinMetric.scala index 1364a5a..7044062 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/levenshteinMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/levenshteinMetric.scala @@ -23,9 +23,7 @@ object levenshteinMetric extends Command { execute(options) exit(options) // Invalid syntax. - } else { - throw new IllegalArgumentException("Expected valid syntax. See --help.") - } + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") } catch { case e => error(e)(options) } diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/metaphoneMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/metaphoneMetric.scala index 6e46de9..1d0b174 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/metaphoneMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/metaphoneMetric.scala @@ -23,9 +23,7 @@ object metaphoneMetric extends Command { execute(options) exit(options) // Invalid syntax. - } else { - throw new IllegalArgumentException("Expected valid syntax. See --help.") - } + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") } catch { case e => error(e)(options) } diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/nysiisMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/nysiisMetric.scala index d49b99e..741cea2 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/nysiisMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/nysiisMetric.scala @@ -23,9 +23,7 @@ object nysiisMetric extends Command { execute(options) exit(options) // Invalid syntax. - } else { - throw new IllegalArgumentException("Expected valid syntax. See --help.") - } + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") } catch { case e => error(e)(options) } diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/soundexMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/soundexMetric.scala index c9590c3..b49eadc 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/soundexMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/soundexMetric.scala @@ -23,9 +23,7 @@ object soundexMetric extends Command { execute(options) exit(options) // Invalid syntax. - } else { - throw new IllegalArgumentException("Expected valid syntax. See --help.") - } + } else throw new IllegalArgumentException("Expected valid syntax. See --help.") } catch { case e => error(e)(options) } -- cgit v1.2.3