1 19 20 package org.netbeans.modules.registry.mergedctx; 21 22 23 import java.util.*; 24 25 abstract class NameCache { 26 Map content; 27 28 protected NameCache() { 29 } 30 31 private boolean isInitialized() { 32 return (content != null); 33 } 34 35 36 public String toString() { 37 final StringBuffer sb = new StringBuffer (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 s = (String ) entry.getKey(); 42 sb.append(" " + s + " " + entry.getValue()); } 44 } 45 return sb.toString(); 46 } 47 48 final void add(final int priority, final String name) { 49 synchronized (NameCache.class) { 50 if (!isInitialized()) content = new HashMap(); 51 52 final Integer foundPriority = (Integer ) content.get(name); 53 if (foundPriority == null || priority < foundPriority.intValue()) { 54 content.put(name, new Integer (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 |