1 /*** 2 * 3 */ 4 package de.cohesion.bssh.impl.util; 5 6 import de.cohesion.bssh.impl.Factory; 7 8 /*** 9 * @author schulzs 10 */ 11 public class LazyCacheEntry<K, V> extends CacheEntry<K, V> { 12 13 private final Factory<K, V> factory; 14 15 public LazyCacheEntry(final K key, final Factory<K, V> factory) { 16 super(key, null); 17 this.factory = factory; 18 } 19 20 @Override 21 public V getValue() throws InstantiationException { 22 V value = super.getValue(); 23 if (value == null) { 24 setValue(value = factory.create(this.getKey())); 25 } 26 return value; 27 } 28 29 }