diff -r 939fa8d8663e -r b188eae2c092 java/dictionary-generator/src/cz/frantovo/telco/dictionary/IndexEntry.java --- a/java/dictionary-generator/src/cz/frantovo/telco/dictionary/IndexEntry.java Tue Jul 09 22:41:49 2013 +0200 +++ b/java/dictionary-generator/src/cz/frantovo/telco/dictionary/IndexEntry.java Tue Jul 09 22:42:32 2013 +0200 @@ -17,14 +17,69 @@ */ 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 IndexEntry implements Comparable { + private String name; + private long offset; + private long length; + private long ordinal; + + public IndexEntry(String name, long offset, long length) { + this.name = name; + this.offset = offset; + this.length = length; + } + + public void serialize(DataOutputStream indexOutputStream) throws IOException { + indexOutputStream.write(name.getBytes(StandardCharsets.UTF_8)); + indexOutputStream.write(0); + indexOutputStream.writeInt((int) offset); // unsigned int 32 + indexOutputStream.writeInt((int) length); // unsigned int 32 + } + + public void setOrdinal(long ordinal) { + this.ordinal = ordinal; + } + + public long getOrdinal() { + return ordinal; + } + @Override public int compareTo(IndexEntry 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) { + int offsetDiff = ((Long) offset).compareTo(o.offset); + if (offsetDiff == 0) { + return ((Long) length).compareTo(o.length); + } else { + return offsetDiff; + } + } else { + return nameDiff; + } + } + + @Override + public boolean equals(Object o) { + return o instanceof IndexEntry && compareTo((IndexEntry) o) == 0; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 53 * hash + Objects.hashCode(this.name); + hash = 53 * hash + (int) (this.offset ^ (this.offset >>> 32)); + hash = 53 * hash + (int) (this.length ^ (this.length >>> 32)); + return hash; } }