1 | |
package org.jtheque.core.utils.db; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.jtheque.core.managers.Managers; |
20 | |
import org.jtheque.core.managers.language.ILanguageManager; |
21 | |
import org.jtheque.core.utils.db.DaoNotes.NoteType; |
22 | |
import org.jtheque.utils.Constants; |
23 | |
import org.jtheque.utils.bean.EqualsUtils; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public final class NoteImpl implements Note { |
31 | |
private final String key; |
32 | |
private final NoteType value; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public NoteImpl(NoteType value, String key) { |
41 | 34 | super(); |
42 | |
|
43 | 34 | this.value = value; |
44 | 34 | this.key = key; |
45 | 34 | } |
46 | |
|
47 | |
@Override |
48 | |
public String getInternationalizedText() { |
49 | 0 | return Managers.getManager(ILanguageManager.class).getMessage(key); |
50 | |
} |
51 | |
|
52 | |
@Override |
53 | |
public String toString() { |
54 | 0 | return getInternationalizedText(); |
55 | |
} |
56 | |
|
57 | |
@Override |
58 | |
public int hashCode() { |
59 | 40 | int result = Constants.HASH_CODE_START; |
60 | |
|
61 | 40 | result = Constants.HASH_CODE_PRIME * result + value.intValue(); |
62 | 40 | result = Constants.HASH_CODE_PRIME * result + (key == null ? 0 : key.hashCode()); |
63 | |
|
64 | 40 | return result; |
65 | |
} |
66 | |
|
67 | |
@Override |
68 | |
public boolean equals(Object obj) { |
69 | 30 | if (this == obj) { |
70 | 10 | return true; |
71 | |
} |
72 | |
|
73 | 20 | if (EqualsUtils.areObjectIncompatible(this, obj)) { |
74 | 0 | return false; |
75 | |
} |
76 | |
|
77 | 20 | final NoteImpl other = (NoteImpl) obj; |
78 | |
|
79 | 20 | if (value != other.value) { |
80 | 12 | return false; |
81 | |
} |
82 | |
|
83 | 8 | return !EqualsUtils.areNotEquals(key, other.key); |
84 | |
|
85 | |
} |
86 | |
|
87 | |
@Override |
88 | |
public String getElementName() { |
89 | 0 | return getInternationalizedText(); |
90 | |
} |
91 | |
|
92 | |
@Override |
93 | |
public NoteType getValue() { |
94 | 70 | return value; |
95 | |
} |
96 | |
} |