From 1adc593498a8fba745f6c433fdc0ddde26bd379f Mon Sep 17 00:00:00 2001 From: Thad Hughes Date: Fri, 23 Jul 2010 18:10:52 -0700 Subject: [PATCH] go --- .../android/dictionary/engine/Dictionary.java | 33 ++---------------- .../android/dictionary/engine/Index.java | 34 +++++++++++++++++++ .../android/dictionary/engine/PairEntry.java | 5 +-- .../hughes/android/dictionary/engine/Row.java | 4 +-- .../dictionary/engine/RowWithIndex.java | 8 ++--- .../android/dictionary/engine/TokenRow.java | 2 +- 6 files changed, 47 insertions(+), 39 deletions(-) create mode 100644 src/com/hughes/android/dictionary/engine/Index.java diff --git a/src/com/hughes/android/dictionary/engine/Dictionary.java b/src/com/hughes/android/dictionary/engine/Dictionary.java index 8f1db2d..861ba43 100644 --- a/src/com/hughes/android/dictionary/engine/Dictionary.java +++ b/src/com/hughes/android/dictionary/engine/Dictionary.java @@ -1,44 +1,17 @@ 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 pairEntries; + final List pairEntries; // persisted - List sources; - - // -------------------------------------------------------------------------- + final List sources; - final class Index { - // One big list! - // Various sub-types. - // persisted - List rows; - - // persisted - List sortedIndexEntries; - - Dictionary getDict() { - return Dictionary.this; - } - } - - static final class IndexEntry implements RAFSerializable { - String token; - int startRow; - - public void write(RandomAccessFile raf) throws IOException { - raf.writeUTF(token); - raf.write(startRow); - } - } + final List indices; } \ No newline at end of file diff --git a/src/com/hughes/android/dictionary/engine/Index.java b/src/com/hughes/android/dictionary/engine/Index.java new file mode 100644 index 0000000..62c3324 --- /dev/null +++ b/src/com/hughes/android/dictionary/engine/Index.java @@ -0,0 +1,34 @@ +/** + * + */ +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 rows; + + // persisted + final List sortedIndexEntries; + + static final class IndexEntry implements RAFSerializable { + String token; + int startRow; + + public void write(RandomAccessFile raf) throws IOException { + raf.writeUTF(token); + raf.write(startRow); + } + } +} \ No newline at end of file diff --git a/src/com/hughes/android/dictionary/engine/PairEntry.java b/src/com/hughes/android/dictionary/engine/PairEntry.java index 40282a0..efdfa00 100644 --- a/src/com/hughes/android/dictionary/engine/PairEntry.java +++ b/src/com/hughes/android/dictionary/engine/PairEntry.java @@ -18,11 +18,12 @@ public class PairEntry extends Entry { 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); } } diff --git a/src/com/hughes/android/dictionary/engine/Row.java b/src/com/hughes/android/dictionary/engine/Row.java index 7c2c927..0f52c30 100644 --- a/src/com/hughes/android/dictionary/engine/Row.java +++ b/src/com/hughes/android/dictionary/engine/Row.java @@ -21,9 +21,9 @@ public interface Row { // dealt with in the normal manner. static class Serializer implements RAFListSerializer { - final Dictionary.Index index; + final Index index; - Serializer(final Dictionary.Index index) { + Serializer(final Index index) { this.index = index; } diff --git a/src/com/hughes/android/dictionary/engine/RowWithIndex.java b/src/com/hughes/android/dictionary/engine/RowWithIndex.java index 00d7db8..b947ff8 100644 --- a/src/com/hughes/android/dictionary/engine/RowWithIndex.java +++ b/src/com/hughes/android/dictionary/engine/RowWithIndex.java @@ -4,16 +4,16 @@ import java.io.IOException; 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 diff --git a/src/com/hughes/android/dictionary/engine/TokenRow.java b/src/com/hughes/android/dictionary/engine/TokenRow.java index 61a35d2..3335d28 100644 --- a/src/com/hughes/android/dictionary/engine/TokenRow.java +++ b/src/com/hughes/android/dictionary/engine/TokenRow.java @@ -5,7 +5,7 @@ import java.io.RandomAccessFile; 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); } -- 2.43.0