]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/ObjectCache.java
UPD: minor consistency cleanups
[gigi.git] / src / org / cacert / gigi / dbObjects / ObjectCache.java
index e06f84f84a57fd0fde3bafe5d8066b9d6efc08d0..0d9fc14ba51b4f2d0e4005a3977367bdd3c66ff5 100644 (file)
@@ -6,16 +6,17 @@ import java.util.HashSet;
 
 public class ObjectCache<T extends IdCachable> {
 
-    HashMap<Integer, WeakReference<T>> hashmap = new HashMap<>();
+    private final HashMap<Integer, WeakReference<T>> hashmap = new HashMap<>();
 
-    private static HashSet<ObjectCache<?>> caches = new HashSet<>();
+    private static final HashSet<ObjectCache<? extends IdCachable>> caches = new HashSet<>();
 
     protected ObjectCache() {
         caches.add(this);
     }
 
-    public void put(T c) {
+    public T put(T c) {
         hashmap.put(c.getId(), new WeakReference<T>(c));
+        return c;
     }
 
     public T get(int id) {
@@ -26,9 +27,13 @@ public class ObjectCache<T extends IdCachable> {
         return null;
     }
 
-    public static void clearAllCashes() {
-        for (ObjectCache<?> objectCache : caches) {
+    public static void clearAllCaches() {
+        for (ObjectCache<? extends IdCachable> objectCache : caches) {
             objectCache.hashmap.clear();
         }
     }
+
+    public void remove(T toRm) {
+        hashmap.remove(toRm);
+    }
 }