]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/engine/TextEntry.java
8dd88f4ac20c7f8977daa6e9c899903ffd91ad10
[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.DataInput;
18 import java.io.DataOutput;
19 import java.io.IOException;
20 import java.io.PrintStream;
21 import java.util.List;
22 import java.util.regex.Pattern;
23
24 import com.hughes.util.raf.RAFListSerializer;
25 import com.hughes.util.raf.RAFSerializable;
26 import com.ibm.icu.text.Transliterator;
27
28 public class TextEntry extends AbstractEntry implements RAFSerializable<TextEntry> {
29
30     public final String text;
31
32     private TextEntry(final Dictionary dictionary, final DataInput raf, final int index)
33     throws IOException {
34         super(dictionary, raf, index);
35         text = raf.readUTF();
36         throw new RuntimeException("TextEntry constructor should be unreachable");
37     }
38
39     @Override
40     public void write(DataOutput raf) throws IOException {
41         super.write(raf);
42         raf.writeUTF(text);
43     }
44
45     static final class Serializer implements RAFListSerializer<TextEntry> {
46
47         final Dictionary dictionary;
48
49         Serializer(Dictionary dictionary) {
50             this.dictionary = dictionary;
51         }
52
53         @Override
54         public TextEntry read(DataInput raf, final int index) throws IOException {
55             return new TextEntry(dictionary, raf, index);
56         }
57
58         @Override
59         public void write(DataOutput raf, TextEntry t) throws IOException {
60             t.write(raf);
61         }
62     }
63
64     @Override
65     public void addToDictionary(final Dictionary dictionary) {
66         assert index == -1;
67         dictionary.textEntries.add(this);
68         index = dictionary.textEntries.size() - 1;
69     }
70
71     @Override
72     public RowBase CreateRow(int rowIndex, Index dictionaryIndex) {
73         throw new UnsupportedOperationException("TextEntry's don't really exist.");
74     }
75
76     public static class Row extends RowBase {
77
78         Row(final DataInput raf, final int thisRowIndex,
79             final Index index, int extra) throws IOException {
80             super(raf, thisRowIndex, index, extra);
81         }
82
83         TextEntry getEntry() {
84             return index.dict.textEntries.get(referenceIndex);
85         }
86
87         @Override
88         public void print(PrintStream out) {
89             out.println("  " + getEntry().text);
90         }
91
92         @Override
93         public String getRawText(boolean compact) {
94             return getEntry().text;
95         }
96
97         @Override
98         public RowMatchType matches(final List<String> searchTokens,
99                                     final Pattern orderedMatchPattern, Transliterator normalizer,
100                                     boolean swapPairEntries) {
101             return null;
102         }
103     }
104
105 }