]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/engine/RowBase.java
About dialog, added pictures, multi word search.
[Dictionary.git] / src / com / hughes / android / dictionary / engine / RowBase.java
index e84eb7377bd780a514d61f705b0d3561ca53488b..8896c88c00ceacc6560de71d5db5381e81496ea4 100644 (file)
@@ -17,7 +17,9 @@ package com.hughes.android.dictionary.engine;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.io.RandomAccessFile;
+import java.util.Comparator;
 import java.util.List;
+import java.util.regex.Pattern;
 
 import com.hughes.util.IndexedObject;
 import com.hughes.util.raf.RAFListSerializer;
@@ -50,6 +52,34 @@ public abstract class RowBase extends IndexedObject {
     this.index = index;
     this.referenceIndex = referenceIndex;
   }
+  
+  static final class RowKey {
+    final Class<? extends RowBase> rowClass;
+    final int referenceIndex;
+    
+    private RowKey(Class<? extends RowBase> rowClass, int referenceIndex) {
+      this.rowClass = rowClass;
+      this.referenceIndex = referenceIndex;
+    }
+    
+    @Override
+    public boolean equals(Object o) {
+      if (!(o instanceof RowKey)) {
+        return false;
+      }
+      final RowKey that = (RowKey) o;
+      return this.referenceIndex == that.referenceIndex && this.rowClass.equals(that.rowClass);
+    }
+    
+    @Override
+    public int hashCode() {
+      return rowClass.hashCode() + referenceIndex;
+    }
+  }
+  
+  public RowKey getRowKey() {
+    return new RowKey(this.getClass(), referenceIndex);
+  }
 
   /**
    * @return the TokenRow that this row is "filed under".
@@ -100,7 +130,7 @@ public abstract class RowBase extends IndexedObject {
 
   public abstract String getRawText(final boolean compact);
   
-  public abstract RowMatchType matches(final List<String> searchTokens, final Transliterator normalizer, boolean swapPairEntries);
+  public abstract RowMatchType matches(final List<String> searchTokens, final Pattern orderedMatch, final Transliterator normalizer, boolean swapPairEntries);
 
   // RowBase must manage "disk-based" polymorphism.  All other polymorphism is
   // dealt with in the normal manner.
@@ -139,4 +169,24 @@ public abstract class RowBase extends IndexedObject {
     }
   }
   
+  public static final class LengthComparator implements Comparator<RowBase> {
+    
+    final boolean swapPairEntries;
+
+    public LengthComparator(boolean swapPairEntries) {
+      this.swapPairEntries = swapPairEntries;
+    }
+
+    @Override
+    public int compare(RowBase row1, RowBase row2) {
+      final int l1 = row1.getSideLength(swapPairEntries);
+      final int l2 = row2.getSideLength(swapPairEntries);
+      return l1 < l2 ? -1 : l1 == l2 ? 0 : 1;
+    }
+  }
+
+  public int getSideLength(boolean swapPairEntries) {
+    return getRawText(false).length();
+  }
+  
 }