/** * This will add a top level constraint. */ public void addConstraint(final FieldConstraint constraint) { if ( constraintList == null ) constraintList = new CompositeFieldConstraint(); this.constraintList.addConstraint( constraint ); }
/** * This will add a top level constraint. */ public void addConstraint(final FieldConstraint constraint) { if ( constraintList == null ) constraintList = new CompositeFieldConstraint(); this.constraintList.addConstraint( constraint ); }
@Test public void testRemoveConstraint() { final CompositeFieldConstraint p = new CompositeFieldConstraint(); final SingleFieldConstraint x = new SingleFieldConstraint( "x" ); p.addConstraint( x ); final CompositeFieldConstraint y = new CompositeFieldConstraint( ); p.addConstraint( y ); assertEquals( 2, p.constraints.length ); p.removeConstraint( 1 ); assertEquals( 1, p.constraints.length ); assertEquals( x, p.constraints[0] ); }
@Test public void testAddConstraint() { final CompositeFieldConstraint p = new CompositeFieldConstraint(); final SingleFieldConstraint x = new SingleFieldConstraint( "x" ); p.addConstraint( x ); assertEquals( 1, p.constraints.length ); assertEquals( x, p.constraints[0] ); final SingleFieldConstraint y = new SingleFieldConstraint( "y" ); p.addConstraint( y ); assertEquals( 2, p.constraints.length ); assertEquals( x, p.constraints[0] ); assertEquals( y, p.constraints[1] ); }
@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 ) ); }
@Test public void testWithCompositeNesting() { final FactPattern p = new FactPattern(); final SingleFieldConstraint x = new SingleFieldConstraint( "x" ); p.addConstraint( x ); assertEquals( 1, p.constraintList.constraints.length ); assertEquals( x, p.constraintList.constraints[0] ); final CompositeFieldConstraint y = new CompositeFieldConstraint(); y.addConstraint( new SingleFieldConstraint("y") ); y.addConstraint( new SingleFieldConstraint("z") ); p.addConstraint( y ); assertEquals( 2, p.constraintList.constraints.length ); assertEquals( x, p.constraintList.constraints[0] ); assertEquals( y, p.constraintList.constraints[1] ); }
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.connectives[0].setOperator( "|| ==" ); X.connectives[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 );
sfc0p0.setOperator( "==" ); sfc0p0.setValue( "sfc0p0Value" ); cfc0.addConstraint( sfc0p0 ); sfc1p0.setOperator( "==" ); sfc1p0.setValue( "sfc1p0Value" ); cfc0.addConstraint( sfc1p0 ); sfc0p1.setOperator( "==" ); sfc0p1.setValue( "sfc0p1Value" ); cfc1.addConstraint( sfc0p1 ); sfc1p1.setOperator( "==" ); sfc1p1.setValue( "sfc1p1Value" ); cfc1.addConstraint( sfc1p1 );
X.connectives[ 0 ].setOperator( "|| ==" ); X.connectives[ 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 );
sfc0p0.setOperator( "==" ); sfc0p0.setValue( "sfc0p0Value" ); cfc0.addConstraint( sfc0p0 ); sfc1p0.setOperator( "==" ); sfc1p0.setValue( "sfc1p0Value" ); cfc0.addConstraint( sfc1p0 ); sfc0p1.setOperator( "==" ); sfc0p1.setValue( "sfc0p1Value" ); cfc1.addConstraint( sfc0p1 ); sfc1p1.setOperator( "==" ); sfc1p1.setValue( "sfc1p1Value" ); cfc1.addConstraint( sfc1p1 );
"sfc0p0Value" ); sfc0.setValue( "sfc0Value" ); cfc0.addConstraint( sfc0 ); "sfc1p0Value" ); sfc1.setValue( "sfc1Value" ); cfc0.addConstraint( sfc1 );