It is possible to hide the eval for computing the intersection in a DSL.
Given
public class Element {
private String name;
private Set<Integer> numbers;
public Element( String name, Integer... numbers ){ ... }
// getters...
public boolean disjointWith( Element other ){
Set<Integer> ownNumbers = new HashSet<Integer>( this.numbers );
ownNumbers.retainAll( other.getNumbers() );
return ownNumbers.isEmpty();
}
}
and the dsl
[when]There is an element {eVar}={eVar} : Element()
[when]- called {nVar}={nVar} : name
[when]- other than {oVar}=this != {oVar}
[when]- where {eVar} is disjoint from {oVar}=eval(
{eVar}.disjointWith( {oVar} ) )
[when]- where {eVar} intersects with {oVar}=eval( !
{eVar}.disjointWith( {oVar} ) )
[then]show disjoint {n1Var} and {n2Var}=System.out.println( {n1Var} +
" and " + {n2Var} + " are disjoint.");
[then]show intersecting {n1Var} and {n2Var}=System.out.println(
{n1Var} + " and " + {n2Var} + " intersect.");
you can write the drsl
package appl.domain
expander elements.dsl
rule "find disjoint pairs"
when
There is an element e1
- called n1
There is an element e2
- called n2
- other than e1
- where e1 is disjoint from e2
then
show disjoint n1 and n2
end
On 25 August 2010 16:55, mechlife <gaiamech(a)gmail.com> wrote:
Thanks for your response.
I need to use it like 1-4 times depending on what the legacy rules are setup
on one rule but i do have thousands of rules.
Also, a future state might be to get these imported into a tool for business
users to start writing these and would definitely be more pleasing if they
had an operator that they could use.
Would you be able to point me to some resources on how to do the custom
operator
if the need arise.
thanks again for your time.
--
View this message in context:
http://drools-java-rules-engine.46999.n3.nabble.com/comparing-an-intersec...
Sent from the Drools - User mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users