/** * This will add a top level constraint. */ public void addConstraint( final FieldConstraint constraint ) { if ( constraintList == null ) { constraintList = new CompositeFieldConstraint(); } this.constraintList.addConstraint( constraint ); }
public FieldConstraint asFieldConstraint( FactPattern factPattern ) { CompositeFieldConstraint comp = new CompositeFieldConstraint(); comp.setCompositeJunctionType( connector.equals( "&&" ) ? CompositeFieldConstraint.COMPOSITE_TYPE_AND : CompositeFieldConstraint.COMPOSITE_TYPE_OR ); for ( Expr expr : subExprs ) { comp.addConstraint( expr.asFieldConstraint( factPattern ) ); } return comp; } }
@Test public void testScopedVariablesWithCompositeFact() { RuleModel m = new RuleModel(); FactPattern p = new FactPattern(); CompositeFieldConstraint cf = new CompositeFieldConstraint(); cf.addConstraint( new SingleFieldConstraint( "x" ) ); p.addConstraint( cf ); SingleFieldConstraint sf = new SingleFieldConstraint( "q" ); sf.setFieldBinding( "abc" ); p.addConstraint( sf ); SingleFieldConstraint sf2 = new SingleFieldConstraint( "q" ); sf2.setFieldBinding( "qed" ); cf.addConstraint( sf2 ); m.addLhsItem( p ); List vars = m.getAllVariables(); assertEquals( 1, vars.size() ); assertEquals( "abc", vars.get( 0 ) ); } /*
sfc1.setValue( "gooValue" ); sfc1.setOperator( "==" ); comp.addConstraint( sfc1 ); sfc2.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); sfc2.setOperator( "!= null" ); comp.addConstraint( sfc2 ); sfc3.setValue( "barValue" ); sfc3.setOperator( "==" ); comp.addConstraint( sfc3 );
sfc1.setValue( "gooValue" ); sfc1.setOperator( "==" ); comp.addConstraint( sfc1 ); sfc2.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); sfc2.setOperator( "!= null" ); comp.addConstraint( sfc2 ); sfc3.setValue( "barValue" ); sfc3.setOperator( "==" ); comp.addConstraint( sfc3 );
X.getConnectives()[ 0 ].setOperator( "|| ==" ); X.getConnectives()[ 0 ].setValue( "bar" ); comp.addConstraint( X ); Y.setValue( "foo" ); Y.setOperator( "==" ); comp.addConstraint( Y ); Q1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); comp2.addConstraint( Q1 ); Q2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); comp2.addConstraint( Q2 ); comp.addConstraint( comp2 );
sfc1.setValue( "gooValue" ); sfc1.setOperator( "==" ); comp.addConstraint( sfc1 ); sfc2.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); sfc2.setOperator( "!= null" ); comp.addConstraint( sfc2 ); sfc3.setValue( "barValue" ); sfc3.setOperator( "==" ); comp.addConstraint( sfc3 );
sfc1.setValue( "gooValue" ); sfc1.setOperator( "==" ); comp.addConstraint( sfc1 ); sfc2.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); sfc2.setOperator( "!= null" ); comp.addConstraint( sfc2 ); sfc3.setValue( "barValue" ); sfc3.setOperator( "==" ); comp.addConstraint( sfc3 );