ptolemy.domains.de.kernel
Class DECQEventQueue.DECQComparator

java.lang.Object
  extended by ptolemy.domains.de.kernel.DECQEventQueue.DECQComparator
All Implemented Interfaces:
java.util.Comparator, CQComparator
Enclosing class:
DECQEventQueue

private static class DECQEventQueue.DECQComparator
extends java.lang.Object
implements CQComparator


Field Summary
private  double _binWidth
           
private  double _zeroReference
           
 
Constructor Summary
DECQEventQueue.DECQComparator()
          Construct a new comparator.
 
Method Summary
 int compare(java.lang.Object object1, java.lang.Object object2)
          Compare two arguments for order.
 long getVirtualBinNumber(java.lang.Object event)
          Given a DE event, return the virtual index of the bin that should contain this event.
 void setBinWidth(java.lang.Object[] entryArray)
          Given an array of DE events, set an appropriate bin width.
 void setZeroReference(java.lang.Object zeroReference)
          Set the zero reference, to be used in calculating the virtual bin number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

_binWidth

private double _binWidth

_zeroReference

private double _zeroReference
Constructor Detail

DECQEventQueue.DECQComparator

public DECQEventQueue.DECQComparator()
Construct a new comparator.

Method Detail

compare

public final int compare(java.lang.Object object1,
                         java.lang.Object object2)
Compare two arguments for order. Return a negative integer, zero, or a positive integer if the first argument is less than, equal to, or greater than the second. Both arguments must be instances of DEEvent. Otherwise a ClassCastException will be thrown. The compareTo() method of the first argument is used to do the comparison.

Specified by:
compare in interface java.util.Comparator
Parameters:
object1 - The first DE event.
object2 - The second DE event.
Returns:
A negative integer, zero, or a positive integer if the first argument is less than, equal to, or greater than the second.
Throws:
java.lang.ClassCastException - If any of the arguments is not an instance of DEEvent.

getVirtualBinNumber

public final long getVirtualBinNumber(java.lang.Object event)
Given a DE event, return the virtual index of the bin that should contain this event. If the argument is not an instance of DEEvent, then a ClassCastException will be thrown. If the bin number is larger than what can be represented in a long, then the low-order 64 bits will be returned. Note that this could change the sign of the result, but the way this is used in the CalendarQueue class, this is OK. It is converted to a bin number by masking some number of low-order bits, so the result will be unaffected by the sign error. Note that this method cannot return a long.MAX_VALUE, which is used internally by CalendarQueue class.

Specified by:
getVirtualBinNumber in interface CQComparator
Parameters:
event - The event.
Returns:
The index of the virtual bin containing the event.
Throws:
java.lang.ClassCastException - If the argument is not an instance of DEEvent.

setBinWidth

public void setBinWidth(java.lang.Object[] entryArray)
Given an array of DE events, set an appropriate bin width. This method assumes that no two DE events have the same time stamp, microstep, and depth. This method also assumes that the events are sorted in a time-increasing order. DEEventQueue. Note that even the time stamps may not be increasing, the receiver depths, or the microsteps may be increasing. This method attempts to choose the bin width so that the average number of entries in a bin is one. If the argument is null or is an array with length less than two, set the bin width to the default, which is 1.0 for this implementation.

Specified by:
setBinWidth in interface CQComparator
Parameters:
entryArray - An array of DE events.
Throws:
java.lang.ClassCastException - If any entry in the array is not an instance of DEEvent.

setZeroReference

public void setZeroReference(java.lang.Object zeroReference)
Set the zero reference, to be used in calculating the virtual bin number. The argument should be a DE event, otherwise a ClassCastException will be thrown.

Specified by:
setZeroReference in interface CQComparator
Parameters:
zeroReference - The starting point for bins.
Throws:
java.lang.ClassCastException - If the argument is not an instance of DEEvent.