Create alias for conditions in Drools Decision table

十年热恋 提交于 2019-12-12 02:13:12

问题


Attached is my decision table, where in I'm using sv2.SV202_CompMedProcedId.get("SV202-02") several times in my condition.

Is there any way that we can create an alias for sv2.SV202_CompMedProcedId.get("SV202-02") (for example, S) and use that alias in my condition instead of using the entire line every time?

CONDITION
sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '70010' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '76499' || sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '76506' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '76999' || sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '77001' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '77032' || sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '77051' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '77059' || sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '77071' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '77084' || sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '77261' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '77999' || sv2.SV202_CompMedProcedId.get(""SV202-02"").Value >= '78000' && sv2.SV202_CompMedProcedId.get(""SV202-02"").Value <= '79999'

where sv2 is the object and SV2 is the class


回答1:


Yes, you can use an alias. Change your condition to:

$s : sv2.SV202_CompMedProcedId.get("SV202-02").Value >= '70010' && $s <= '76499' || $s >= '76506' && $s <= '76999' || $s >= '77001' && $s <= '77032' || $s >= '77051' && $s <= '77059' || $s >= '77071' && $s <= '77084' || $s >= '77261' && $s <= '77999' || $s >= '78000' && $s <= '79999'




回答2:


If this is frequent enough you might write and import a static Java (!) function:

public boolean isInRanges( Comparable value, Comparable... bounds ){
    for( int i = 0; i < bounds.length; i += 2 ){
        if( bounds[i].compareTo(value) <= 0 &&
            value.compareTo(bounds[i+1]) <= 0 ) return true; 
    }
    return false;
}

The simple call is obvious.

You can't use a DRL function: AFAIK, the vararg notation isn't implemented (but check).



来源:https://stackoverflow.com/questions/29993404/create-alias-for-conditions-in-drools-decision-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!