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.IOException;
18 import java.io.PrintStream;
19 import java.io.RandomAccessFile;
20 import java.util.List;
21 import java.util.regex.Pattern;
23 import com.hughes.android.dictionary.engine.Index.IndexEntry;
24 import com.ibm.icu.text.Transliterator;
26 public class TokenRow extends RowBase {
28 public final boolean hasMainEntry;
30 TokenRow(final RandomAccessFile raf, final int thisRowIndex, final Index index, final boolean hasMainEntry) throws IOException {
31 super(raf, thisRowIndex, index);
32 this.hasMainEntry = hasMainEntry;
35 TokenRow(final int referenceIndex, final int thisRowIndex, final Index index, final boolean hasMainEntry) {
36 super(referenceIndex, thisRowIndex, index);
37 this.hasMainEntry = hasMainEntry;
40 public String toString() {
41 return getToken() + "@" + referenceIndex;
45 public TokenRow getTokenRow(final boolean search) {
50 public void setTokenRow(TokenRow tokenRow) {
51 throw new RuntimeException("Shouldn't be setting TokenRow's TokenRow!");
54 public String getToken() {
55 return getIndexEntry().token;
58 public IndexEntry getIndexEntry() {
59 return index.sortedIndexEntries.get(referenceIndex);
63 public void print(final PrintStream out) {
64 final String surrounder = hasMainEntry ? "***" : "===";
65 out.println(surrounder + getToken() + surrounder);
66 for (final HtmlEntry htmlEntry : index.sortedIndexEntries.get(referenceIndex).htmlEntries) {
67 out.println("HtmlEntry: " + htmlEntry.title + " <<<" + htmlEntry.html + ">>>");
72 public String getRawText(boolean compact) {
77 public RowMatchType matches(List<String> searchTokens, final Pattern orderedMatchPattern, Transliterator normalizer, boolean swapPairEntries) {
78 return RowMatchType.NO_MATCH;