java/dictionary-generator/src/cz/frantovo/telco/dictionary/SynonymsEntry.java
changeset 17 b188eae2c092
parent 15 93208f791318
child 130 b8dc8a6f82cf
     1.1 --- a/java/dictionary-generator/src/cz/frantovo/telco/dictionary/SynonymsEntry.java	Tue Jul 09 22:41:49 2013 +0200
     1.2 +++ b/java/dictionary-generator/src/cz/frantovo/telco/dictionary/SynonymsEntry.java	Tue Jul 09 22:42:32 2013 +0200
     1.3 @@ -17,14 +17,51 @@
     1.4   */
     1.5  package cz.frantovo.telco.dictionary;
     1.6  
     1.7 +import java.io.DataOutputStream;
     1.8 +import java.io.IOException;
     1.9 +import java.nio.charset.StandardCharsets;
    1.10 +import java.util.Objects;
    1.11 +
    1.12  /**
    1.13   *
    1.14   * @author Ing. František Kučera (frantovo.cz)
    1.15   */
    1.16  public class SynonymsEntry implements Comparable<SynonymsEntry> {
    1.17  
    1.18 +	private IndexEntry base;
    1.19 +	private String name;
    1.20 +
    1.21 +	public SynonymsEntry(IndexEntry base, String name) {
    1.22 +		this.base = base;
    1.23 +		this.name = name;
    1.24 +	}
    1.25 +
    1.26 +	public void serialize(DataOutputStream synonymOutputStream) throws IOException {
    1.27 +		synonymOutputStream.write(name.getBytes(StandardCharsets.UTF_8));
    1.28 +		synonymOutputStream.write(0);
    1.29 +		synonymOutputStream.writeInt((int) base.getOrdinal()); // unsigned int 32
    1.30 +	}
    1.31 +
    1.32  	@Override
    1.33  	public int compareTo(SynonymsEntry o) {
    1.34 -		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    1.35 +		int nameDiff = name.compareTo(o.name);
    1.36 +		if (nameDiff == 0) {
    1.37 +			return base.compareTo(o.base);
    1.38 +		} else {
    1.39 +			return nameDiff;
    1.40 +		}
    1.41 +	}
    1.42 +
    1.43 +	@Override
    1.44 +	public boolean equals(Object o) {
    1.45 +		return o instanceof IndexEntry && compareTo((SynonymsEntry) o) == 0;
    1.46 +	}
    1.47 +
    1.48 +	@Override
    1.49 +	public int hashCode() {
    1.50 +		int hash = 3;
    1.51 +		hash = 47 * hash + Objects.hashCode(this.base);
    1.52 +		hash = 47 * hash + Objects.hashCode(this.name);
    1.53 +		return hash;
    1.54  	}
    1.55  }