KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nfunk > jep > function > List


1 /*****************************************************************************
2
3 JEP - Java Math Expression Parser 2.3.0
4       October 3 2004
5       (c) Copyright 2004, Nathan Funk and Richard Morris
6       See LICENSE.txt for license information.
7
8 *****************************************************************************/

9
10 package org.nfunk.jep.function;
11
12 import java.util.*;
13 import org.nfunk.jep.*;
14
15 /** The list function.
16  * Returns a Vector comprising all the children.
17  *
18  * @author Rich Morris
19  * Created on 29-Feb-2004
20  */

21 public class List extends PostfixMathCommand
22 {
23     public List()
24     {
25         numberOfParameters = -1;
26     }
27     
28     public void run(Stack inStack)
29         throws ParseException
30     {
31         checkStack(inStack); // check the stack
32
if(curNumberOfParameters <1)
33             throw new ParseException("Empty list");
34         Vector res = new Vector(curNumberOfParameters);
35         res.setSize(curNumberOfParameters);
36         for(int i=curNumberOfParameters-1;i>=0;--i)
37         {
38             Object JavaDoc param = inStack.pop();
39             res.setElementAt(param,i);
40         }
41         inStack.push(res);
42         return;
43     }
44 }
45
Popular Tags