java - Drools - Check if map exist consecutive dates -
i have collection (map) contain data of 7 days. keys of hashmap dates in format yyyy-mm-dd
need create rule check if string exists inside list[string] in days , days consecutive dates. there way it?
i'm trying using contains it's not include checking of consecutive dates.
rule "bonus a" lock-on-active true when databinding : databinding($data : data) items : list( size > 6 ) collect( list(this contains "1" && contains "2" && contains "3" ) $data.values ) databinding.addpoint(7.5); end
and here code
map<string, object> data = new hashmap<string, object>(); data.put("2015-08-03", arrays.aslist("2", "3", "1", "4")); data.put("2015-08-05", arrays.aslist("2", "3", "1", "4")); data.put("2015-08-04", arrays.aslist("2", "3", "1", "4")); data.put("2015-08-07", arrays.aslist("2", "3", "1", "4")); data.put("2015-08-06", arrays.aslist("2", "3", "1", "4")); data.put("2015-08-09", arrays.aslist("2", "3", "1", "4")); data.put("2015-08-08", arrays.aslist("2", "3", "1", "4")); databinding databinding = new databinding(); databinding.setdata(data); ksession.insert(databinding); ksession.fireallrules();
thanks suggestion.
i suggest write static method checking whether set of 7 string values denotes 7 consecutive dates:
static boolean consecutive (set<string> dates){ // ... }
and add constraint rule:
rule "bonus a" when databinding : databinding($data : data) eval( consecutive( $data.keyset() ) ) items : list( size > 6 ) ...
there no simple way around this.
you may add method drl function, minor changes in syntax - see drools manual.
Comments
Post a Comment