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 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;
24 import com.hughes.util.raf.RAFListSerializer;
25 import com.ibm.icu.text.Transliterator;
27 public class TextEntry extends AbstractEntry {
29 public final String text;
31 private TextEntry(final Dictionary dictionary, final DataInput raf, final int index)
33 super(dictionary, raf, index);
35 throw new RuntimeException("TextEntry constructor should be unreachable");
39 public void write(DataOutput raf) throws IOException {
44 static final class Serializer implements RAFListSerializer<TextEntry> {
46 final Dictionary dictionary;
48 Serializer(Dictionary dictionary) {
49 this.dictionary = dictionary;
53 public TextEntry read(DataInput raf, final int index) throws IOException {
54 return new TextEntry(dictionary, raf, index);
58 public void write(DataOutput raf, TextEntry t) throws IOException {
64 public void addToDictionary(final Dictionary dictionary) {
66 dictionary.textEntries.add(this);
67 index = dictionary.textEntries.size() - 1;
71 public RowBase CreateRow(int rowIndex, Index dictionaryIndex) {
72 throw new UnsupportedOperationException("TextEntry's don't really exist.");
75 public static class Row extends RowBase {
77 Row(final DataInput raf, final int thisRowIndex,
78 final Index index, int extra) throws IOException {
79 super(raf, thisRowIndex, index, extra);
82 TextEntry getEntry() {
83 return index.dict.textEntries.get(referenceIndex);
87 public void print(PrintStream out) {
88 out.println(" " + getEntry().text);
92 public String getRawText(boolean compact) {
93 return getEntry().text;
97 public RowMatchType matches(final List<String> searchTokens,
98 final Pattern orderedMatchPattern, Transliterator normalizer,
99 boolean swapPairEntries) {