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