Class DoubleCQComparator

  • All Implemented Interfaces:
    java.util.Comparator, CQComparator

    public class DoubleCQComparator
    extends java.lang.Object
    implements CQComparator
    This class implements the CQComparator interface. It compares instances of Double. Therefore, all arguments passed to its methods have to be of type Double (or Double[] for the getBinWidth() method). If this is violated, a ClassCastException will be thrown. This class is used to test the CalendarQueue.
    Since:
    Ptolemy II 0.2
    Version:
    $Id$
    Author:
    Lukito Muliadi
    See Also:
    CQComparator, CalendarQueue
    Pt.AcceptedRating:
    Yellow (liuj)
    Pt.ProposedRating:
    Green (eal)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.Object object1, java.lang.Object object2)
      Compare the two argument.
      long getVirtualBinNumber​(java.lang.Object entry)
      Given an entry, a zero reference, and a bin width, return a virtual bin number for the entry.
      void setBinWidth​(java.lang.Object[] entryArray)
      Given an array of Double objects, find the 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, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • DoubleCQComparator

        public DoubleCQComparator()
    • Method Detail

      • compare

        public int compare​(java.lang.Object object1,
                           java.lang.Object object2)
        Compare the two argument. Return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. Both arguments have to be instances of Double, otherwise a ClassCastException will be thrown.
        Specified by:
        compare in interface java.util.Comparator
        Parameters:
        object1 - The first Double.
        object2 - The second Double.
        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 either argument is not an instance of Double.
      • getVirtualBinNumber

        public long getVirtualBinNumber​(java.lang.Object entry)
        Given an entry, a zero reference, and a bin width, return a virtual bin number for the entry. The virtual bin number is a quantized double. The calculation performed is:

        (entry - zeroReference) / binWidth,

        with the result cast to long. If the arguments are not instances of Double, then a ClassCastException will be thrown.
        Specified by:
        getVirtualBinNumber in interface CQComparator
        Parameters:
        entry - The entry.
        Returns:
        The virtual bin number for the entry, according to the zero reference and the bin width.
        Throws:
        java.lang.ClassCastException - If the arguments are not instances of Double.
      • setBinWidth

        public void setBinWidth​(java.lang.Object[] entryArray)
        Given an array of Double objects, find the appropriate bin width. By 'appropriate', the bin width is chosen such that on average the number of entry in all non-empty bins is equal to one. If the argument is null, return the default bin width, which is 1.0 for this implementation.
        Specified by:
        setBinWidth in interface CQComparator
        Parameters:
        entryArray - An array of Double objects.
        Throws:
        java.lang.ClassCastException - If one of the array elements is not an instance of Double.
      • setZeroReference

        public void setZeroReference​(java.lang.Object zeroReference)
        Set the zero reference, to be used in calculating the virtual bin number.
        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 Double.