01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.core.index;
11:
12: import org.eclipse.jdt.core.compiler.CharOperation;
13: import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
14: import org.eclipse.jdt.internal.compiler.util.SimpleSet;
15:
16: public class EntryResult {
17:
18: private char[] word;
19: private HashtableOfObject[] documentTables;
20: private SimpleSet documentNames;
21:
22: public EntryResult(char[] word, HashtableOfObject table) {
23: this .word = word;
24: if (table != null)
25: this .documentTables = new HashtableOfObject[] { table };
26: }
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:
34: public void addDocumentTable(HashtableOfObject table) {
35: if (this .documentTables != null) {
36: int length = this .documentTables.length;
37: System
38: .arraycopy(
39: this .documentTables,
40: 0,
41: this .documentTables = new HashtableOfObject[length + 1],
42: 0, length);
43: this .documentTables[length] = table;
44: } else {
45: this .documentTables = new HashtableOfObject[] { table };
46: }
47: }
48:
49: public char[] getWord() {
50: return this .word;
51: }
52:
53: public String[] getDocumentNames(Index index)
54: throws java.io.IOException {
55: if (this .documentTables != null) {
56: int length = this .documentTables.length;
57: if (length == 1 && this .documentNames == null) { // have a single table
58: Object offset = this .documentTables[0].get(word);
59: int[] numbers = index.diskIndex
60: .readDocumentNumbers(offset);
61: String[] names = new String[numbers.length];
62: for (int i = 0, l = numbers.length; i < l; i++)
63: names[i] = index.diskIndex
64: .readDocumentName(numbers[i]);
65: return names;
66: }
67:
68: for (int i = 0; i < length; i++) {
69: Object offset = this .documentTables[i].get(word);
70: int[] numbers = index.diskIndex
71: .readDocumentNumbers(offset);
72: for (int j = 0, k = numbers.length; j < k; j++)
73: addDocumentName(index.diskIndex
74: .readDocumentName(numbers[j]));
75: }
76: }
77:
78: if (this .documentNames == null)
79: return CharOperation.NO_STRINGS;
80:
81: String[] names = new String[this .documentNames.elementSize];
82: int count = 0;
83: Object[] values = this .documentNames.values;
84: for (int i = 0, l = values.length; i < l; i++)
85: if (values[i] != null)
86: names[count++] = (String) values[i];
87: return names;
88: }
89:
90: public boolean isEmpty() {
91: return this.documentTables == null
92: && this.documentNames == null;
93: }
94: }
|