package org.ambraproject.wombat.util;

import org.ambraproject.rhombat.cache.Cache;

import java.io.IOException;
import java.io.Serializable;

public class CacheUtil {
  private CacheUtil() {
  }

  @FunctionalInterface
  public static interface Lookup<T> {
    T get() throws IOException;
  }

  public static <T> T getOrCompute(Cache cache, String key, Lookup<? extends T> supplier)
      throws IOException {
    T value = cache.get(key);
    if (value == null) {
      value = supplier.get();
      cache.put(key, (Serializable) value);
    }
    return value;
  }

}

@@ -191,108 +191,1075 @@
 %7B%0A  
-%7D%0A%0A  @FunctionalInterface%0A  public static interface Lookup%3CT%3E %7B%0A    T get() throws IOException;%0A  %7D%0A
+  throw new AssertionError(%22Not instantiable%22);%0A  %7D%0A%0A  /**%0A   * Function to look up a value if it is not cached.%0A   */%0A  @FunctionalInterface%0A  public static interface Lookup%3CT%3E %7B%0A    T get() throws IOException;%0A  %7D%0A%0A  /**%0A   * Retrieve a value from a cache if possible, computing and inserting it otherwise.%0A   * %3Cp%3E%0A   * The value returned by the %7B@code lookup%7D must be %7B@link Serializable%7D, even though the type %7B@code T%7D is not%0A   * required to implement %7B@code Serializable%7D. (For example, %7B@code T%7D may be %7B@link java.util.List%7D, which is not%0A   * %7B@code Serializable%7D, provided that %7B@code lookup%7D guarantees that all returned values will be %7B@link%0A   * java.util.ArrayList%7D instances, which are %7B@code Serializable%7D.)%0A   *%0A   * @param cache  the cache%0A   * @param key    the cache key to look up%0A   * @param lookup the operation that will produce the value if it is not in the cache%0A   * @return the retrieved or produced value%0A   * @throws IOException%0A   * @throws java.lang.ClassCastException if %7B@code lookup%7D returns a non-%7B@code Serializable%7D value%0A   */
 %0A  p
@@ -1335,24 +1335,22 @@
 ends T%3E 
-supplier
+lookup
 )%0A      
@@ -1443,16 +1443,14 @@
 e = 
-supplier
+lookup
 .get

Add Javadoc to CacheUtil