-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordSet.java
More file actions
45 lines (41 loc) · 1.41 KB
/
WordSet.java
File metadata and controls
45 lines (41 loc) · 1.41 KB
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
import java.util.*;
public class WordSet<K extends Comparable<K>, V> implements Counter<K, V> {
public String get(K word) {
//Enter code here
StringBuilder words = new StringBuilder();
words.append(count.get(word).toString() + ",");
for(V w: map.get(word)){
words.append(w + ",");
}
words.replace(words.length()-1,words.length(),"");
return words.toString();
}
public int getCount(K word) {
//Enter code here
//fine
return count.get(word);
}
public Set<K> keySet() {
//Enter code here
return map.keySet();
}
public void put(K keyWord, V word) {
//Enter code here
if(!map.containsKey(keyWord)){
set = new HashSet<>();
set.add(word);
map.put(keyWord, set);
count.put(keyWord,1);
}
else if(map.containsKey(keyWord)){
map.get(keyWord).add(word);
count.put(keyWord, count.get(keyWord) + 1);
}
//System.out.println(map.get(keyWord));
//System.out.println(count.get(keyWord));
}
// declare any required instance variables or helpful auxiliary types and methods here
Map<K, Set<V>> map = new HashMap<>();
Set<V> set = new HashSet<>();
Map<K, Integer> count = new HashMap<>();
}