package com.hughes.android.dictionary.engine;
+import com.hughes.util.StringUtil;
import com.hughes.util.raf.RAFListSerializer;
import com.hughes.util.raf.RAFSerializable;
import com.ibm.icu.text.Transliterator;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
-import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class PairEntry extends AbstractEntry implements RAFSerializable<PairEntry>,
- Comparable<PairEntry> {
+ Comparable<PairEntry> {
public final List<Pair> pairs;
this.pairs.add(new Pair(lang1, lang2));
}
- public PairEntry(final Dictionary dictionary, final RandomAccessFile raf, final int index)
- throws IOException {
+ public PairEntry(final Dictionary dictionary, final DataInput raf, final int index)
+ throws IOException {
super(dictionary, raf, index);
- final int size = raf.readInt();
+ final int size = dictionary.dictFileVersion >= 7 ? StringUtil.readVarInt(raf) : raf.readInt();
pairs = new ArrayList<PairEntry.Pair>(size);
for (int i = 0; i < size; ++i) {
pairs.add(new Pair(raf.readUTF(), raf.readUTF()));
}
@Override
- public void write(RandomAccessFile raf) throws IOException {
+ public void write(DataOutput raf) throws IOException {
super.write(raf);
- // TODO: this could be a short.
- raf.writeInt(pairs.size());
+ StringUtil.writeVarInt(raf, pairs.size());
for (int i = 0; i < pairs.size(); ++i) {
assert pairs.get(i).lang1.length() > 0;
raf.writeUTF(pairs.get(i).lang1);
}
@Override
- public PairEntry read(RandomAccessFile raf, int index) throws IOException {
+ public PairEntry read(DataInput raf, int index) throws IOException {
return new PairEntry(dictionary, raf, index);
}
@Override
- public void write(RandomAccessFile raf, PairEntry t) throws IOException {
+ public void write(DataOutput raf, PairEntry t) throws IOException {
t.write(raf);
}
- };
+ }
@Override
public void addToDictionary(final Dictionary dictionary) {
public static class Row extends RowBase {
- Row(final RandomAccessFile raf, final int thisRowIndex,
- final Index index) throws IOException {
- super(raf, thisRowIndex, index);
+ Row(final DataInput raf, final int thisRowIndex,
+ final Index index, int extra) throws IOException {
+ super(raf, thisRowIndex, index, extra);
}
Row(final int referenceIndex, final int thisRowIndex,
- final Index index) {
+ final Index index) {
super(referenceIndex, thisRowIndex, index);
}
@Override
public RowMatchType matches(final List<String> searchTokens,
- final Pattern orderedMatchPattern, final Transliterator normalizer,
- final boolean swapPairEntries) {
+ final Pattern orderedMatchPattern, final Transliterator normalizer,
+ final boolean swapPairEntries) {
final int side = swapPairEntries ? 1 : 0;
final List<Pair> pairs = getEntry().pairs;
final String[] pairSides = new String[pairs.size()];
throw new IllegalArgumentException();
}
+ @Override
+ public boolean equals(Object o)
+ {
+ if (o == this) return true;
+ if (!(o instanceof Pair)) return false;
+ Pair p = (Pair)o;
+ return p.lang1.equals(lang1) && p.lang2.equals(lang2);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return (lang1 + "|" + lang2).hashCode();
+ }
}
}