Package ca.uqac.lif.cep.tuples
Class TupleFixed
- java.lang.Object
-
- ca.uqac.lif.cep.tuples.Tuple
-
- ca.uqac.lif.cep.tuples.TupleFixed
-
- All Implemented Interfaces:
ca.uqac.lif.cep.Duplicable
,java.util.Map<java.lang.String,java.lang.Object>
public final class TupleFixed extends Tuple implements ca.uqac.lif.cep.Duplicable
Implementation of a named tuple. Contrarily to aTupleMap
, a fixed tuple assumes stronger hypotheses on its use in order to reduce memory usage and decrease response time.- After its instantiation, the object is immutable: all
its fields are declared
private final
and 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.
The process can be further optimized by using the
FixedTupleBuilder
class to build a stream of tuples that all follow the same schema.Note that if these constraints are not suitable for your processing, you should use the "regular"
TupleMap
class that gives you much more flexibility (possibly at the expense of some overhead).- Author:
- Sylvain Hallé
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ca.uqac.lif.cep.tuples.Tuple
Tuple.MapEntry<K,V>
-
-
Constructor Summary
Constructors Constructor Description TupleFixed(java.lang.String[] names, java.lang.Object[] values)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(java.lang.Object key)
boolean
containsValue(java.lang.Object value)
TupleFixed
duplicate(boolean with_state)
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>>
entrySet()
boolean
equals(java.lang.Object o)
java.lang.Object
get(java.lang.Object key)
int
getIndexOf(java.lang.String s)
java.lang.Object
getValue(int index)
int
hashCode()
boolean
isEmpty()
java.util.Set<java.lang.String>
keySet()
Tuple
put(java.lang.String key, java.lang.Object value)
void
putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> m)
Tuple
remove(java.lang.Object key)
int
size()
java.lang.String
toString()
java.util.Collection<java.lang.Object>
values()
-
-
-
Method Detail
-
clear
public final void clear()
- Specified by:
clear
in interfacejava.util.Map<java.lang.String,java.lang.Object>
-
containsKey
public final boolean containsKey(java.lang.Object key)
- Specified by:
containsKey
in interfacejava.util.Map<java.lang.String,java.lang.Object>
-
containsValue
public final boolean containsValue(java.lang.Object value)
- Specified by:
containsValue
in interfacejava.util.Map<java.lang.String,java.lang.Object>
-
entrySet
public final java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
- Specified by:
entrySet
in interfacejava.util.Map<java.lang.String,java.lang.Object>
-
get
public final java.lang.Object get(java.lang.Object key)
- Specified by:
get
in interfacejava.util.Map<java.lang.String,java.lang.Object>
-
getValue
public final java.lang.Object getValue(int index)
-
getIndexOf
public final int getIndexOf(java.lang.String s)
-
isEmpty
public final boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Map<java.lang.String,java.lang.Object>
-
keySet
public final java.util.Set<java.lang.String> keySet()
- Specified by:
keySet
in interfacejava.util.Map<java.lang.String,java.lang.Object>
-
put
public final Tuple put(java.lang.String key, java.lang.Object value)
- Specified by:
put
in interfacejava.util.Map<java.lang.String,java.lang.Object>
-
putAll
public final void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> m)
- Specified by:
putAll
in interfacejava.util.Map<java.lang.String,java.lang.Object>
-
remove
public final Tuple remove(java.lang.Object key)
- Specified by:
remove
in interfacejava.util.Map<java.lang.String,java.lang.Object>
-
size
public final int size()
- Specified by:
size
in interfacejava.util.Map<java.lang.String,java.lang.Object>
-
values
public final java.util.Collection<java.lang.Object> values()
- Specified by:
values
in interfacejava.util.Map<java.lang.String,java.lang.Object>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
duplicate
public TupleFixed duplicate(boolean with_state)
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equals
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
hashCode
in classjava.lang.Object
-
-