-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathWord.java
61 lines (47 loc) · 1.45 KB
/
Word.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.annimon.java8streamexample;
import com.annimon.stream.Objects;
public final class Word implements Comparable<Word> {
private final String word, translate;
public Word(Word other) {
this.word = other.word;
this.translate = other.translate;
}
public Word(String word, String translate) {
this.word = word;
this.translate = translate;
}
public String getWord() {
return word;
}
public Word setWord(String word) {
return new Word(word, translate);
}
public String getTranslate() {
return translate;
}
public Word setTranslate(String translate) {
return new Word(word, translate);
}
@Override
public int compareTo(Word other) {
int cmp = Objects.compare(word, other.word, String::compareToIgnoreCase);
if (cmp != 0) return cmp;
return Objects.compare(translate, other.translate, String::compareToIgnoreCase);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final Word other = (Word) o;
return Objects.equals(translate, other.translate) &&
Objects.equals(word, other.word);
}
@Override
public int hashCode() {
return Objects.hash(word, translate);
}
@Override
public String toString() {
return word + " — " + translate;
}
}