|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
不好意思,我实在看不明白,有人能帮忙解释一下这个方法是干什么用的吗?compiere的源码
Java code
/**
* Evaluate @context@=value or @context@!value or @context@^value.
* <pre>
* value: strips ' and " always (no escape or mid stream)
* value: can also be a context variable
* </pre>
* @param source class implementing get_ValueAsString(variable)
* @param logic logic tuple
* @return true or false
*/
private static boolean evaluateLogicTuple (Evaluatee source, String logic)
{
StringTokenizer st = new StringTokenizer (logic.trim(), "!=^><", true);
if (st.countTokens() != 3)
{
log.warning("Logic tuple does not comply with format "
+ "'@context@=value' where operand could be one of '=!^><' => " + logic);
return false;
}
// First Part
String first = st.nextToken().trim(); // get '@tag@'
String firstEval = first.trim();
if (first.indexOf('@') != -1) // variable
{
first = first.replace ('@', ' ').trim (); // strip 'tag'
firstEval = source.get_ValueAsString (first); // replace with it's value
if (firstEval == null)
firstEval = "";
}
firstEval = firstEval.replace('\'', ' ').replace('"', ' ').trim(); // strip ' and "
// Comperator
String operand = st.nextToken();
// Second Part
String second = st.nextToken(); // get value
String secondEval = second.trim();
if (second.indexOf('@') != -1) // variable
{
second = second.replace('@', ' ').trim(); // strip tag
secondEval = source.get_ValueAsString (second); // replace with it's value
if (secondEval == null)
secondEval = "";
}
secondEval = secondEval.replace('\'', ' ').replace('"', ' ').trim(); // strip ' and "
// Handling of ID compare (null => 0)
if (first.indexOf("_ID") != -1 && firstEval.length() == 0)
firstEval = "0";
if (second.indexOf("_ID") != -1 && secondEval.length() == 0)
secondEval = "0";
// Logical Comparison
boolean result = evaluateLogicTuple (firstEval, operand, secondEval);
//
if (log.isLevelFinest())
log.finest(logic
+ " => \"" + firstEval + "\" " + operand + " \"" + secondEval + "\" => " + result);
//
return result;
} // evaluateLogicTuple
代码来自:https://svn.bitsoftware.ro:8443/ ... util/Evaluator.java |
|