-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBigram.java
More file actions
43 lines (34 loc) · 810 Bytes
/
Copy pathBigram.java
File metadata and controls
43 lines (34 loc) · 810 Bytes
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
package effect.java.annotation;
import java.util.HashSet;
import java.util.Set;
public class Bigram {
private final char first;
private final char second;
public Bigram(char first, char second) {
this.first = first;
this.second = second;
}
// public boolean equals(Bigram b) {
// return b.first == first && b.second == second;
// }
@Override
public boolean equals(Object o) {
if (!(o instanceof Bigram)) {
return false;
}
Bigram b = (Bigram) o;
return b.first == first && b.second == second;
}
public int hashCode() {
return 31 * first + second;
}
public static void main(String[] args) {
Set<Bigram> s = new HashSet<>();
for (int i =0; i <10; i++) {
for (char ch = 'a'; ch<='z'; ch++) {
s.add(new Bigram(ch,ch));
}
}
System.out.print(s.size());
}
}