KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > index > EntryResult


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc 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 JavaDoc[] getDocumentNames(Index index) throws java.io.IOException JavaDoc {
46     if (this.documentTables != null) {
47         int length = this.documentTables.length;
48         if (length == 1 && this.documentNames == null) { // have a single table
49
Object JavaDoc offset = this.documentTables[0].get(word);
50             int[] numbers = index.diskIndex.readDocumentNumbers(offset);
51             String JavaDoc[] names = new String JavaDoc[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 JavaDoc 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 JavaDoc[] names = new String JavaDoc[this.documentNames.elementSize];
69     int count = 0;
70     Object JavaDoc[] values = this.documentNames.values;
71     for (int i = 0, l = values.length; i < l; i++)
72         if (values[i] != null)
73             names[count++] = (String JavaDoc) values[i];
74     return names;
75 }
76 public boolean isEmpty() {
77     return this.documentTables == null && this.documentNames == null;
78 }
79 }
80
Popular Tags