Package ca.uqac.lif.cep.tuples
Class CacheMap<T>
- java.lang.Object
-
- ca.uqac.lif.cep.tuples.CacheMap<T>
-
- All Implemented Interfaces:
java.util.Map<java.lang.String,T>
public final class CacheMap<T> extends java.lang.Object implements java.util.Map<java.lang.String,T>Implementation of an immutable map.- After its instantiation, the object is immutable: all
its fields are declared
private finaland no method can ever change their value. (As a matter of fact, all its methods are alsofinal.) This entails that methods that normally should be able to modify the contents of a Map (e.g.put()orclear()here have no effect. - Internally, the tuple uses plain arrays (instead of a
HashMap) for storing keys and values. For tuples with, a small number of keys, this should actually provide faster access than a HashMap. In all cases, arrays use up less memory than a HashMap. - Because of this, one can also ask for the index of a key/value pair, and obtain a value based on its index (rather than its key). Assuming that all tuples in a stream have their key/value pairs arranged in the same order, this means one can ask for the index of a key a first time, and from that point on query the remaining tuples by directly providing the index.
- Author:
- Sylvain Hallé
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<java.lang.String,T>>entrySet()Tget(java.lang.Object key)intgetIndexOf(java.lang.String s)Get the index of a key in the current mapintgetIndexOf(java.lang.String key, int index, T out)Retrieves a value, possibly using an index.java.lang.ObjectgetValue(int index)booleanisEmpty()java.util.Set<java.lang.String>keySet()Tput(java.lang.String key, T value)voidputAll(java.util.Map<? extends java.lang.String,? extends T> m)voidputAll(T[] values)voidputAt(int index, T value)Tremove(java.lang.Object key)intsize()java.lang.StringtoString()java.util.Collection<T>values()
-
-
-
Method Detail
-
clear
public final void clear()
- Specified by:
clearin interfacejava.util.Map<java.lang.String,T>
-
containsKey
public final boolean containsKey(java.lang.Object key)
- Specified by:
containsKeyin interfacejava.util.Map<java.lang.String,T>
-
containsValue
public final boolean containsValue(java.lang.Object value)
- Specified by:
containsValuein interfacejava.util.Map<java.lang.String,T>
-
entrySet
public final java.util.Set<java.util.Map.Entry<java.lang.String,T>> entrySet()
- Specified by:
entrySetin interfacejava.util.Map<java.lang.String,T>
-
get
public final T get(java.lang.Object key)
- Specified by:
getin interfacejava.util.Map<java.lang.String,T>
-
getValue
public final java.lang.Object getValue(int index)
-
getIndexOf
public final int getIndexOf(java.lang.String s)
Get the index of a key in the current map- Parameters:
s- The key- Returns:
- The index of that key, or -1 if key does not exist
-
getIndexOf
public final int getIndexOf(java.lang.String key, int index, T out)Retrieves a value, possibly using an index. This allows one to both get the direct index of a value in the map, if not known, and to fetch that value.Object o; cached_index = map.getIndexOf("mykey", cached_index, o);This will put the value corresponding tomykeyino, and updatecached_indexto the position in the array where this key was found. Later calls togetIndexOfwill use that value to directly access the element, rather than look for it.- Parameters:
key- The key to get in the mapindex- If negative, the method will look for the key in the map to get the value. If greater than or equal to 0, the method will directly use that value to fetch the object to return.out- After the call, will contain a reference to the value one is looking for- Returns:
- The index value
-
isEmpty
public final boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Map<java.lang.String,T>
-
keySet
public final java.util.Set<java.lang.String> keySet()
- Specified by:
keySetin interfacejava.util.Map<java.lang.String,T>
-
put
public final T put(java.lang.String key, T value)
- Specified by:
putin interfacejava.util.Map<java.lang.String,T>
-
putAt
public final void putAt(int index, T value)
-
putAll
public final void putAll(T[] values)
-
putAll
public final void putAll(java.util.Map<? extends java.lang.String,? extends T> m)
- Specified by:
putAllin interfacejava.util.Map<java.lang.String,T>
-
remove
public final T remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map<java.lang.String,T>
-
size
public final int size()
- Specified by:
sizein interfacejava.util.Map<java.lang.String,T>
-
values
public final java.util.Collection<T> values()
- Specified by:
valuesin interfacejava.util.Map<java.lang.String,T>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-