]> gitweb.fperrin.net Git - DictionaryPC.git/blobdiff - src/com/hughes/android/dictionary/engine/IndexBuilder.java
Unit tests working, looks like I'd been revamping the parsers.
[DictionaryPC.git] / src / com / hughes / android / dictionary / engine / IndexBuilder.java
index 0d111911edcb0a3a87a9b27957c809ad8b355a58..0424d0bb22aee9a9350c4307302d1d032a5f50d3 100644 (file)
@@ -44,31 +44,41 @@ public class IndexBuilder {
   }
   
   public void build() {
-    final Set<IndexedEntry> tokenEntryDatas = new HashSet<IndexedEntry>();
+    final Set<IndexedEntry> tokenIndexedEntries = new HashSet<IndexedEntry>();
     final List<RowBase> rows = index.rows;
     index.mainTokenCount = 0;
     for (final TokenData tokenData : tokenToData.values()) {
-      tokenEntryDatas.clear();
+      tokenIndexedEntries.clear();
       final int indexIndex = index.sortedIndexEntries.size();
       final int startRow = rows.size();
       
-      final TokenRow tokenRow = new TokenRow(indexIndex, rows.size(), index, tokenData.hasMainEntry);
-      rows.add(tokenRow);
-      if (tokenRow.hasMainEntry) {
-        index.mainTokenCount++;
-      }
-//      System.out.println("Added TokenRow: " + rows.get(rows.size() - 1));
+      TokenRow tokenRow = null;
+      
       int numRows = 0;  // off by one--doesn't count the token row!
 //      System.out.println("TOKEN: " + tokenData.token);
-      for (final Map.Entry<EntryTypeName, List<IndexedEntry>> typeToEntry : tokenData.typeToEntries.entrySet()) {
-        for (final IndexedEntry entryData : typeToEntry.getValue()) {
-          if (entryData.index() == -1) {
-            entryData.addToDictionary(dictionaryBuilder.dictionary);
-            assert entryData.index() >= 0;
+      for (final Map.Entry<EntryTypeName, List<IndexedEntry>> typeToIndexedEntries : tokenData.typeToEntries.entrySet()) {
+        for (final IndexedEntry indexedEntry : typeToIndexedEntries.getValue()) {
+          
+          if (!indexedEntry.isValid) {
+            continue;
+          }
+          
+          if (tokenRow == null) {
+//          System.out.println("Added TokenRow: " + rows.get(rows.size() - 1));
+            tokenRow = new TokenRow(indexIndex, rows.size(), index, tokenData.hasMainEntry);
+            rows.add(tokenRow);
+            if (tokenRow.hasMainEntry) {
+              index.mainTokenCount++;
+            }
+          }
+          
+          if (indexedEntry.index() == -1) {
+            indexedEntry.addToDictionary(dictionaryBuilder.dictionary);
+            assert indexedEntry.index() >= 0;
           }
-          if (tokenEntryDatas.add(entryData)) {
-            rows.add(new PairEntry.Row(entryData.index(), rows.size(), index));
-            ++entryData.entry.entrySource.numEntries;
+          if (tokenIndexedEntries.add(indexedEntry)) {
+            rows.add(new PairEntry.Row(indexedEntry.index(), rows.size(), index));
+            ++indexedEntry.entry.entrySource.numEntries;
             ++numRows;
             
 //            System.out.print("  " + typeToEntry.getKey() + ": ");