]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/engine/Dictionary.java
First decent implementation of HtmlEntry attached to TokenRow.
[Dictionary.git] / src / com / hughes / android / dictionary / engine / Dictionary.java
index 2deb24f31790129f82d966e39d720492b56872eb..9224f51deb87cf52bd7063100ac80dd7860e3446 100644 (file)
@@ -19,6 +19,7 @@ import java.io.IOException;
 import java.io.PrintStream;
 import java.io.RandomAccessFile;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import com.hughes.android.dictionary.DictionaryInfo;
@@ -32,7 +33,7 @@ public class Dictionary implements RAFSerializable<Dictionary> {
   
   static final int CACHE_SIZE = 5000;
   
-  static final int CURRENT_DICT_VERSION = 4;
+  static final int CURRENT_DICT_VERSION = 6;
   static final String END_OF_DICTIONARY = "END OF DICTIONARY";
   
   // persisted
@@ -41,6 +42,7 @@ public class Dictionary implements RAFSerializable<Dictionary> {
   public final String dictInfo;
   public final List<PairEntry> pairEntries;
   public final List<TextEntry> textEntries;
+  public final List<HtmlEntry> htmlEntries;
   public final List<EntrySource> sources;
   public final List<Index> indices;
   
@@ -58,6 +60,7 @@ public class Dictionary implements RAFSerializable<Dictionary> {
     this.dictInfo = dictInfo;
     pairEntries = new ArrayList<PairEntry>();
     textEntries = new ArrayList<TextEntry>();
+    htmlEntries = new ArrayList<HtmlEntry>();
     sources = new ArrayList<EntrySource>();
     indices = new ArrayList<Index>();
   }
@@ -78,6 +81,11 @@ public class Dictionary implements RAFSerializable<Dictionary> {
       
       pairEntries = CachingList.create(RAFList.create(raf, new PairEntry.Serializer(this), raf.getFilePointer()), CACHE_SIZE);
       textEntries = CachingList.create(RAFList.create(raf, new TextEntry.Serializer(this), raf.getFilePointer()), CACHE_SIZE);
+      if (dictFileVersion >= 5) {
+        htmlEntries = CachingList.create(RAFList.create(raf, new HtmlEntry.Serializer(this), raf.getFilePointer()), CACHE_SIZE);
+      } else {
+        htmlEntries = Collections.emptyList();
+      }
       indices = CachingList.createFullyCached(RAFList.create(raf, indexSerializer, raf.getFilePointer()));
     } catch (RuntimeException e) {
       final IOException ioe = new IOException("RuntimeException loading dictionary");
@@ -98,6 +106,7 @@ public class Dictionary implements RAFSerializable<Dictionary> {
     RAFList.write(raf, sources, new EntrySource.Serializer(this));
     RAFList.write(raf, pairEntries, new PairEntry.Serializer(this));
     RAFList.write(raf, textEntries, new TextEntry.Serializer(this));
+    RAFList.write(raf, htmlEntries, new HtmlEntry.Serializer(this));
     RAFList.write(raf, indices, indexSerializer);
     raf.writeUTF(END_OF_DICTIONARY);
   }
@@ -112,6 +121,17 @@ public class Dictionary implements RAFSerializable<Dictionary> {
       t.write(raf);
     }};
     
+    final RAFListSerializer<HtmlEntry> htmlEntryIndexSerializer = new RAFListSerializer<HtmlEntry>() {
+        @Override
+        public void write(RandomAccessFile raf, HtmlEntry t) throws IOException {
+            if (t.index() == -1) throw new IndexOutOfBoundsException();
+            raf.writeInt(t.index());
+        }
+        @Override
+        public HtmlEntry read(RandomAccessFile raf, int readIndex) throws IOException {
+            return htmlEntries.get(raf.readInt());
+        }}; 
+    
     public void print(final PrintStream out) {
       out.println("dictInfo=" + dictInfo);
       for (final EntrySource entrySource : sources) {