X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fengine%2FTextEntry.java;h=1856753da87f24c430e5a6e53445ed265506c49d;hb=5f7b259669237dad4cbfdec8536537815846979b;hp=8bef29482ec67c1cc65c2901f778829023a0e9d1;hpb=f16d8ed40c49c70cf6c4e80e0392f9c01793cd25;p=Dictionary.git diff --git a/src/com/hughes/android/dictionary/engine/TextEntry.java b/src/com/hughes/android/dictionary/engine/TextEntry.java index 8bef294..1856753 100644 --- a/src/com/hughes/android/dictionary/engine/TextEntry.java +++ b/src/com/hughes/android/dictionary/engine/TextEntry.java @@ -14,75 +14,91 @@ package com.hughes.android.dictionary.engine; +import java.io.DataInput; +import java.io.DataOutput; import java.io.IOException; import java.io.PrintStream; -import java.io.RandomAccessFile; - -import com.hughes.util.raf.RAFSerializable; -import com.hughes.util.raf.RAFSerializer; - -public class TextEntry extends AbstractEntry implements RAFSerializable { - - final String text; - - public TextEntry(final Dictionary dictionary, final RandomAccessFile raf) throws IOException { - super(dictionary, raf); - text = raf.readUTF(); - } - @Override - public void write(RandomAccessFile raf) throws IOException { - super.write(raf); - raf.writeUTF(text); - } - - static final class Serializer implements RAFSerializer { - - final Dictionary dictionary; - - Serializer(Dictionary dictionary) { - this.dictionary = dictionary; - } +import java.util.List; +import java.util.regex.Pattern; - @Override - public TextEntry read(RandomAccessFile raf) throws IOException { - return new TextEntry(dictionary, raf); +import com.hughes.util.raf.RAFListSerializer; +import com.ibm.icu.text.Transliterator; + +public class TextEntry extends AbstractEntry { + + public final String text; + + private TextEntry(final Dictionary dictionary, final DataInput raf, final int index) + throws IOException { + super(dictionary, raf, index); + text = raf.readUTF(); + throw new RuntimeException("TextEntry constructor should be unreachable"); } @Override - public void write(RandomAccessFile raf, TextEntry t) throws IOException { - t.write(raf); + public void write(DataOutput raf) throws IOException { + super.write(raf); + raf.writeUTF(text); } - }; - - - @Override - public int addToDictionary(final Dictionary dictionary) { - dictionary.textEntries.add(this); - return dictionary.textEntries.size() - 1; - } - - public static class Row extends RowBase { - - Row(final RandomAccessFile raf, final int thisRowIndex, - final Index index) throws IOException { - super(raf, thisRowIndex, index); - } - - public TextEntry getEntry() { - return index.dict.textEntries.get(referenceIndex); + + static final class Serializer implements RAFListSerializer { + + final Dictionary dictionary; + + Serializer(Dictionary dictionary) { + this.dictionary = dictionary; + } + + @Override + public TextEntry read(DataInput raf, final int index) throws IOException { + return new TextEntry(dictionary, raf, index); + } + + @Override + public void write(DataOutput raf, TextEntry t) throws IOException { + t.write(raf); + } } - + @Override - public void print(PrintStream out) { - out.println(" " + getEntry().text); + public void addToDictionary(final Dictionary dictionary) { + assert index == -1; + dictionary.textEntries.add(this); + index = dictionary.textEntries.size() - 1; } @Override - public String getRawText(boolean compact) { - return getEntry().text; + public RowBase CreateRow(int rowIndex, Index dictionaryIndex) { + throw new UnsupportedOperationException("TextEntry's don't really exist."); } - } + public static class Row extends RowBase { + + Row(final DataInput raf, final int thisRowIndex, + final Index index, int extra) throws IOException { + super(raf, thisRowIndex, index, extra); + } + TextEntry getEntry() { + return index.dict.textEntries.get(referenceIndex); + } + + @Override + public void print(PrintStream out) { + out.println(" " + getEntry().text); + } + + @Override + public String getRawText(boolean compact) { + return getEntry().text; + } + + @Override + public RowMatchType matches(final List searchTokens, + final Pattern orderedMatchPattern, Transliterator normalizer, + boolean swapPairEntries) { + return null; + } + } }