]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/engine/EntrySource.java
Faster multi search, exact search, moved Normalization around.
[Dictionary.git] / src / com / hughes / android / dictionary / engine / EntrySource.java
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package com.hughes.android.dictionary.engine;
16
17 import java.io.IOException;
18 import java.io.RandomAccessFile;
19 import java.io.Serializable;
20
21 import com.hughes.util.IndexedObject;
22 import com.hughes.util.raf.RAFListSerializer;
23
24 public class EntrySource extends IndexedObject implements Serializable {
25   
26   private static final long serialVersionUID = -1323165134846120269L;
27   
28   final String name;
29   int numEntries;
30   
31   public EntrySource(final int index, final String name, int numEntries) {
32     super(index);
33     this.name = name;
34     this.numEntries = numEntries;
35   }
36   
37   @Override
38   public String toString() {
39     return name;
40   }
41   
42   
43
44
45   public int getNumEntries() {
46     return numEntries;
47   }
48
49   public String getName() {
50     return name;
51   }
52
53
54   public static final class Serializer implements RAFListSerializer<EntrySource> {
55     
56     final Dictionary dictionary;
57     
58     Serializer(Dictionary dictionary) {
59       this.dictionary = dictionary;
60     }
61
62     @Override
63     public EntrySource read(RandomAccessFile raf, int readIndex)
64         throws IOException {
65       final String name = raf.readUTF();
66       final int numEntries = dictionary.dictFileVersion >= 3 ? raf.readInt() : 0;
67       return new EntrySource(readIndex, name, numEntries);
68     }
69
70     @Override
71     public void write(RandomAccessFile raf, EntrySource t) throws IOException {
72       raf.writeUTF(t.name);
73       raf.writeInt(t.numEntries);
74     }    
75   };
76   
77 }