author | František Kučera <franta-hg@frantovo.cz> |
Mon, 19 Aug 2013 18:34:11 +0200 | |
changeset 122 | 69bedd6a1d1a |
parent 17 | b188eae2c092 |
child 130 | b8dc8a6f82cf |
permissions | -rw-r--r-- |
franta-hg@15 | 1 |
/** |
franta-hg@15 | 2 |
* Free Telco Dictionary |
franta-hg@15 | 3 |
* Copyright © 2013 František Kučera (frantovo.cz) |
franta-hg@15 | 4 |
* |
franta-hg@15 | 5 |
* This program is free software: you can redistribute it and/or modify |
franta-hg@15 | 6 |
* it under the terms of the GNU General Public License as published by |
franta-hg@15 | 7 |
* the Free Software Foundation, either version 3 of the License, or |
franta-hg@15 | 8 |
* (at your option) any later version. |
franta-hg@15 | 9 |
* |
franta-hg@15 | 10 |
* This program is distributed in the hope that it will be useful, |
franta-hg@15 | 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
franta-hg@15 | 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
franta-hg@15 | 13 |
* GNU General Public License for more details. |
franta-hg@15 | 14 |
* |
franta-hg@15 | 15 |
* You should have received a copy of the GNU General Public License |
franta-hg@15 | 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
franta-hg@15 | 17 |
*/ |
franta-hg@15 | 18 |
package cz.frantovo.telco.dictionary; |
franta-hg@15 | 19 |
|
franta-hg@17 | 20 |
import java.io.DataOutputStream; |
franta-hg@17 | 21 |
import java.io.IOException; |
franta-hg@17 | 22 |
import java.nio.charset.StandardCharsets; |
franta-hg@17 | 23 |
import java.util.Objects; |
franta-hg@17 | 24 |
|
franta-hg@15 | 25 |
/** |
franta-hg@15 | 26 |
* |
franta-hg@15 | 27 |
* @author Ing. František Kučera (frantovo.cz) |
franta-hg@15 | 28 |
*/ |
franta-hg@15 | 29 |
public class SynonymsEntry implements Comparable<SynonymsEntry> { |
franta-hg@15 | 30 |
|
franta-hg@17 | 31 |
private IndexEntry base; |
franta-hg@17 | 32 |
private String name; |
franta-hg@17 | 33 |
|
franta-hg@17 | 34 |
public SynonymsEntry(IndexEntry base, String name) { |
franta-hg@17 | 35 |
this.base = base; |
franta-hg@17 | 36 |
this.name = name; |
franta-hg@17 | 37 |
} |
franta-hg@17 | 38 |
|
franta-hg@17 | 39 |
public void serialize(DataOutputStream synonymOutputStream) throws IOException { |
franta-hg@17 | 40 |
synonymOutputStream.write(name.getBytes(StandardCharsets.UTF_8)); |
franta-hg@17 | 41 |
synonymOutputStream.write(0); |
franta-hg@17 | 42 |
synonymOutputStream.writeInt((int) base.getOrdinal()); // unsigned int 32 |
franta-hg@17 | 43 |
} |
franta-hg@17 | 44 |
|
franta-hg@15 | 45 |
@Override |
franta-hg@15 | 46 |
public int compareTo(SynonymsEntry o) { |
franta-hg@17 | 47 |
int nameDiff = name.compareTo(o.name); |
franta-hg@17 | 48 |
if (nameDiff == 0) { |
franta-hg@17 | 49 |
return base.compareTo(o.base); |
franta-hg@17 | 50 |
} else { |
franta-hg@17 | 51 |
return nameDiff; |
franta-hg@17 | 52 |
} |
franta-hg@17 | 53 |
} |
franta-hg@17 | 54 |
|
franta-hg@17 | 55 |
@Override |
franta-hg@17 | 56 |
public boolean equals(Object o) { |
franta-hg@17 | 57 |
return o instanceof IndexEntry && compareTo((SynonymsEntry) o) == 0; |
franta-hg@17 | 58 |
} |
franta-hg@17 | 59 |
|
franta-hg@17 | 60 |
@Override |
franta-hg@17 | 61 |
public int hashCode() { |
franta-hg@17 | 62 |
int hash = 3; |
franta-hg@17 | 63 |
hash = 47 * hash + Objects.hashCode(this.base); |
franta-hg@17 | 64 |
hash = 47 * hash + Objects.hashCode(this.name); |
franta-hg@17 | 65 |
return hash; |
franta-hg@15 | 66 |
} |
franta-hg@15 | 67 |
} |