-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwoDataStructuresDict.scala
46 lines (38 loc) · 1.43 KB
/
TwoDataStructuresDict.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package dictionary
import dictionary.searcher._
import dictionary.suggester._
class TwoDataStructuresDict extends Dictionary {
private var searcher: Option[Searcher] = None
private var suggester: Option[Suggester] = None
def contains(word: String): Boolean =
searcher match {
case Some(s) => s.contains(word)
case None => throw UninitializedFieldError("Uninititalized Searcher!")
}
def insert(word: String): Unit = {
searcher match {
case Some(s) => s.insert(word)
case None => throw UninitializedFieldError("Uninititalized Searcher!")
}
suggester match {
case Some(s) => s.insert(word)
case None => throw UninitializedFieldError("Uninititalized Suggester!")
}
}
def getSuggestion(word: String, maximumSuggestion: Int): Seq[String] =
suggester match {
case Some(s) => s.getSuggestion(word).take(maximumSuggestion)
case None => throw UninitializedFieldError("Uninititalized Suggester!")
}
def getName: String = "Two Data Structures"
def setSearcher(newSearcher: Searcher): Unit =
searcher match {
case Some(s) => s.transfer(newSearcher); searcher = Some(newSearcher);
case None => searcher = Some(newSearcher);
}
def setSuggester(newSuggester: Suggester): Unit =
suggester match {
case Some(s) => s.transfer(newSuggester); suggester = Some(newSuggester);
case None => suggester = Some(newSuggester);
}
}