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