I don't want to sort facts outside of drools rules. The sorting is part of business requirements. My opinion is that is not a good thing to keep parts of business logic in different places.
I spent some time to figure out how it is possible to sort a collection of facts and here is my solution: --------------------------- function String factKey(Fact f) { return String.format( "%010d~~%s~~%s", f.getRank(), f.getName(), f.getValue() ); } query sortFactsQuery $factsMap: HashMap() from accumulate( $f: Fact(), init( HashMap map = new HashMap(); ), action( map.put(factKey($f), $f); ), reverse( map.remove(factKey($f)); ), result( map ) ) $sortedKeyList: TreeSet() from collect( String() from $factsMap.keySet() ) $sortedFacts: List() from accumulate( $key: String() from $sortedKeyList, collectList( $factsMap.get( $key ) ) ) end ----------------------- -- View this message in context: http://drools.46999.n3.nabble.com/facts-custom-sort-tp3538410p3541805.html Sent from the Drools: User forum mailing list archive at Nabble.com. _______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users