org.d_haven.event.impl
Class ThresholdEnqueuePredicate

java.lang.Object
  extended by org.d_haven.event.impl.ThresholdEnqueuePredicate
All Implemented Interfaces:
EnqueuePredicate

public final class ThresholdEnqueuePredicate
extends java.lang.Object
implements EnqueuePredicate

The ThresholdEnqueuePredicate limits the elements that can be enqueued based on the size of the Pipe.


Field Summary
private  int m_threshold
           
 
Constructor Summary
ThresholdEnqueuePredicate(int limit)
          Create a new ThresholdEnqueuePredicate with the supplied limit.
 
Method Summary
 boolean accept(java.lang.Object[] elements, Sink modifyingSink)
          Returns true if the Sink size + the number of elements is less than the threshold.
 boolean accept(java.lang.Object element, Sink modifyingSink)
          Returns true if the Sink size + 1 (the element) is less than the threshold.
 int getThreshold()
          Get the threshold size.
private  boolean testThreshold(Sink modifyingSink, int numElements)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_threshold

private final int m_threshold
Constructor Detail

ThresholdEnqueuePredicate

public ThresholdEnqueuePredicate(int limit)
Create a new ThresholdEnqueuePredicate with the supplied limit.

Parameters:
limit - A number greater than zero
Method Detail

accept

public boolean accept(java.lang.Object element,
                      Sink modifyingSink)
Returns true if the Sink size + 1 (the element) is less than the threshold.

Specified by:
accept in interface EnqueuePredicate
Parameters:
element - the element being tested
modifyingSink - the sink to enqueue to
Returns:
true if we are under the threshold

accept

public boolean accept(java.lang.Object[] elements,
                      Sink modifyingSink)
Returns true if the Sink size + the number of elements is less than the threshold.

Specified by:
accept in interface EnqueuePredicate
Parameters:
elements - the elements being tested
modifyingSink - the sink to enqueue to
Returns:
true if we are under the threshold

getThreshold

public int getThreshold()
Get the threshold size.

Returns:
the threshold

testThreshold

private boolean testThreshold(Sink modifyingSink,
                              int numElements)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object