-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dictionary.java
37 lines (32 loc) · 858 Bytes
/
Dictionary.java
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
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashSet;
/**
* Dictionary class.
*/
public class Dictionary {
private HashSet<String> words;
/**
* Default constructor.
*
* @param words {@link java.util.Set} of words for dictionary.
*/
public Dictionary(HashSet<String> words) {
this.words = words;
}
Dictionary(Path file) {
try {
this.words = new HashSet<>(Arrays.asList(Files.readString(file).split(" ")));
} catch (IOException e) {
System.err.println("ERROR: I/O Exception with input file for dictionary: " + e.getMessage());
}
}
HashSet<String> getWords() {
return words;
}
boolean contains(String word) {
return words.contains(word);
}
}