cz.cuni.amis.utils.maps
Class AbstractLazyMap<KEY,VALUE>

Package class diagram package AbstractLazyMap
java.lang.Object
  extended by cz.cuni.amis.utils.maps.AbstractLazyMap<KEY,VALUE>
Type Parameters:
KEY - KeyType
VALUE - ValueType
All Implemented Interfaces:
Map<KEY,VALUE>

public abstract class AbstractLazyMap<KEY,VALUE>
extends Object
implements Map<KEY,VALUE>

Abstract implementation of a lazy map. The values are created on-demand by the create method if they are not cached already. The keySet is kept updated however, only the values are lazy-generated. If you need to iterate over the map, but you don't actually need all the values, iterate over the keySet.

Author:
srlok

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
AbstractLazyMap()
           
AbstractLazyMap(Map<KEY,VALUE> baseMap)
           
AbstractLazyMap(Set<KEY> entryKeySet)
           
 
Method Summary
 void addKey(KEY key)
           
 void clear()
           
 void clearCache()
          manually clears the cached objects
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
protected abstract  VALUE create(Object key)
          Creates the Mapped object based on its key.
 Set<Map.Entry<KEY,VALUE>> entrySet()
           
 VALUE get(Object key)
           
 boolean isEmpty()
           
 Set<KEY> keySet()
           
 VALUE put(KEY key, VALUE value)
           
 void putAll(Map<? extends KEY,? extends VALUE> m)
           
 VALUE remove(Object key)
           
 void setKeySet(Set<KEY> newKeySet)
           
 int size()
           
 Collection<VALUE> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

AbstractLazyMap

public AbstractLazyMap()

AbstractLazyMap

public AbstractLazyMap(Set<KEY> entryKeySet)

AbstractLazyMap

public AbstractLazyMap(Map<KEY,VALUE> baseMap)
Method Detail

create

protected abstract VALUE create(Object key)
Creates the Mapped object based on its key. Every LazyMap must implement this.

Parameters:
key -
Returns:

addKey

public void addKey(KEY key)

clear

public void clear()
Specified by:
clear in interface Map<KEY,VALUE>

clearCache

public void clearCache()
manually clears the cached objects


containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<KEY,VALUE>

setKeySet

public void setKeySet(Set<KEY> newKeySet)

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<KEY,VALUE>

entrySet

public Set<Map.Entry<KEY,VALUE>> entrySet()
Specified by:
entrySet in interface Map<KEY,VALUE>

get

public VALUE get(Object key)
Specified by:
get in interface Map<KEY,VALUE>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<KEY,VALUE>

keySet

public Set<KEY> keySet()
Specified by:
keySet in interface Map<KEY,VALUE>

put

public VALUE put(KEY key,
                 VALUE value)
Specified by:
put in interface Map<KEY,VALUE>

putAll

public void putAll(Map<? extends KEY,? extends VALUE> m)
Specified by:
putAll in interface Map<KEY,VALUE>

remove

public VALUE remove(Object key)
Specified by:
remove in interface Map<KEY,VALUE>

size

public int size()
Specified by:
size in interface Map<KEY,VALUE>

values

public Collection<VALUE> values()
Specified by:
values in interface Map<KEY,VALUE>


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.