1 package com.hughes.android.dictionary.engine;
3 import java.io.IOException;
4 import java.io.RandomAccessFile;
6 public abstract class RowWithIndex implements Row {
7 final Dictionary.Index index;
11 TokenRow tokenRow = null;
13 RowWithIndex(final RandomAccessFile raf, final int thisRowIndex, final Dictionary.Index index) throws IOException {
15 this.thisRowIndex = thisRowIndex;
16 this.referenceIndex = raf.readInt();
20 public void write(RandomAccessFile raf) throws IOException {
21 raf.writeInt(referenceIndex);
25 public TokenRow getTokenRow(final boolean search) {
26 if (tokenRow == null && search) {
27 int r = thisRowIndex - 1;
29 final Row row = index.rows.get(r);
30 final TokenRow candidate = row.getTokenRow(false);
31 if (candidate != null) {
32 for (++r; r <= thisRowIndex; ++r) {
33 index.rows.get(r).setTokenRow(candidate);
37 assert tokenRow != null;
43 public void setTokenRow(TokenRow tokenRow) {
44 assert this.tokenRow == null;
45 assert tokenRow != null;
46 this.tokenRow = tokenRow;