Removed DOCUMENT ME comments that were generated and applied source code
[utils] / support / general / src / main / java / org / wamblee / cache / CachedObject.java
index f844c728e9b69d18c176ed3afc95133d223fe243..f8eb8b0fad49c6c900f351ba6c6325c7168f503c 100644 (file)
@@ -1,53 +1,35 @@
 /*
  * Copyright 2005 the original author or authors.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.wamblee.cache;
 
-import java.io.Serializable;
-
 import org.apache.log4j.Logger;
 
+import java.io.Serializable;
+
 /**
  * Represents a cached object. The object is either retrieved from the cache if
  * the cache has it, or a call back is invoked to get the object (and put it in
  * the cache).
- *
+ * 
  * @author Erik Brakkee
+ * 
  */
 public class CachedObject<KeyType extends Serializable, ValueType extends Serializable> {
-
     private static final Logger LOGGER = Logger.getLogger(CachedObject.class);
 
-    /**
-     * Callback invoked to compute an object if it was not found in the cache.
-     * 
-     * @param <T>
-     *            Type of the object
-     */
-    public static interface Computation<Key extends Serializable, Value extends Serializable> {
-        /**
-         * Gets the object. Called when the object is not in the cache.
-         * 
-         * @param aObjectKey
-         *            Id of the object in the cache.
-         * @return Object, must be non-null.
-         */
-        Value getObject(Key aObjectKey);
-    }
-
     /**
      * Cache to use.
      */
@@ -75,7 +57,7 @@ public class CachedObject<KeyType extends Serializable, ValueType extends Serial
      *            cache.
      */
     public CachedObject(Cache<KeyType, ValueType> aCache, KeyType aObjectKey,
-            Computation<KeyType, ValueType> aComputation) {
+        Computation<KeyType, ValueType> aComputation) {
         cache = aCache;
         objectKey = aObjectKey;
         computation = aComputation;
@@ -89,8 +71,9 @@ public class CachedObject<KeyType extends Serializable, ValueType extends Serial
      */
     public ValueType get() {
         ValueType object = (ValueType) cache.get(objectKey); // the used
-                                                                // cache is
-                                                                // thread safe.
+        // cache is
+        // thread safe.
+
         if (object == null) {
             // synchronize the computation to make sure that the object is only
             // computed
@@ -99,6 +82,7 @@ public class CachedObject<KeyType extends Serializable, ValueType extends Serial
             // recomputed.
             synchronized (this) {
                 object = (ValueType) cache.get(objectKey);
+
                 if (object == null) {
                     // No other thread did a recomputation so we must do this
                     // now.
@@ -108,13 +92,13 @@ public class CachedObject<KeyType extends Serializable, ValueType extends Serial
                 }
             }
         }
+
         return object;
     }
 
     /**
      * Invalidates the cache for the object so that it is recomputed the next
      * time it is requested.
-     * 
      */
     public void invalidate() {
         cache.remove(objectKey);
@@ -128,4 +112,22 @@ public class CachedObject<KeyType extends Serializable, ValueType extends Serial
     public Cache getCache() {
         return cache;
     }
+
+    /**
+     * Callback invoked to compute an object if it was not found in the cache.
+     * 
+     * @param <T>
+     *            Type of the object
+     */
+    public static interface Computation<Key extends Serializable, Value extends Serializable> {
+        /**
+         * Gets the object. Called when the object is not in the cache.
+         * 
+         * @param aObjectKey
+         *            Id of the object in the cache.
+         * 
+         * @return Object, must be non-null.
+         */
+        Value getObject(Key aObjectKey);
+    }
 }