KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > properties > QueryResults


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.core.internal.properties;
12
13 /**
14  * This type acts as a container for the results of
15  * a query over the property store.
16  * <p>
17  * Where the results of a query are potentially spread across
18  * multiple resources, the results are gathered together in a
19  * single query results object.</p>
20  *
21  */

22 import java.util.*;
23
24 //
25
public class QueryResults {
26     protected HashMap table = new HashMap(10);
27
28     public QueryResults() {
29         super();
30     }
31
32     protected void add(ResourceName resourceName, Object JavaDoc value) {
33         List properties = getResults(resourceName);
34         if (properties.isEmpty())
35             table.put(resourceName, properties);
36         if (properties.indexOf(value) == -1)
37             properties.add(value);
38     }
39
40     /**
41      * Answers with an <code>Enumeration</code> of resources that comprise
42      * the result.
43      *
44      * @return an <code>Enumeration</code> of <code>ResourceName</code>,
45      * or an empty enumerator if there were no matching resources.
46      */

47     public Enumeration getResourceNames() {
48         return Collections.enumeration(table.keySet());
49     }
50
51     /**
52      * Returns all the results for a given resource.
53      *
54      * @param resourceName the resource for which the results are sought.
55      * @return a <code>List</code> of the matching results. The <code>List</code>
56      * will be empty if there are no matching results.
57      */

58     public List getResults(ResourceName resourceName) {
59         List results = (List) table.get(resourceName);
60         if (results == null)
61             results = new ArrayList(10);
62         return results;
63     }
64 }
65
Popular Tags