4 package com.hughes.android.dictionary.engine;
6 import java.io.IOException;
7 import java.io.RandomAccessFile;
8 import java.util.Collection;
11 import com.hughes.util.raf.RAFList;
12 import com.hughes.util.raf.RAFSerializable;
13 import com.hughes.util.raf.RAFSerializer;
14 import com.hughes.util.raf.UniformRAFList;
16 final class Index implements RAFSerializable<Index> {
17 final Dictionary dict;
19 final String shortName;
20 final String longName;
23 final List<Index.IndexEntry> sortedIndexEntries;
28 final List<RowBase> rows;
30 // --------------------------------------------------------------------------
32 public Index(final Dictionary dict, final RandomAccessFile raf) throws IOException {
34 shortName = raf.readUTF();
35 longName = raf.readUTF();
37 sortedIndexEntries = RAFList.create(raf, IndexEntry.SERIALIZER, raf.getFilePointer());
38 rows = UniformRAFList.create(raf, new RowBase.Serializer(this), raf.getFilePointer());
41 public void write(final RandomAccessFile raf) throws IOException {
42 raf.writeUTF(shortName);
43 raf.writeUTF(longName);
44 RAFList.write(raf, sortedIndexEntries, IndexEntry.SERIALIZER);
45 UniformRAFList.write(raf, (Collection<RowBase>) rows, new RowBase.Serializer(this), 5);
49 static final class IndexEntry implements RAFSerializable<Index.IndexEntry> {
52 static final RAFSerializer<IndexEntry> SERIALIZER = new RAFSerializer<IndexEntry> () {
54 public IndexEntry read(RandomAccessFile raf) throws IOException {
55 return new IndexEntry(raf);
58 public void write(RandomAccessFile raf, IndexEntry t) throws IOException {
61 public IndexEntry(final RandomAccessFile raf) throws IOException {
62 token = raf.readUTF();
63 startRow = raf.readInt();
65 public void write(RandomAccessFile raf) throws IOException {