Class PeriodicGroupMap

  • All Implemented Interfaces:
    ScheduleableGroupAction, TaskRunnable, Runnable, Map
    Direct Known Subclasses:
    PeriodicCleanUpMap

    public class PeriodicGroupMap
    extends PeriodicGroupRunnable
    implements Map
    PeriodicGroupMap is a general Map and a scheduleable unit. Elements pairs will be grouped by using the time they enter the map. PeriodicGroupMap can be scheduled to Timer or TimerPool. For every run period, ScheduleableGroupAction will act on the elements which are timeout in the map.
    • Field Detail

      • map

        protected Map map
    • Constructor Detail

      • PeriodicGroupMap

        public PeriodicGroupMap​(ScheduleableGroupAction target,
                                long runPeriod,
                                long timeoutPeriod,
                                boolean removeElementAfterAction)
        Constructor of PeriodicGroupMap.
        Parameters:
        target - The ScheduleableGroupAction to run when there is time
        runPeriod - Run period in ms
        timeoutPeriod - timeout period in ms
        removeElementAfterAction - A boolean to indicate whether to remove the elements after action
      • PeriodicGroupMap

        public PeriodicGroupMap​(ScheduleableGroupAction target,
                                long runPeriod,
                                long timeoutPeriod,
                                boolean removeElementAfterAction,
                                Map map)
                         throws IllegalArgumentException
        Constructor of PeriodicGroupMap.
        Parameters:
        target - The ScheduleableGroupAction to run when there is time
        runPeriod - Run period in ms
        timeoutPeriod - timeout period in ms
        removeElementAfterAction - A boolean to indicate whether to remove the elements after action
        map - The synchronized map to use
        Throws:
        IllegalArgumentException
    • Method Detail

      • clear

        public void clear()
        Removes all the elements.
        Specified by:
        clear in interface Map
      • containsKey

        public boolean containsKey​(Object key)
        Checks if the map contains the key.
        Specified by:
        containsKey in interface Map
        Parameters:
        key - The key of the element
        Returns:
        boolean to indicate whether the map contains the key
      • containsValue

        public boolean containsValue​(Object value)
        Checks if the map contains the value.
        Specified by:
        containsValue in interface Map
        Parameters:
        value - The value of the element
        Returns:
        boolean to indicate whether the map contains the value
      • get

        public Object get​(Object key)
        Gets the element assoicated with the key.
        Specified by:
        get in interface Map
        Parameters:
        key - The key of the element
        Returns:
        Object assoicated with the key
      • put

        public Object put​(Object key,
                          Object value)
        Puts the key and element to the map.
        Specified by:
        put in interface Map
        Parameters:
        key - The key to identify the element
        value - The value of the element
        Returns:
        The element the key previously map to
      • remove

        public Object remove​(Object key)
        Removes the element associated with the key.
        Specified by:
        remove in interface Map
        Parameters:
        key - The key to identify the element
        Returns:
        The element the key map to
      • putAll

        public void putAll​(Map m)
        Puts all the elements in the map to this map.
        Specified by:
        putAll in interface Map
        Parameters:
        m - The map to be added to this map.
      • size

        public int size()
        Returns the size of this map.
        Specified by:
        size in interface Map
      • keySet

        public Set keySet()
        Returns the Set of keys of this map.
        Specified by:
        keySet in interface Map
        Returns:
        Set of keys of this map
      • values

        public Collection values()
        Returns the Collection of values of this map.
        Specified by:
        values in interface Map
        Returns:
        Collection of values of this map
      • entrySet

        public Set entrySet()
        Returns a Set view of entry in this map.
        Specified by:
        entrySet in interface Map
        Returns:
        Set view of entry in this map.
      • equals

        public boolean equals​(Object o)
        Compares whether this map is equal to Object o.
        Specified by:
        equals in interface Map
        Overrides:
        equals in class Object
        Parameters:
        o - The object to be compared to
        Returns:
        boolean to indicate whether they are equal
      • hashCode

        public int hashCode()
        Returns hash code of the map.
        Specified by:
        hashCode in interface Map
        Overrides:
        hashCode in class Object
        Returns:
        hash code of this map
      • isEmpty

        public boolean isEmpty()
        Indicates whether this PeriodicRunnable is empty.
        Specified by:
        isEmpty in interface Map
        Specified by:
        isEmpty in interface TaskRunnable
        Overrides:
        isEmpty in class PeriodicRunnable
        Returns:
        A boolean to indicate whether this PeriodicRunnable is empty
      • run

        public void run()
        Implements for TaskRunnable. Run the function of ScheduleableGroupAction on the objects in thisTurn 1 by 1, and interchange thisTurn and nextTurn.
        Specified by:
        run in interface Runnable
        Overrides:
        run in class PeriodicGroupRunnable