]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/engine/TextEntry.java
Added Apache license.
[Dictionary.git] / src / com / hughes / android / dictionary / engine / TextEntry.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.PrintStream;
19 import java.io.RandomAccessFile;
20
21 import com.hughes.util.raf.RAFSerializable;
22 import com.hughes.util.raf.RAFSerializer;
23
24 public class TextEntry extends AbstractEntry implements RAFSerializable<TextEntry> {
25   
26   final String text;
27   
28   public TextEntry(final RandomAccessFile raf) throws IOException {
29     text = raf.readUTF();
30   }
31   @Override
32   public void write(RandomAccessFile raf) throws IOException {
33     raf.writeUTF(text);
34   }
35   
36   static final RAFSerializer<TextEntry> SERIALIZER = new RAFSerializer<TextEntry>() {
37     @Override
38     public TextEntry read(RandomAccessFile raf) throws IOException {
39       return new TextEntry(raf);
40     }
41
42     @Override
43     public void write(RandomAccessFile raf, TextEntry t) throws IOException {
44       t.write(raf);
45     }
46   };
47   
48   @Override
49   public int addToDictionary(final Dictionary dictionary) {
50     dictionary.textEntries.add(this);
51     return dictionary.textEntries.size() - 1;
52   }
53
54   public static class Row extends RowBase {
55     
56     Row(final RandomAccessFile raf, final int thisRowIndex,
57         final Index index) throws IOException {
58       super(raf, thisRowIndex, index);
59     }
60     
61     public TextEntry getEntry() {
62       return index.dict.textEntries.get(referenceIndex);
63     }
64     
65     @Override
66     public void print(PrintStream out) {
67       out.println("  " + getEntry().text);
68     }
69
70     @Override
71     public String getRawText(boolean compact) {
72       return getEntry().text;
73     }
74   }
75
76
77
78 }