-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWordMap.pde
60 lines (45 loc) · 1.14 KB
/
WordMap.pde
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Code from Visualizing Data, First Edition, Copyright 2008 Ben Fry.
class WordMap extends SimpleMapModel {
HashMap words;
int scanSampled;
int sampleYear;
WordMap(int year) {
words = new HashMap();
sampleYear = year;
}
void addWord(String word) {
WordItem item = (WordItem) words.get(word);
if (item == null) {
item = new WordItem(word, sampleYear);
words.put(word, item);
}
item.incrementSize();
}
void setscanSampled(int s) {
scanSampled = s;
}
int getscanSampled() {
return this.scanSampled;
}
void finishAdd() {
items = new WordItem[words.size()];
words.values().toArray(items);
}
void putWord (String word, WordItem wordItem) {
words.put(word, wordItem);
}
void inputWord(String word, int frequency) {
WordItem w = new WordItem(word, sampleYear);
w.setSize(frequency);
this.putWord(word, w);
}
WordItem getWordItem(String word) {
return (WordItem) words.get(word);
}
boolean containsWord(String word) {
return words.containsKey(word);
}
boolean isEmpty() {
return words.isEmpty();
}
}