uk.ac.man.cs.rainbow.simulator
Class ThreadSet

java.lang.Object
  |
  +--uk.ac.man.cs.rainbow.simulator.ThreadSet
All Implemented Interfaces:
Cloneable, Serializable

public final class ThreadSet
extends Object
implements Serializable, Cloneable

"Unordered" collection of threads, where a thread can only belong at most once.

See Also:
Serialized Form

Constructor Summary
ThreadSet()
          Create a new set of threads.
 
Method Summary
 void add(RainbowThread t)
          Add a thread to the set.
 Object clone()
          Produce a copy of the set of threads.
protected  RainbowThread elementAt(int locn)
          Report the thread at the given location.
 RainbowThread get()
          Obtain a thread from the set.
 RainbowThread get(int where)
          Obtain a thread from the set.
 RainbowThread get(Random randomGenerator)
          Obtain a thread from the set.
 RainbowThread getAt(int locn)
          Get and remove the thread at the given location.
 boolean isEmpty()
          Tests if this set is empty.
 boolean isPresent(RainbowThread t)
          Tests if the given thread is in the set.
 void remove(RainbowThread t)
          Remove a given thread from the set.
 int size()
          Return the size of the set.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadSet

public ThreadSet()
Create a new set of threads.
Method Detail

isEmpty

public boolean isEmpty()
Tests if this set is empty.

isPresent

public boolean isPresent(RainbowThread t)
Tests if the given thread is in the set.

size

public int size()
Return the size of the set.

add

public void add(RainbowThread t)
Add a thread to the set. The position used is the end of the internal queue.

remove

public void remove(RainbowThread t)
Remove a given thread from the set. Does nothing if the thread was not present in the set.

get

public RainbowThread get()
Obtain a thread from the set. The thread chosen will be the thread at the head of the internal queue.

get

public RainbowThread get(int where)
Obtain a thread from the set. The argument selects whether the thread will be chosen from the head or the tail of the queue.
See Also:
Simulator.ORDERING_QUEUE, Simulator.ORDERING_STACK

get

public RainbowThread get(Random randomGenerator)
Obtain a thread from the set. The thread will be selected from a random location in the queue, with that random number coming from the supplied RNG.

getAt

public RainbowThread getAt(int locn)
Get and remove the thread at the given location.

elementAt

protected RainbowThread elementAt(int locn)
Report the thread at the given location.

clone

public Object clone()
Produce a copy of the set of threads. This copy will not be modified if the original is modified. The threads themselves are not copied.
Overrides:
clone in class Object