For the form "(type=sita##) && ((ctyp=fpl##) | | (ctyp=chg##) | | (ctyp=cnl##) | | (ctyp=dla##) | | (ctyp=dl##) | | (ctyp=ed##)) && (adep=zsss##)) "The string, often with a certain thing in the judging condition, to calculate the entire condition of the final result (True/false).
The following gives the Java code
1 Packagecom.test;2 3 ImportNet.sourceforge.jeval.Evaluator;4 5 Public classT1 {6 7 Public Static voidMain (string[] args)throwsException {8String condition = "(type=sita##) && (((ctyp=fpl##) | | (ctyp=chg##) | | (ctyp=cnl##) | | (ctyp=dla##) | | (ctyp=dl##) | | (ctyp=ed##)) && (adep=zsss##)) ";9Condition = replaceexpression (condition, "type=", "SITA", "=");TenCondition = replaceexpression (condition, "ctyp=", "FPL", "="); OneCondition = replaceexpression (condition, "adep=", "" "," = "); ASYSTEM.OUT.PRINTLN ("Condition:" +condition);//condition: (1) && ((1) | | (0) | | (0) | | (0) | | (0) | | (0)) && (0)) - - /** the * Numeric Expression parsing tool - * Evaluator need to download Jeval package, attached link after this article - */ -Evaluator Evaluator =NewEvaluator (); + Booleanb = evaluator.getbooleanresult (condition);//false - System.out.println (b); +System.out.println (Evaluator.evaluate ("2+3"));//5.0 A at } - - /** - * - * @paramcondition - * @paramReplace in * @paramtobecompared - * @paramoperators to * @return + * @throwsException throws an exception for non-conforming calculations - */ the Public Staticstring Replaceexpression (string condition, string replace, *String tobecompared, String operators)throwsException { $ while(Condition.contains (replace)) {Panax Notoginseng intStart =Condition.indexof (replace); - intEnd = Condition.indexof ("# #", start); theString Express =condition.substring (start, end); +Express =express.substring (Replace.length ()); A if(">=". Equals (Operators)) { the + if(Long.parselong (tobecompared) >=Long.parselong (Express)) { -Condition = condition.substring (0, start) + "1" $+ condition.substring (end + 2)); $}Else { -Condition = condition.substring (0, start) + "0" -+ condition.substring (end + 2)); the } -}Else if("<=". Equals (Operators)) {Wuyi if(Long.parselong (tobecompared) <=Long.parselong (Express)) { theCondition = condition.substring (0, start) + "1" -+ condition.substring (end + 2)); Wu}Else { -Condition = condition.substring (0, start) + "0" About+ condition.substring (end + 2)); $ } -}Else if(">". Equals (Operators)) { - - if(Long.parselong (tobecompared) >Long.parselong (Express)) { ACondition = condition.substring (0, start) + "1" ++ condition.substring (end + 2)); the}Else { -Condition = condition.substring (0, start) + "0" $+ condition.substring (end + 2)); the } the}Else if("<". Equals (Operators)) { the if(Long.parselong (tobecompared) <Long.parselong (Express)) { theCondition = condition.substring (0, start) + "1" -+ condition.substring (end + 2)); in}Else { theCondition = condition.substring (0, start) + "0" the+ condition.substring (end + 2)); About } the}Else if("!=". Equals (Operators)) { the if(!express.equals (tobecompared)) { theCondition = condition.substring (0, start) + "1" ++ condition.substring (end + 2)); -}Else { theCondition = condition.substring (0, start) + "0"Bayi+ condition.substring (end + 2)); the } the}Else { - if("raddress=". Equals (replace) { -string[] Tobecomparedarray = Tobecompared.split (""); theString flag = "0"; the for(String tobecomparedstring:tobecomparedarray) { the if(Express.equals (tobecomparedstring)) { theFlag = "1"; - Break; the } the } theCondition = condition.substring (0, start) +Flag94+ condition.substring (end + 2)); the the}Else { the if(Express.equals (tobecompared)) {98Condition = condition.substring (0, start) + "1" About+ condition.substring (end + 2)); -}Else {101Condition = condition.substring (0, start) + "0"102+ condition.substring (end + 2));103 }104 } the }106 }107 returncondition;108 }109}
Related jar package Download:http://files.cnblogs.com/files/x-jingxin/jeval.zip
Java Data processing