1 package com.hughes.android.dictionary.engine;
3 import java.io.IOException;
4 import java.io.PrintStream;
5 import java.io.RandomAccessFile;
7 import com.hughes.util.raf.RAFSerializable;
8 import com.hughes.util.raf.RAFSerializer;
10 public class PairEntry extends Entry implements RAFSerializable<PairEntry> {
12 public static final class Pair {
15 public Pair(final String lang1, final String lang2) {
19 public String toString() {
20 return lang1 + " :: " + lang2;
26 public PairEntry(final Pair[] pairs) {
30 public PairEntry(final RandomAccessFile raf) throws IOException {
31 pairs = new Pair[raf.readInt()];
32 for (int i = 0; i < pairs.length; ++i) {
33 pairs[i] = new Pair(raf.readUTF(), raf.readUTF());
37 public void write(RandomAccessFile raf) throws IOException {
38 // TODO: this could be a short.
39 raf.writeInt(pairs.length);
40 for (int i = 0; i < pairs.length; ++i) {
41 raf.writeUTF(pairs[i].lang1);
42 raf.writeUTF(pairs[i].lang2);
46 static final RAFSerializer<PairEntry> SERIALIZER = new RAFSerializer<PairEntry>() {
48 public PairEntry read(RandomAccessFile raf) throws IOException {
49 return new PairEntry(raf);
53 public void write(RandomAccessFile raf, PairEntry t) throws IOException {
59 public static class Row extends RowBase {
61 Row(final RandomAccessFile raf, final int thisRowIndex,
62 final Index index) throws IOException {
63 super(raf, thisRowIndex, index);
66 Row(final int referenceIndex, final int thisRowIndex,
68 super(referenceIndex, thisRowIndex, index);
71 public PairEntry getEntry() {
72 return index.dict.pairEntries.get(referenceIndex);
76 public Object draw(String searchText) {
77 // TODO Auto-generated method stub
82 public void print(PrintStream out) {
83 final PairEntry pairEntry = getEntry();
84 for (int i = 0; i < pairEntry.pairs.length; ++i) {
85 out.print((i == 0 ? " " : " ") + pairEntry.pairs[i]);