Class 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 a TupleMap, 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 also final.) This entails that methods that normally should be able to modify the contents of a Map (e.g. put() or clear() 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 interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • 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()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface ca.uqac.lif.cep.Duplicable

        duplicate
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • TupleFixed

        public TupleFixed​(java.lang.String[] names,
                          java.lang.Object[] values)
    • Method Detail

      • clear

        public final void clear()
        Specified by:
        clear in interface java.util.Map<java.lang.String,​java.lang.Object>
      • containsKey

        public final boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<java.lang.String,​java.lang.Object>
      • containsValue

        public final boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.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 interface java.util.Map<java.lang.String,​java.lang.Object>
      • get

        public final java.lang.Object get​(java.lang.Object key)
        Specified by:
        get in interface java.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 interface java.util.Map<java.lang.String,​java.lang.Object>
      • keySet

        public final java.util.Set<java.lang.String> keySet()
        Specified by:
        keySet in interface java.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 interface java.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 interface java.util.Map<java.lang.String,​java.lang.Object>
      • remove

        public final Tuple remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<java.lang.String,​java.lang.Object>
      • size

        public final int size()
        Specified by:
        size in interface java.util.Map<java.lang.String,​java.lang.Object>
      • values

        public final java.util.Collection<java.lang.Object> values()
        Specified by:
        values in interface java.util.Map<java.lang.String,​java.lang.Object>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • duplicate

        public TupleFixed duplicate​(boolean with_state)
        Specified by:
        duplicate in interface ca.uqac.lif.cep.Duplicable
        Specified by:
        duplicate in class Tuple
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Map<java.lang.String,​java.lang.Object>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<java.lang.String,​java.lang.Object>
        Overrides:
        hashCode in class java.lang.Object