From 8b8ce923a152c9395f4af52ad27104fc5c1c6512 Mon Sep 17 00:00:00 2001 From: Rocky Madden Date: Mon, 19 Nov 2012 20:07:48 -0700 Subject: More idiomatic code. --- .../org/hashtree/stringmetric/phonetic/Alphabet.scala | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'core') diff --git a/core/source/core/scala/org/hashtree/stringmetric/phonetic/Alphabet.scala b/core/source/core/scala/org/hashtree/stringmetric/phonetic/Alphabet.scala index fd94e75..e6b1c0e 100755 --- a/core/source/core/scala/org/hashtree/stringmetric/phonetic/Alphabet.scala +++ b/core/source/core/scala/org/hashtree/stringmetric/phonetic/Alphabet.scala @@ -3,27 +3,13 @@ package org.hashtree.stringmetric.phonetic import scala.annotation.tailrec object Alphabet { - final val SometimesVowels: Set[Char] = Set('a', 'e', 'i', 'o', 'u', 'y') - final val Vowels: Set[Char] = Set('a', 'e', 'i', 'o', 'u') - def is(char: Char): Boolean = (char >= 65 && char <= 90) || (char >= 97 && char <= 122) - def is(charArray: Array[Char]): Boolean = { - @tailrec - def still(ca: Seq[Char]): Boolean = - if (ca.length == 0) true - else - if (!is(ca.head)) false - else still(ca.tail) - - if (charArray.length == 0) false - else if (charArray.length <= 4) still(charArray) - else still(charArray.toList) - } + def is(charArray: Array[Char]): Boolean = charArray.length > 0 && !charArray.find(!is(_)).isDefined def is(string: String): Boolean = is(string.toCharArray) - def isSometimesVowel(char: Char): Boolean = (char == 'y' || char == 'Y' || isVowel(char)) + def isSometimesVowel(char: Char): Boolean = char == 'y' || char == 'Y' || isVowel(char) def isVowel(char: Char): Boolean = ( char == 'a' || char == 'e' || char == 'i' || char == 'o' || char =='u' -- cgit v1.2.3