]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/engine/EntrySource.java
271ba5eb48f1d1ef5d3562814f978cdda6228329
[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 com.hughes.util.IndexedObject;
18 import com.hughes.util.raf.RAFListSerializer;
19
20 import java.io.DataInput;
21 import java.io.DataOutput;
22 import java.io.IOException;
23
24 public class EntrySource extends IndexedObject {
25
26     final String name;
27     int numEntries;
28
29     public EntrySource(final int index, final String name, int numEntries) {
30         super(index);
31         this.name = name;
32         this.numEntries = numEntries;
33     }
34
35     @Override
36     public String toString() {
37         return name;
38     }
39
40     public int getNumEntries() {
41         return numEntries;
42     }
43
44     public String getName() {
45         return name;
46     }
47
48     public static final class Serializer implements RAFListSerializer<EntrySource> {
49
50         final Dictionary dictionary;
51
52         Serializer(Dictionary dictionary) {
53             this.dictionary = dictionary;
54         }
55
56         @Override
57         public EntrySource read(DataInput raf, int readIndex)
58         throws IOException {
59             final String name = raf.readUTF();
60             final int numEntries = dictionary.dictFileVersion >= 3 ? raf.readInt() : 0;
61             return new EntrySource(readIndex, name, numEntries);
62         }
63
64         @Override
65         public void write(DataOutput raf, EntrySource t) throws IOException {
66             raf.writeUTF(t.name);
67             raf.writeInt(t.numEntries);
68         }
69     }
70
71 }