KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > search > matching > PossibleMatchSet


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.search.matching;
12
13 import org.eclipse.core.runtime.IPath;
14 import org.eclipse.jdt.core.IPackageFragmentRoot;
15 import org.eclipse.jdt.internal.compiler.util.ObjectVector;
16 import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
17
18 /**
19  * A set of PossibleMatches that is sorted by package fragment roots.
20  */

21 public class PossibleMatchSet {
22
23 private SimpleLookupTable rootsToPossibleMatches = new SimpleLookupTable(5);
24 private int elementCount = 0;
25
26 public void add(PossibleMatch possibleMatch) {
27     IPath path = possibleMatch.openable.getPackageFragmentRoot().getPath();
28     ObjectVector possibleMatches = (ObjectVector) this.rootsToPossibleMatches.get(path);
29     if (possibleMatches != null) {
30         if (possibleMatches.contains(possibleMatch)) return;
31     } else {
32         this.rootsToPossibleMatches.put(path, possibleMatches = new ObjectVector());
33     }
34
35     possibleMatches.add(possibleMatch);
36     this.elementCount++;
37 }
38 public PossibleMatch[] getPossibleMatches(IPackageFragmentRoot[] roots) {
39     PossibleMatch[] result = new PossibleMatch[this.elementCount];
40     int index = 0;
41     for (int i = 0, length = roots.length; i < length; i++) {
42         ObjectVector possibleMatches = (ObjectVector) this.rootsToPossibleMatches.get(roots[i].getPath());
43         if (possibleMatches != null) {
44             possibleMatches.copyInto(result, index);
45             index += possibleMatches.size();
46         }
47     }
48     if (index < this.elementCount)
49         System.arraycopy(result, 0, result = new PossibleMatch[index], 0, index);
50     return result;
51 }
52 public void reset() {
53     this.rootsToPossibleMatches = new SimpleLookupTable(5);
54     this.elementCount = 0;
55 }
56 }
57
Popular Tags