KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > groupJep > function > GList


1 /* @author rich
2  * Created on 05-Mar-2004
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.groupJep.function;
9 import org.nfunk.jep.function.*;
10 import org.lsmp.djep.groupJep.*;
11 import org.lsmp.djep.groupJep.interfaces.*;
12
13 import java.util.*;
14 import org.nfunk.jep.*;
15 /**
16  * @author Rich Morris
17  * Created on 05-Mar-2004
18  */

19 public class GList extends PostfixMathCommand {
20     private GroupI group;
21     /**
22      *
23      */

24     private GList() { }
25     public GList(GroupI group)
26     {
27         numberOfParameters = -1;
28         this.group = group;
29     }
30
31     /**
32      * Calculates the result of applying the "+" operator to the arguments from
33      * the stack and pushes it back on the stack.
34      */

35     public void run(Stack stack) throws ParseException {
36         checkStack(stack);// check the stack
37
if(!(group instanceof HasListI))
38             throw new ParseException("List not defined for this group");
39         Number JavaDoc res[] = new Number JavaDoc[curNumberOfParameters];
40         // repeat summation for each one of the current parameters
41
for(int i=curNumberOfParameters-1;i>=0;--i) {
42             res[i] = (Number JavaDoc) stack.pop();
43         }
44         stack.push(((HasListI) group).list(res));
45         return;
46     }
47 }
48
Popular Tags