1 11 package org.eclipse.jdt.internal.core.index; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; 15 import org.eclipse.jdt.internal.compiler.util.SimpleSet; 16 17 public class EntryResult { 18 19 private char[] word; 20 private HashtableOfObject[] documentTables; 21 private SimpleSet documentNames; 22 23 public EntryResult(char[] word, HashtableOfObject table) { 24 this.word = word; 25 if (table != null) 26 this.documentTables = new HashtableOfObject[] {table}; 27 } 28 public void addDocumentName(String documentName) { 29 if (this.documentNames == null) 30 this.documentNames = new SimpleSet(3); 31 this.documentNames.add(documentName); 32 } 33 public void addDocumentTable(HashtableOfObject table) { 34 if (this.documentTables != null) { 35 int length = this.documentTables.length; 36 System.arraycopy(this.documentTables, 0, this.documentTables = new HashtableOfObject[length + 1], 0, length); 37 this.documentTables[length] = table; 38 } else { 39 this.documentTables = new HashtableOfObject[] {table}; 40 } 41 } 42 public char[] getWord() { 43 return this.word; 44 } 45 public String [] getDocumentNames(Index index) throws java.io.IOException { 46 if (this.documentTables != null) { 47 int length = this.documentTables.length; 48 if (length == 1 && this.documentNames == null) { Object offset = this.documentTables[0].get(word); 50 int[] numbers = index.diskIndex.readDocumentNumbers(offset); 51 String [] names = new String [numbers.length]; 52 for (int i = 0, l = numbers.length; i < l; i++) 53 names[i] = index.diskIndex.readDocumentName(numbers[i]); 54 return names; 55 } 56 57 for (int i = 0; i < length; i++) { 58 Object offset = this.documentTables[i].get(word); 59 int[] numbers = index.diskIndex.readDocumentNumbers(offset); 60 for (int j = 0, k = numbers.length; j < k; j++) 61 addDocumentName(index.diskIndex.readDocumentName(numbers[j])); 62 } 63 } 64 65 if (this.documentNames == null) 66 return CharOperation.NO_STRINGS; 67 68 String [] names = new String [this.documentNames.elementSize]; 69 int count = 0; 70 Object [] values = this.documentNames.values; 71 for (int i = 0, l = values.length; i < l; i++) 72 if (values[i] != null) 73 names[count++] = (String ) values[i]; 74 return names; 75 } 76 public boolean isEmpty() { 77 return this.documentTables == null && this.documentNames == null; 78 } 79 } 80 | Popular Tags |