KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > search > PrebuiltIndexes


1 /*******************************************************************************
2  * Copyright (c) 2005 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.help.internal.search;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashSet JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Set JavaDoc;
17
18 /**
19  * Plugins with prebuilt search indexes.
20  *
21  */

22 public class PrebuiltIndexes {
23     private SearchIndex targetIndex;
24
25     /**
26      * Set of PluginIndex
27      */

28     private Set JavaDoc set = new HashSet JavaDoc();
29
30     PrebuiltIndexes(SearchIndex targetIndex) {
31         super();
32         this.targetIndex = targetIndex;
33     }
34
35     void add(String JavaDoc plugin, String JavaDoc path) {
36         set.add(new PluginIndex(plugin, path, targetIndex));
37     }
38
39     /**
40      * Removes Plugin indexes with no index
41      */

42     private void trim() {
43         List JavaDoc indexes = new ArrayList JavaDoc(set);
44         for (int i = 0; i < indexes.size();) {
45             PluginIndex index = (PluginIndex) indexes.get(i);
46             if (index.getPaths().size() == 0) {
47                 set.remove(index);
48             }
49             i++;
50         }
51     }
52
53     public PluginIndex[] getIndexes() {
54         trim();
55         return (PluginIndex[]) set.toArray(new PluginIndex[set.size()]);
56     }
57 }
58
Popular Tags