2 * Free Telco Dictionary
3 * Copyright © 2013 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package cz.frantovo.telco.dictionary;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.nio.charset.StandardCharsets;
22 import java.util.Objects;
25 * Represents one item in StarDict synonyms file (.syn)
26 * links the synonym term (string) to the position of the base term in index file
28 * @author Ing. František Kučera (frantovo.cz)
30 public class SynonymsEntry implements Comparable<SynonymsEntry> {
32 private IndexEntry base;
35 public SynonymsEntry(IndexEntry base, String name) {
40 public void serialize(DataOutputStream synonymOutputStream) throws IOException {
41 synonymOutputStream.write(name.getBytes(StandardCharsets.UTF_8));
42 synonymOutputStream.write(0);
43 synonymOutputStream.writeInt((int) base.getOrdinal()); // unsigned int 32
47 public int compareTo(SynonymsEntry o) {
48 int nameDiff = name.compareTo(o.name);
50 return base.compareTo(o.base);
57 public boolean equals(Object o) {
58 return o instanceof IndexEntry && compareTo((SynonymsEntry) o) == 0;
62 public int hashCode() {
64 hash = 47 * hash + Objects.hashCode(this.base);
65 hash = 47 * hash + Objects.hashCode(this.name);