1 // Copyright 2011 Google Inc. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 package com.hughes.android.dictionary.engine;
17 import com.hughes.util.raf.RAFListSerializer;
18 import com.hughes.util.raf.RAFSerializable;
19 import com.ibm.icu.text.Transliterator;
21 import java.io.DataInput;
22 import java.io.DataOutput;
23 import java.io.IOException;
24 import java.io.PrintStream;
25 import java.util.List;
26 import java.util.regex.Pattern;
28 public class TextEntry extends AbstractEntry implements RAFSerializable<TextEntry> {
32 public TextEntry(final Dictionary dictionary, final DataInput raf, final int index)
34 super(dictionary, raf, index);
36 throw new RuntimeException("TextEntry constructor should be unreachable");
40 public void write(DataOutput raf) throws IOException {
45 static final class Serializer implements RAFListSerializer<TextEntry> {
47 final Dictionary dictionary;
49 Serializer(Dictionary dictionary) {
50 this.dictionary = dictionary;
54 public TextEntry read(DataInput raf, final int index) throws IOException {
55 return new TextEntry(dictionary, raf, index);
59 public void write(DataOutput raf, TextEntry t) throws IOException {
65 public void addToDictionary(final Dictionary dictionary) {
67 dictionary.textEntries.add(this);
68 index = dictionary.textEntries.size() - 1;
72 public RowBase CreateRow(int rowIndex, Index dictionaryIndex) {
73 throw new UnsupportedOperationException("TextEntry's don't really exist.");
76 public static class Row extends RowBase {
78 Row(final DataInput raf, final int thisRowIndex,
79 final Index index, int extra) throws IOException {
80 super(raf, thisRowIndex, index, extra);
83 public TextEntry getEntry() {
84 return index.dict.textEntries.get(referenceIndex);
88 public void print(PrintStream out) {
89 out.println(" " + getEntry().text);
93 public String getRawText(boolean compact) {
94 return getEntry().text;
98 public RowMatchType matches(final List<String> searchTokens,
99 final Pattern orderedMatchPattern, Transliterator normalizer,
100 boolean swapPairEntries) {