]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/engine/TokenRow.java
First decent implementation of HtmlEntry attached to TokenRow.
[Dictionary.git] / src / com / hughes / android / dictionary / engine / TokenRow.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.ibm.icu.text.Transliterator;
24
25 public class TokenRow extends RowBase {
26   
27   public final boolean hasMainEntry;
28   
29   TokenRow(final RandomAccessFile raf, final int thisRowIndex, final Index index, final boolean hasMainEntry) throws IOException {
30     super(raf, thisRowIndex, index);
31     this.hasMainEntry = hasMainEntry;
32   }
33
34   TokenRow(final int referenceIndex, final int thisRowIndex, final Index index, final boolean hasMainEntry) {
35     super(referenceIndex, thisRowIndex, index);
36     this.hasMainEntry = hasMainEntry;
37   }
38   
39   public String toString() {
40     return getToken() + "@" + referenceIndex;
41   }
42
43   @Override
44   public TokenRow getTokenRow(final boolean search) {
45     return this;
46   }
47
48   @Override
49   public void setTokenRow(TokenRow tokenRow) {
50     throw new RuntimeException("Shouldn't be setting TokenRow's TokenRow!");
51   }
52   
53   public String getToken() {
54     return index.sortedIndexEntries.get(referenceIndex).token;
55   }
56
57   @Override
58   public void print(final PrintStream out) {
59     final String surrounder = hasMainEntry ? "***" : "===";
60     out.println(surrounder + getToken() + surrounder);
61     for (final HtmlEntry htmlEntry : index.sortedIndexEntries.get(referenceIndex).htmlEntries) {
62         out.println("HtmlEntry: " + htmlEntry.title + " <<<" + htmlEntry.html + ">>>");
63     }
64   }
65
66   @Override
67   public String getRawText(boolean compact) {
68     return getToken();
69   }
70
71   @Override
72   public RowMatchType matches(List<String> searchTokens, final Pattern orderedMatchPattern, Transliterator normalizer, boolean swapPairEntries) {
73     return RowMatchType.NO_MATCH;
74   }
75
76
77 }