jconch.pipeline.impl
Class TypeSafePipeLink<T>
java.lang.Object
jconch.pipeline.PipeLink<T>
jconch.pipeline.impl.TypeSafePipeLink<T>
- All Implemented Interfaces:
- PipeElement
public class TypeSafePipeLink<T>
- extends PipeLink<T>
Due to a limitation in Java's generic implementation, there is no way to go
from a parameterized type to a Class instance representing that type.
And since type erasure undermines casts to parameterized types, there is no
run-time type safety guarantied through parameterized types alone.
This class works around that by taking in a Class instance which can
then be used to perform run-time type checks.
|
Constructor Summary |
protected |
TypeSafePipeLink(java.util.concurrent.BlockingQueue<T> queue,
java.lang.Class<T> elementClass)
|
|
Method Summary |
boolean |
add(T in)
Adds an element into the link, if at all possible. |
java.lang.Class<T> |
getElementClass()
Provides the element class. |
| Methods inherited from class jconch.pipeline.PipeLink |
breakLink, clearQueue, get, getAddTimeout, getFetchTimeout, getQueueLength, getRemainingCapacity, registerSource, setAddTimeout, setFetchTimeout, start |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TypeSafePipeLink
protected TypeSafePipeLink(java.util.concurrent.BlockingQueue<T> queue,
java.lang.Class<T> elementClass)
-
- Parameters:
elementClass - The class of elements to be added.
- Throws:
org.apache.commons.lang.NullArgumentException - If elementClass is null.
add
public boolean add(T in)
- Adds an element into the link, if at all possible.
- Overrides:
add in class PipeLink<T>
- Parameters:
in - The element to add.
- Returns:
true if the add succeeded
- Throws:
org.apache.commons.lang.IllegalClassException - If in is not an element of the type represented by
getElementClass().
getElementClass
public java.lang.Class<T> getElementClass()
- Provides the element class.
- Returns:
- The
Class instance representing the contract that classes
must adhere to. Never null.