sky.monome.util
Class ThreadWithUserObjects


java.lang.Object

  extended by java.lang.Thread

      extended by sky.monome.util.ThreadWithUserObjects

All Implemented Interfaces:
java.lang.Runnable

public abstract class ThreadWithUserObjects
extends java.lang.Thread

Thread which can have user objects for use by example in the run() method. Implementors of this class must redefine the run() method.

Author:
PJ Skyman

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.lang.Object[] userObjects
          Array of arguments given to this thread.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ThreadWithUserObjects(java.lang.Object... userObjects)
          Constructs a thread with given user objects.
ThreadWithUserObjects(java.lang.String name, java.lang.Object... userObjects)
          Constructs a thread with given user objects and the specified name.
ThreadWithUserObjects(java.lang.ThreadGroup threadGroup, java.lang.String name, java.lang.Object... userObjects)
          Constructs a thread with given user objects, the specified thread group and the specified name.
 
Method Summary
<T> T
getUserObject(java.lang.Class<T> clazz, int index)
          Returns the user object at the specified index in the array of user objects.
<T> T
getUserObject(int index)
          Returns the user object at the specified index in the array of user objects.
abstract  void run()
          Contains the main action of this thread.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

userObjects


protected final java.lang.Object[] userObjects
Array of arguments given to this thread.

Constructor Detail

ThreadWithUserObjects


public ThreadWithUserObjects(java.lang.Object... userObjects)
Constructs a thread with given user objects.

Parameters:
userObjects - User objects that can be used by example in the run() method.

ThreadWithUserObjects


public ThreadWithUserObjects(java.lang.String name,

                             java.lang.Object... userObjects)
Constructs a thread with given user objects and the specified name.

Parameters:
name - Name of this thread.
userObjects - User objects that can be used by example in the run() method.

ThreadWithUserObjects


public ThreadWithUserObjects(java.lang.ThreadGroup threadGroup,

                             java.lang.String name,

                             java.lang.Object... userObjects)
Constructs a thread with given user objects, the specified thread group and the specified name.

Parameters:
threadGroup - Thread group into which this thread will be executed.
name - Name of this thread.
userObjects - User objects that can be used by example in the run() method.
Method Detail

getUserObject


public <T> T getUserObject(int index)
Returns the user object at the specified index in the array of user objects. The returned user object is typed to the specified type if you parametrize this call.

Type Parameters:
T - Type of the returned user object.
Parameters:
index - Index of the user object in the array of user objects.
Returns:
The (eventually typed) user object at the specified index in the array of user objects.
Throws:
java.lang.ArrayIndexOutOfBoundsException - When the index is not valid for the array of user objects.
java.lang.ClassCastException - When the user object can't be typed to the specified type.
Since:
SkyMonome v1.1

getUserObject


public <T> T getUserObject(java.lang.Class<T> clazz,

                           int index)
Returns the user object at the specified index in the array of user objects. The returned user object is typed, if possible, to the specified type.

Type Parameters:
T - Type of the returned user object.
Parameters:
clazz - Class object which indicates the type of the returned user object.
index - Index of the user object in the array of user objects.
Returns:
The typed user object at the specified index in the array of user objects.
Throws:
java.lang.ArrayIndexOutOfBoundsException - When the index is not valid for the array of user objects.
java.lang.ClassCastException - When the user object can't be typed to the specified type.

run


public abstract void run()
Contains the main action of this thread. Implementors must redefine this method.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread