|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.collect.TotalMap<K,V>
public class TotalMap<K,V>
A map that is defined for all values in the domain K. This class is similar
to the Map interface, but there are fundamental differences that make
it difficult to implement the interface. For example, it's impossible to produce a
valueSet for an arbitrary TotalMap. (It's even impossible to safely define
the Map.get method, since it is defined for all Objects, and the
lambda implementing the total map is only defined in terms of K.)
The total coverage of the domain is achieved by defining the map in terms of a
Lambda. Additionally, specific values can be overridden with specific results
via the override(K, V) method; these mappings can be undone via revert(K).
Optionally, the results of get(K) queries that call the lambda can be automatically
cached with the other overriding mappings.
This class is not thread safe (to reduce overhead in sequenential applications, and because
external references to _overrides make it difficult to make safety guarantees). It is
possible, for example, for a TotalMap with caching enabled to still compute a result more than
once.
| Constructor Summary | |
|---|---|
TotalMap()
Create a TotalMap whose value is null for all inputs. |
|
TotalMap(Lambda<? super K,? extends V> lambda)
Create a TotalMap defined in terms of lambda. |
|
TotalMap(Lambda<? super K,? extends V> lambda,
boolean cache)
Create a TotalMap defined in terms of lambda. |
|
TotalMap(Lambda<? super K,? extends V> lambda,
java.util.Map<? super K,V> overrides)
Create a TotalMap defined in terms of lambda, with the exception of
the given overriding assignments. |
|
TotalMap(Lambda<? super K,? extends V> lambda,
java.util.Map<? super K,V> overrides,
boolean cache)
Create a TotalMap defined in terms of lambda, with the exception of
the given overriding assignments. |
|
TotalMap(java.util.Map<? super K,V> overrides)
Create a TotalMap whose value is null for all inputs, with the exception
of the given overriding assignments. |
|
| Method Summary | ||
|---|---|---|
int |
cacheSize()
Get the size of the cache -- the number of overridden values |
|
boolean |
containsOverride(java.lang.Object key)
|
|
V |
get(K key)
|
|
static
|
make()
Call the constructor (allows the type arguments to be inferred) |
|
static
|
make(Lambda<? super K,? extends V> lambda)
Call the constructor (allows the type arguments to be inferred) |
|
static
|
make(Lambda<? super K,? extends V> lambda,
boolean cache)
Call the constructor (allows the type arguments to be inferred) |
|
static
|
make(Lambda<? super K,? extends V> lambda,
java.util.Map<? super K,V> overrides)
Call the constructor (allows the type arguments to be inferred) |
|
static
|
make(Lambda<? super K,? extends V> lambda,
java.util.Map<? super K,V> overrides,
boolean cache)
Call the constructor (allows the type arguments to be inferred) |
|
static
|
make(java.util.Map<? super K,V> overrides)
Call the constructor (allows the type arguments to be inferred) |
|
void |
override(K key,
V value)
Add the given mapping to the override map. |
|
void |
overrideAll(java.util.Map<? extends K,? extends V> map)
Add all the given mappings to the override map |
|
V |
revert(K key)
Remove the given key from the override map. |
|
void |
revertAll()
Remove all mappings from the override map. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TotalMap()
TotalMap whose value is null for all inputs. Caching is disabled.
public TotalMap(Lambda<? super K,? extends V> lambda)
TotalMap defined in terms of lambda. Caching is disabled.
public TotalMap(Lambda<? super K,? extends V> lambda,
boolean cache)
TotalMap defined in terms of lambda. Caching may be enabled
or disabled.
public TotalMap(java.util.Map<? super K,V> overrides)
TotalMap whose value is null for all inputs, with the exception
of the given overriding assignments. The given map is stored (not copied), so subsequent
external changes will be reflected here (and vice versa). Cahcing is disabled.
public TotalMap(Lambda<? super K,? extends V> lambda,
java.util.Map<? super K,V> overrides)
TotalMap defined in terms of lambda, with the exception of
the given overriding assignments. The given map is stored (not copied), so subsequent
external changes will be reflected here (and vice versa). Caching is disabled.
public TotalMap(Lambda<? super K,? extends V> lambda,
java.util.Map<? super K,V> overrides,
boolean cache)
TotalMap defined in terms of lambda, with the exception of
the given overriding assignments. The given map is stored (not copied), so subsequent
external changes will be reflected here (and vice versa). Caching is enabled or disabled
as specified.
| Method Detail |
|---|
public V get(K key)
key
public void override(K key,
V value)
get(key)
will immediately return value.
public boolean containsOverride(java.lang.Object key)
true iff the override map contains the given keypublic V revert(K key)
get(key)
will invoke the lambda.
null if the mapping
did not exist.public void overrideAll(java.util.Map<? extends K,? extends V> map)
public void revertAll()
get will
invoke the lambda.
public int cacheSize()
public static <K,V> TotalMap<K,V> make()
public static <K,V> TotalMap<K,V> make(Lambda<? super K,? extends V> lambda)
public static <K,V> TotalMap<K,V> make(Lambda<? super K,? extends V> lambda,
boolean cache)
public static <K,V> TotalMap<K,V> make(java.util.Map<? super K,V> overrides)
public static <K,V> TotalMap<K,V> make(Lambda<? super K,? extends V> lambda,
java.util.Map<? super K,V> overrides)
public static <K,V> TotalMap<K,V> make(Lambda<? super K,? extends V> lambda,
java.util.Map<? super K,V> overrides,
boolean cache)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||