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