Don’t store a Shell if there is already the real thing, always return the most real...
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 15 Oct 2010 04:34:27 +0000 (06:34 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 15 Oct 2010 04:34:27 +0000 (06:34 +0200)
src/main/java/net/pterodactylus/sone/data/ShellCache.java

index fd3d6bc..33e033c 100644 (file)
@@ -65,13 +65,17 @@ public class ShellCache<T> {
         *            The object to store
         */
        @SuppressWarnings("unchecked")
-       public void put(String id, T object) {
+       public T put(String id, T object) {
                if (!(object instanceof Shell<?>)) {
                        objectCache.put(id, object);
                        shellCache.remove(id);
-               } else {
-                       shellCache.put(id, (Shell<T>) object);
+                       return object;
                }
+               if (objectCache.containsKey(id)) {
+                       return objectCache.get(id);
+               }
+               shellCache.put(id, (Shell<T>) object);
+               return object;
        }
 
        /**