cz.cuni.amis.pogamut.ut2004.agent.module.utils
Class TabooSet<T>

Package class diagram package TabooSet
java.lang.Object
  extended by cz.cuni.amis.pogamut.ut2004.agent.module.utils.TabooSet<T>
All Implemented Interfaces:
cz.cuni.amis.utils.IFilter<T>, Iterable<T>, Collection<T>

public class TabooSet<T>
extends Object
implements cz.cuni.amis.utils.IFilter<T>, Collection<T>

This class is a simple implementation of TabooSet (similar to TabooList). It allows you to insert items that are taboo either for infinite time (via add(Object)) or for a specified amount of UT2004 time (via add(Object, double)).

Items inside taboo set are either removed automatically due to a timeout (a specified amount of time has passed) or manually via remove(Object).


Nested Class Summary
static interface TabooSet.IRelaxedTaboo<T>
           
 
Constructor Summary
TabooSet(UT2004Bot bot)
          Constructor of the TabuSet.
 
Method Summary
 boolean add(T item)
          Adds a taboo item that is valid for an infinite amount of time.
 void add(T item, double timeout)
          Adds a tabu item that is valid for a period of 'timeout' time (in seconds).
 boolean addAll(Collection<? extends T> c)
           
 void clear()
          Clears the taboo set.
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
 Set<T> filter(Collection<T> collection)
          Filters collection according to the current state of the tabu set.
 Set<T> filter(Collection<T> collection, TabooSet.IRelaxedTaboo estimator)
          Filters collection according to the current state of the tabu set.
 double getTabooTime(T item)
          If not tabooized forever, it returns remaining time for the item to remain taboo.
 double getTime()
          Returns current UT2004 time that is used by the TabooSet.
 boolean isAccepted(T item)
          Method that is used by DistanceUtils methods to filter items.
 boolean isEmpty()
           
 boolean isTaboo(T item)
          Determines whether an 'item' is inside tabu set or not based on the current UT2004 time.
 boolean isTaboo(T item, TabooSet.IRelaxedTaboo estimator)
          Determines whether an 'item' is considered to be taboo using relaxed 'estimator'.
 Iterator<T> iterator()
           
 boolean remove(Object item)
          Removes a tabu item from the set.
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 int size()
          Return how many items are inside taboo set.
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

TabooSet

public TabooSet(UT2004Bot bot)
Constructor of the TabuSet.

Parameters:
bot -
Method Detail

getTabooTime

public double getTabooTime(T item)
If not tabooized forever, it returns remaining time for the item to remain taboo.

If tabooized forever, returns Double.POSITIVE_INFINITY.

If item is not tabooized, returns 0.

Parameters:
item -
Returns:

isTaboo

public boolean isTaboo(T item)
Determines whether an 'item' is inside tabu set or not based on the current UT2004 time.

Parameters:
item -
Returns:

isTaboo

public boolean isTaboo(T item,
                       TabooSet.IRelaxedTaboo estimator)
Determines whether an 'item' is considered to be taboo using relaxed 'estimator'.

Parameters:
item -
estimator -
Returns:

isAccepted

public boolean isAccepted(T item)
Method that is used by DistanceUtils methods to filter items.

Specified by:
isAccepted in interface cz.cuni.amis.utils.IFilter<T>
Parameters:
item -
Returns:
returns !isTaboo(Object)

filter

public Set<T> filter(Collection<T> collection)
Filters collection according to the current state of the tabu set. It returns a new hash set containing items from 'collection' that are not inside tabu set.

Parameters:
collection -
Returns:

filter

public Set<T> filter(Collection<T> collection,
                     TabooSet.IRelaxedTaboo estimator)
Filters collection according to the current state of the tabu set. It returns a new hash set containing items from 'collection' that are not inside tabu set.

Parameters:
collection -
Returns:

getTime

public double getTime()
Returns current UT2004 time that is used by the TabooSet.


add

public boolean add(T item)
Adds a taboo item that is valid for an infinite amount of time.

Specified by:
add in interface Collection<T>
Parameters:
item -
Returns:

add

public void add(T item,
                double timeout)
Adds a tabu item that is valid for a period of 'timeout' time (in seconds).

Parameters:
item -
timeout - in seconds

remove

public boolean remove(Object item)
Removes a tabu item from the set.

Specified by:
remove in interface Collection<T>
Parameters:
item -
Returns:

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<T>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<T>

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>
Specified by:
iterator in interface Collection<T>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<T>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<T>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<T>

addAll

public boolean addAll(Collection<? extends T> c)
Specified by:
addAll in interface Collection<T>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<T>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<T>

size

public int size()
Return how many items are inside taboo set.

Specified by:
size in interface Collection<T>
Returns:

clear

public void clear()
Clears the taboo set.

Specified by:
clear in interface Collection<T>


Copyright © 2014 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.