]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/engine/PairEntry.java
Major refactor of down dictionary list is stored by app.
[Dictionary.git] / src / com / hughes / android / dictionary / engine / PairEntry.java
index a84bc2a102c033f76221cee22cfb429b37648d84..ebfd84a14f4fd9bbdafc62c4679b6f4ad51721f3 100644 (file)
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
 package com.hughes.android.dictionary.engine;
 
 import java.io.IOException;
@@ -13,16 +27,18 @@ public class PairEntry extends AbstractEntry implements RAFSerializable<PairEntr
   
   public final List<Pair> pairs;
 
-  public PairEntry() {
-    pairs = new ArrayList<Pair>(1);
+  public PairEntry(final EntrySource entrySource) {
+    super(entrySource);
+    pairs = new ArrayList<Pair>(1);    
   }
 
-  public PairEntry(final String lang1, final String lang2) {
-    pairs = new ArrayList<Pair>(1);
+  public PairEntry(final EntrySource entrySource, final String lang1, final String lang2) {
+    this(entrySource);
     this.pairs.add(new Pair(lang1, lang2));
   }
   
-  public PairEntry(final RandomAccessFile raf) throws IOException {
+  public PairEntry(final Dictionary dictionary, final RandomAccessFile raf) throws IOException {
+    super(dictionary, raf);
     final int size = raf.readInt();
     pairs = new ArrayList<PairEntry.Pair>(size);
     for (int i = 0; i < size; ++i) {
@@ -31,18 +47,27 @@ public class PairEntry extends AbstractEntry implements RAFSerializable<PairEntr
   }
   @Override
   public void write(RandomAccessFile raf) throws IOException {
+    super.write(raf);
     // TODO: this could be a short.
     raf.writeInt(pairs.size());
     for (int i = 0; i < pairs.size(); ++i) {
+      assert pairs.get(i).lang1.length() > 0;
       raf.writeUTF(pairs.get(i).lang1);
       raf.writeUTF(pairs.get(i).lang2);
     }
   }
   
-  static final RAFSerializer<PairEntry> SERIALIZER = new RAFSerializer<PairEntry>() {
+  static final class Serializer implements RAFSerializer<PairEntry> {
+    
+    final Dictionary dictionary;
+    
+    Serializer(Dictionary dictionary) {
+      this.dictionary = dictionary;
+    }
+
     @Override
     public PairEntry read(RandomAccessFile raf) throws IOException {
-      return new PairEntry(raf);
+      return new PairEntry(dictionary, raf);
     }
 
     @Override