com.atlassian.jira.util.collect
Class MemoizingMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by com.atlassian.jira.util.collect.MemoizingMap<K,V>
Type Parameters:
K - the key type.
V - the value type.
All Implemented Interfaces:
Map<K,V>

@NotThreadSafe
public class MemoizingMap<K,V>
extends AbstractMap<K,V>
implements Map<K,V>

A Map that is backed by a MemoizingMap.Master map that contains suppliers for the values that are called lazily when required. This can reduce the amount of memory required if there are a number of entries that may or may not be required in the most case.

For example, when rendering Velocity templates, the context map is populated with a lot of things that are only ever required occasionally.

Note: even though this class is effectively immutable and does not support direct mutation, the memoization strategy is not thread-safe and should not be used if thread-safety is required. Adding thread-safety to this class would be fairly trivial through.


Nested Class Summary
static class MemoizingMap.Master<K,V>
          Master that individual Maps can be printed from.
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Method Summary
 boolean containsKey(Object key)
           
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Object key)
          .
 boolean isEmpty()
           
 Set<K> keySet()
           
 V remove(Object key)
           
 int size()
           
 
Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, equals, hashCode, put, putAll, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsValue, equals, hashCode, put, putAll, values
 

Method Detail

get

public V get(Object key)
.

Implements the local caching of a value from the master.

Specified by:
get in interface Map<K,V>
Overrides:
get in class AbstractMap<K,V>

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in class AbstractMap<K,V>

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class AbstractMap<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>
Specified by:
entrySet in class AbstractMap<K,V>

size

public int size()
Specified by:
size in interface Map<K,V>
Overrides:
size in class AbstractMap<K,V>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>
Overrides:
isEmpty in class AbstractMap<K,V>

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>
Overrides:
remove in class AbstractMap<K,V>


Copyright © 2002-2013 Atlassian. All Rights Reserved.