1 package com.teamkonzept.lib.math; 2 3 4 public class OperatorPriority implements Comparable { 5 6 static int LOGICAL_NOT_PRIORITY = 8; 7 static int MATH_FUNCTION_PRIORITY = 7; 8 static int MATH_EXP_PRIORITY = 6; 9 static int MATH_MULT_PRIORITY = 5; 10 static int MATH_ADD_PRIORITY = 4; 11 static int COMPARE_LESS_PRIORITY = 3; 12 static int COMPARE_EQUAL_PRIORITY = 2; 13 static int LOGICAL_OR_PRIORITY = 1; 14 static int LOGICAL_AND_PRIORITY = 0; 15 16 17 int paren = 0; 18 19 int symbol = 0; 20 21 int position = 0; 22 23 24 public OperatorPriority(int parenPriority, int symbolPriority, 25 int positionPriority){ 26 symbol = symbolPriority; 27 paren = parenPriority; 28 position = positionPriority; 29 } 30 31 36 public int compareTo(Object o){ 37 OperatorPriority op = (OperatorPriority)o; 38 if ( paren < op.paren ) 40 return -1; 41 if ( paren > op.paren ) 42 return 1; 43 if ( symbol < op.symbol ) 45 return -1; 46 if ( symbol > op.symbol ) 47 return 1; 48 if ( position > op.position ) 50 return -1; 51 if ( position < op.position ) 52 return 1; 53 return 0; 54 } 55 } 56 | Popular Tags |