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