Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Scaler.java

Go to the documentation of this file.
00001 // file:    Scaler.java
00002 // author:  Robert M. Keller
00003 // purpose: Example of a Function1 object
00004 
00005 /**
00006  * A Scaler is a Function1 object that can be used to scale a list of
00007  * Numbers by a scale factor.  If both the scale factor and the function
00008  * argument are Integer or Long, a Long will be returned.  Otherwise a
00009  * Double will be returned.
00010  */
00011 
00012 class Scaler implements Function1
00013 {
00014 private Number factor;
00015 
00016 /**
00017  * Create a Scaler with a specific scale factor.
00018  * @param _factor the factor to be used
00019  */
00020 
00021 Scaler(Number _factor)
00022   {
00023   factor = _factor;
00024   }
00025 
00026 
00027 /**
00028  * Apply this Scaler object to an Object x, which should be a Number.
00029  * If x is not a number, a ClassCastException will be thrown.
00030  *
00031  * @param x the Object to which this function is applied
00032  * @return a Double containing this Scaler's factor times the argument's value
00033  */
00034 
00035 public Object apply(Object x)
00036   {
00037   return Multiplier.multiply(factor, x);
00038   }
00039 }

Generated at Wed Feb 19 23:28:36 2003 for OpenList by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001