package com.hughes.android.dictionary.engine;
-import java.io.IOException;
-import java.io.RandomAccessFile;
import java.util.List;
-import com.hughes.util.raf.RAFSerializable;
public class Dictionary {
// persisted
- List<PairEntry> pairEntries;
+ final List<PairEntry> pairEntries;
// persisted
- List<EntrySource> sources;
-
- // --------------------------------------------------------------------------
+ final List<EntrySource> sources;
- final class Index {
- // One big list!
- // Various sub-types.
- // persisted
- List<Row> rows;
-
- // persisted
- List<IndexEntry> sortedIndexEntries;
-
- Dictionary getDict() {
- return Dictionary.this;
- }
- }
-
- static final class IndexEntry implements RAFSerializable<IndexEntry> {
- String token;
- int startRow;
-
- public void write(RandomAccessFile raf) throws IOException {
- raf.writeUTF(token);
- raf.write(startRow);
- }
- }
+ final List<Index> indices;
}
\ No newline at end of file
--- /dev/null
+/**
+ *
+ */
+package com.hughes.android.dictionary.engine;
+
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.List;
+
+import com.hughes.android.dictionary.engine.Dictionary.Index.IndexEntry;
+import com.hughes.util.raf.RAFSerializable;
+
+final class Index {
+ final Dictionary dict;
+ final String name;
+
+ // One big list!
+ // Various sub-types.
+ // persisted
+ final List<Row> rows;
+
+ // persisted
+ final List<Index.IndexEntry> sortedIndexEntries;
+
+ static final class IndexEntry implements RAFSerializable<Index.IndexEntry> {
+ String token;
+ int startRow;
+
+ public void write(RandomAccessFile raf) throws IOException {
+ raf.writeUTF(token);
+ raf.write(startRow);
+ }
+ }
+}
\ No newline at end of file
public static class Row extends RowWithIndex {
- Row(final RandomAccessFile raf, final int thisRowIndex, final Dictionary.Index index) throws IOException {
+ Row(final RandomAccessFile raf, final int thisRowIndex,
+ final Index index) throws IOException {
super(raf, thisRowIndex, index);
}
public PairEntry getEntry() {
- return index.getDict().pairEntries.get(referenceIndex);
+ return index.dict.pairEntries.get(referenceIndex);
}
}
// dealt with in the normal manner.
static class Serializer implements RAFListSerializer<Row> {
- final Dictionary.Index index;
+ final Index index;
- Serializer(final Dictionary.Index index) {
+ Serializer(final Index index) {
this.index = index;
}
import java.io.RandomAccessFile;
public abstract class RowWithIndex implements Row {
- final Dictionary.Index index;
+ final Index index;
int thisRowIndex;
int referenceIndex;
TokenRow tokenRow = null;
- RowWithIndex(final RandomAccessFile raf, final int thisRowIndex, final Dictionary.Index index) throws IOException {
+ RowWithIndex(final RandomAccessFile raf, final int thisRowIndex, final Index index) throws IOException {
this.index = index;
- this.thisRowIndex = thisRowIndex;
- this.referenceIndex = raf.readInt();
+ this.thisRowIndex = thisRowIndex; // where this was inside the list.
+ this.referenceIndex = raf.readInt(); // what this points to.
}
@Override
public class TokenRow extends RowWithIndex {
- TokenRow(final RandomAccessFile raf, final int thisRowIndex, final Dictionary.Index index) throws IOException {
+ TokenRow(final RandomAccessFile raf, final int thisRowIndex, final Index index) throws IOException {
super(raf, thisRowIndex, index);
}