Class SensorComparator

java.lang.Object
  extended by SensorComparator
All Implemented Interfaces:
java.util.Comparator<FinchSensor>
Direct Known Subclasses:
AccelComparator, LightComparator, TemperatureComparator, ZaccelComparator

public abstract class SensorComparator
extends java.lang.Object
implements java.util.Comparator<FinchSensor>

Superclass of our various Comparator objects. The instantiation of a child of this class will specify:
1. compare() (per the Comparator interface requirements)
2. doubleValue() Returns the corresponding value of the from the FinchSensor
3. toString() Returns a string that describes the child

Author:
Andrew H. Fagg and Steven Ness

Constructor Summary
SensorComparator()
           
 
Method Summary
protected static double arrayMagnitude(double[] vec)
          Compute the magnitude (or length) of a vector (specifically, the L2 norm)
protected static int compare(double a, double b)
          Quick method used to compare doubles
protected static int compare(int a, int b)
          Quick method used to compare integers a and b
abstract  double doubleValue(FinchSensor obj)
          Return the value of obj that is specified by the instantiation of the child class.
protected static int sum(int[] vals)
          Return the sum over an array of ints
abstract  java.lang.String toString()
          Force the child class to return a string that describes itself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
compare, equals
 

Constructor Detail

SensorComparator

public SensorComparator()
Method Detail

compare

protected static int compare(int a,
                             int b)
Quick method used to compare integers a and b

Parameters:
a -
b -
Returns:
1 if a is greater than b, -1 if the reverse is true, and 0 if they are equal

compare

protected static int compare(double a,
                             double b)
Quick method used to compare doubles

Parameters:
a -
b -
Returns:
1 if a is greater than b, -1 if the reverse is true, and 0 if they are equal

sum

protected static int sum(int[] vals)
Return the sum over an array of ints

Parameters:
vals - Array of integers
Returns:
Sum over the array.

arrayMagnitude

protected static double arrayMagnitude(double[] vec)
Compute the magnitude (or length) of a vector (specifically, the L2 norm)

Parameters:
vec - An array of doubles
Returns:
The vector magnitude

doubleValue

public abstract double doubleValue(FinchSensor obj)
Return the value of obj that is specified by the instantiation of the child class.

Parameters:
obj - A FinchSensor sample
Returns:
The value from obj that is specified by the child class

toString

public abstract java.lang.String toString()
Force the child class to return a string that describes itself.

Overrides:
toString in class java.lang.Object
Returns:
The self-describing string.