KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > registry > mergedctx > NameCache


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.registry.mergedctx;
21
22
23 import java.util.*;
24
25 abstract class NameCache {
26     Map /*<String name, Integer priority>*/ content;
27
28     protected NameCache() {
29     }
30
31     private boolean isInitialized() {
32         return (content != null);
33     }
34
35
36     public String JavaDoc toString() {
37         final StringBuffer JavaDoc sb = new StringBuffer JavaDoc(getClass().toString() + ": " + System.identityHashCode(this));
38         if (isInitialized()) {
39             for (Iterator iterator = content.entrySet().iterator(); iterator.hasNext();) {
40                 final Map.Entry entry = (Map.Entry) iterator.next();
41                 final String JavaDoc s = (String JavaDoc) entry.getKey();
42                 sb.append(" " + s + " " + entry.getValue());//NOI18N
43
}
44         }
45         return sb.toString();
46     }
47
48     final void add(final int priority, final String JavaDoc name) {
49         synchronized (NameCache.class) {
50             if (!isInitialized()) content = new HashMap();
51
52             final Integer JavaDoc foundPriority = (Integer JavaDoc) content.get(name);
53             if (foundPriority == null || priority < foundPriority.intValue()) {
54                 content.put(name, new Integer JavaDoc(priority));
55             }
56         }
57     }
58
59     void clear() {
60         synchronized (NameCache.class) {
61             content = null;
62         }
63     }
64
65
66     final Collection getNames() {
67         return (isInitialized()) ? Collections.unmodifiableCollection(content.keySet()) : Collections.EMPTY_LIST;
68     }
69 }
70
Popular Tags