diff -r 939fa8d8663e -r b188eae2c092 java/dictionary-generator/src/cz/frantovo/telco/dictionary/SynonymsEntry.java --- a/java/dictionary-generator/src/cz/frantovo/telco/dictionary/SynonymsEntry.java Tue Jul 09 22:41:49 2013 +0200 +++ b/java/dictionary-generator/src/cz/frantovo/telco/dictionary/SynonymsEntry.java Tue Jul 09 22:42:32 2013 +0200 @@ -17,14 +17,51 @@ */ package cz.frantovo.telco.dictionary; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Objects; + /** * * @author Ing. František Kučera (frantovo.cz) */ public class SynonymsEntry implements Comparable { + private IndexEntry base; + private String name; + + public SynonymsEntry(IndexEntry base, String name) { + this.base = base; + this.name = name; + } + + public void serialize(DataOutputStream synonymOutputStream) throws IOException { + synonymOutputStream.write(name.getBytes(StandardCharsets.UTF_8)); + synonymOutputStream.write(0); + synonymOutputStream.writeInt((int) base.getOrdinal()); // unsigned int 32 + } + @Override public int compareTo(SynonymsEntry o) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + int nameDiff = name.compareTo(o.name); + if (nameDiff == 0) { + return base.compareTo(o.base); + } else { + return nameDiff; + } + } + + @Override + public boolean equals(Object o) { + return o instanceof IndexEntry && compareTo((SynonymsEntry) o) == 0; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 47 * hash + Objects.hashCode(this.base); + hash = 47 * hash + Objects.hashCode(this.name); + return hash; } }