1 9 10 package org.lsmp.djep.groupJep.function; 11 import org.nfunk.jep.function.*; 12 13 import java.util.*; 14 import org.nfunk.jep.*; 15 16 public class GLogical extends PostfixMathCommand 17 { 18 int id; 19 20 public GLogical(int id_in) 21 { 22 id = id_in; 23 numberOfParameters = 2; 24 } 25 26 public void run(Stack inStack) 27 throws ParseException 28 { 29 checkStack(inStack); 31 Object param2 = inStack.pop(); 32 Object param1 = inStack.pop(); 33 34 if ((param1 instanceof Boolean ) && (param2 instanceof Boolean )) 35 { 36 boolean a = ((Boolean )param1).booleanValue(); 37 boolean b = ((Boolean )param2).booleanValue(); 38 boolean flag=false; 39 40 switch (id) 41 { 42 case Logical.AND: 43 flag = a && b; 44 break; 45 case Logical.OR: 46 flag = a || b; 47 break; 48 default: 49 throw new ParseException("Illegal logical operator"); 50 } 51 inStack.push(flag ? Boolean.TRUE : Boolean.FALSE); } 53 else 54 { 55 throw new ParseException("Invalid parameter type"); 56 } 57 return; 58 } 59 } 60 | Popular Tags |