KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > xjep > function > Max


1 /* @author rich
2  * Created on 18-Nov-2003
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

8 package org.lsmp.djep.xjep.function;
9
10 import java.util.*;
11 import org.nfunk.jep.*;
12 import org.nfunk.jep.function.*;
13
14 /**
15  * A product function product(x^2,x,1,10) finds the product of x^2 with x running from 1 to 10.
16  *
17  * @author Rich Morris
18  * Created on 10-Sept-2004
19  */

20 public class Max extends SumType {
21
22     static Comparative comp = new Comparative(Comparative.LE);
23
24     public Max()
25     {
26         super("Max");
27     }
28
29         
30     public Object JavaDoc evaluate(Object JavaDoc elements[]) throws ParseException
31     {
32         Object JavaDoc ret;
33         ret = elements[0];
34         for(int i=1;i<elements.length;++i)
35         {
36             if(comp.gt(elements[i],ret))
37             ret = elements[i];
38         }
39         return ret;
40     }
41 }
42
Popular Tags