/** * Returns a set of the mappings contained in this hash table. */ public Set entrySet() { processQueue(); return hash.entrySet(); }
/** * Soften a class * * @param clazz * the class */ public synchronized void soften(CtClass clazz) { if (repository.isPrune()) clazz.prune(); classes.remove(clazz.getName()); softcache.put(clazz.getName(), clazz); }
/** * Constructs a new <code>WeakHashMap</code> with the same mappings as the * specified <tt>Map</tt>. The <code>WeakHashMap</code> is created with * an initial capacity of twice the number of mappings in the specified map * or 11 (whichever is greater), and a default load factor, which is * <tt>0.75</tt>. * * @param t the map whose mappings are to be placed in this map. */ public SoftValueHashMap(Map t) { this(Math.max(2 * t.size(), 11), 0.75f); putAll(t); }
/** * Returns the value to which this map maps the specified <code>key</code>. * If this map does not contain a value for this key, then return * <code>null</code>. * * @param key * The key whose associated value, if any, is to be returned. */ @Override public V get(Object key) { processQueue(); return valueOrNull(hash.get(key)); }
@Override public void putAll(Map<? extends K,? extends V> arg0) { processQueue(); for (K key:arg0.keySet()) put(key, arg0.get(key)); }
/** * Flush a class * * @param classname * the class to flush */ public synchronized void flushClass(String classname) { classes.remove(classname); softcache.remove(classname); }
/** * Close the class pool */ public void close() { this.removeClassPath(classPath); classPath.close(); classes.clear(); softcache.clear(); }
/** * Whether the class is cached in this pooled * * @param classname * the class name * @return the cached class */ protected CtClass getCachedLocally(String classname) { CtClass cached = (CtClass)classes.get(classname); if (cached != null) return cached; synchronized (softcache) { return (CtClass)softcache.get(classname); } }
/** * Get any local copy of the class * * @param classname * the class name * @return the class * @throws NotFoundException * when the class is not found */ public synchronized CtClass getLocally(String classname) throws NotFoundException { softcache.remove(classname); CtClass clazz = (CtClass)classes.get(classname); if (clazz == null) { clazz = createCtClass(classname, true); if (clazz == null) throw new NotFoundException(classname); super.cacheCtClass(classname, clazz, false); } return clazz; }
/** * Close the class pool */ public void close() { this.removeClassPath(classPath); classPath.close(); classes.clear(); softcache.clear(); }
/** * Whether the class is cached in this pooled * * @param classname * the class name * @return the cached class */ protected CtClass getCachedLocally(String classname) { CtClass cached = (CtClass)classes.get(classname); if (cached != null) return cached; synchronized (softcache) { return (CtClass)softcache.get(classname); } }
/** * Removes the mapping for the given <code>key</code> from this map, if * present. * * @param key * The key whose mapping is to be removed. * * @return The value to which this key was mapped, or <code>null</code> if * there was no mapping for the key. */ @Override public V remove(Object key) { processQueue(); return valueOrNull(hash.remove(key)); }
/** * Returns the number of key-value mappings in this map. <strong>Note:</strong> * <em>In contrast with most implementations of the * <code>Map</code> interface, the time required by this operation is * linear in the size of the map.</em> */ public int size() { processQueue(); return hash.size(); }
/** * Cache a class * * @param classname * the class name * @param c * the ctClass * @param dynamic * whether the class is dynamically generated */ protected void cacheCtClass(String classname, CtClass c, boolean dynamic) { if (dynamic) { super.cacheCtClass(classname, c, dynamic); } else { if (repository.isPrune()) c.prune(); softcache.put(classname, c); } }
/** * Flush a class * * @param classname * the class to flush */ public synchronized void flushClass(String classname) { classes.remove(classname); softcache.remove(classname); }
/** * Constructs a new <code>WeakHashMap</code> with the same mappings as the * specified <code>Map</code>. The <code>WeakHashMap</code> is created with * an initial capacity of twice the number of mappings in the specified map * or 11 (whichever is greater), and a default load factor, which is * <code>0.75</code>. * * @param t the map whose mappings are to be placed in this map. */ public SoftValueHashMap(Map<K,V> t) { this(Math.max(2 * t.size(), 11), 0.75f); putAll(t); }
/** * Close the class pool */ public void close() { this.removeClassPath(classPath); classPath.close(); classes.clear(); softcache.clear(); }
/** * Whether the class is cached in this pooled * * @param classname * the class name * @return the cached class */ protected CtClass getCachedLocally(String classname) { CtClass cached = (CtClass)classes.get(classname); if (cached != null) return cached; synchronized (softcache) { return (CtClass)softcache.get(classname); } }
/** * Updates this map so that the given <code>key</code> maps to the given * <code>value</code>. If the map previously contained a mapping for * <code>key</code> then that mapping is replaced and the previous value * is returned. * * @param key * The key that is to be mapped to the given <code>value</code> * @param value * The value to which the given <code>key</code> is to be * mapped * * @return The previous value to which this key was mapped, or * <code>null</code> if if there was no mapping for the key */ @Override public V put(K key, V value) { processQueue(); return valueOrNull(hash.put(key, SoftValueRef.create(key, value, queue))); }
/** * Returns <code>true</code> if this map contains no key-value mappings. */ public boolean isEmpty() { processQueue(); return hash.isEmpty(); }