private ConnectiveConstraint visitConnectiveConstraint(ConnectiveConstraint cc) { ConnectiveConstraint clone = new ConnectiveConstraint(); clone.setConstraintValueType( cc.getConstraintValueType() ); clone.setExpressionValue( (ExpressionFormLine) visit( cc.getExpressionValue() ) ); clone.setFieldName( cc.getFieldName() ); clone.setFieldType( cc.getFieldType() ); clone.setOperator( cc.getOperator() ); for ( Map.Entry<String, String> entry : cc.getParameters().entrySet() ) { clone.setParameter( entry.getKey(), entry.getValue() ); } clone.setValue( cc.getValue() ); return clone; }
private void fixConnectiveConstraints(SingleFieldConstraint sfc) { if ( sfc.connectives == null ) { return; } for ( ConnectiveConstraint cc : sfc.connectives ) { if ( cc.getFieldName() == null ) { cc.setFieldName( sfc.getFieldName() ); cc.setFieldType( sfc.getFieldType() ); } } }
private void fixConstraints(FactPattern fp, SingleFieldConstraint sfc) { sfc.setFactType( fp.getFactType() ); sfc.setFieldName( fixFieldName( sfc.getFieldName() ) ); if ( sfc.connectives == null ) { return; } for ( ConnectiveConstraint cc : sfc.connectives ) { cc.setFactType( fp.getFactType() ); cc.setFieldName( fixFieldName( cc.getFieldName() ) ); } }
sfc0cc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); sfc0cc0.setFieldName( "sfc0" ); sfc0cc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); sfc0cc0.setOperator( "|| ==" ); sfc0cc0.setParameter( "sfc0cc0p0", "sfc0cc0p0Value" ); sfc0cc0.setValue( "sfc0cc0Value" ); assertTrue( sfc0Clone.connectives[0] instanceof ConnectiveConstraint ); ConnectiveConstraint sfc0cc0Clone = (ConnectiveConstraint) sfc0Clone.connectives[0]; assertEquals( sfc0cc0.getConstraintValueType(), sfc0cc0Clone.getConstraintValueType() ); assertEquals( sfc0cc0.getFieldName(), sfc0cc0Clone.getFieldName() ); assertEquals( sfc0cc0.getFieldType(), sfc0cc0Clone.getFieldType() ); assertEquals( sfc0cc0.getOperator(), sfc0cc0Clone.getOperator() ); assertNotNull( sfc0cc0Clone.getParameter( "sfc0cc0p0" ) ); assertEquals( sfc0cc0.getParameter( "sfc0cc0p0" ), sfc0cc0Clone.getParameter( "sfc0cc0p0" ) ); assertEquals( sfc0cc0.getValue(), sfc0cc0Clone.getValue() );
@Test public void testConnective() { RuleModel m = new RuleModel(); m.name = "test literal strings"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); con.setFieldName( "field1" ); con.setOperator( "==" ); con.setValue( "goo" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_VARIABLE ); p.addConstraint( con ); ConnectiveConstraint connective = new ConnectiveConstraint(); connective.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); connective.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); connective.setOperator( "|| ==" ); connective.setValue( "blah" ); con.connectives = new ConnectiveConstraint[ 1 ]; con.connectives[ 0 ] = connective; m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); String expected = "rule \"test literal strings\" " + "\tdialect \"mvel\"\n when " + "Person( field1 == goo || == \"blah\" )" + " then " + "end"; assertEqualsIgnoreWhitespace( expected, result ); }
conn.getConstraintValueType(), conn.getFieldType(), conn.getOperator(), parameters, conn.getValue(), conn.getExpressionValue() );
private void visitSingleFieldConstraint(SingleFieldConstraint sfc) { InterpolationVariable var = new InterpolationVariable( sfc.getValue(), sfc.getFieldType(), factPattern.getFactType(), sfc.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == sfc.getConstraintValueType() && !vars.containsKey( var ) ) { vars.put( var, vars.size() ); } //Visit Connection constraints if ( sfc.connectives != null ) { for ( int i = 0; i < sfc.connectives.length; i++ ) { final ConnectiveConstraint cc = sfc.connectives[i]; InterpolationVariable ccVar = new InterpolationVariable( cc.getValue(), cc.getFieldType(), factPattern.getFactType(), cc.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.containsKey( ccVar ) ) { vars.put( ccVar, vars.size() ); } } } }
private void visitSingleFieldConstraint(SingleFieldConstraintEBLeftSide sfexp) { String genericType = sfexp.getExpressionLeftSide().getGenericType(); String factType = sfexp.getExpressionLeftSide().getPreviousClassType(); if ( factType == null ) { factType = sfexp.getExpressionLeftSide().getClassType(); } InterpolationVariable var = new InterpolationVariable( sfexp.getValue(), genericType, factType, sfexp.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == sfexp.getConstraintValueType() && !vars.containsKey( var ) ) { vars.put( var, vars.size() ); } //Visit Connection constraints if ( sfexp.connectives != null ) { for ( int i = 0; i < sfexp.connectives.length; i++ ) { final ConnectiveConstraint cc = sfexp.connectives[i]; InterpolationVariable ccVar = new InterpolationVariable( cc.getValue(), genericType, factType, cc.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.containsKey( ccVar ) ) { vars.put( ccVar, vars.size() ); } } } }
cons[0].setFieldType( "String" ); cons[0].connectives = new ConnectiveConstraint[1]; cons[0].connectives[0] = new ConnectiveConstraint( "Car", "age", "String", "&", "x" ); cons[0].connectives[0].setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); cons[1] = new SingleFieldConstraint( "make" ); cons[1].setFieldType( "Long" ); cons[1].connectives = new ConnectiveConstraint[1]; cons[1].connectives[0] = new ConnectiveConstraint( "Car", "make", "Long", "=", "2" ); cons[1].connectives[0].setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
/** * This adds a new connective. */ public void addNewConnective() { String fieldName = this.fieldName; String fieldType = this.fieldType; String factType = this.factType; if ( this.connectives == null ) { this.connectives = new ConnectiveConstraint[]{new ConnectiveConstraint( factType, fieldName, fieldType )}; } else { final ConnectiveConstraint[] newList = new ConnectiveConstraint[this.connectives.length + 1]; for ( int i = 0; i < this.connectives.length; i++ ) { newList[i] = this.connectives[i]; } newList[this.connectives.length] = new ConnectiveConstraint( factType, fieldName, fieldType ); this.connectives = newList; } }
X.setOperator( "==" ); X.connectives = new ConnectiveConstraint[ 1 ]; X.connectives[ 0 ] = new ConnectiveConstraint(); X.connectives[ 0 ].setConstraintValueType( ConnectiveConstraint.TYPE_LITERAL ); X.connectives[ 0 ].setFieldType( SuggestionCompletionEngine.TYPE_STRING ); X.connectives[ 0 ].setOperator( "|| ==" ); X.connectives[ 0 ].setValue( "bar" ); comp.addConstraint( X );
conn.getConstraintValueType(), conn.getFieldType(), conn.getOperator(), parameters, conn.getValue(), conn.getExpressionValue() );
private void visitSingleFieldConstraint(SingleFieldConstraint sfc) { InterpolationVariable var = new InterpolationVariable( sfc.getValue(), sfc.getFieldType(), factPattern.getFactType(), sfc.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == sfc.getConstraintValueType() && !vars.containsKey( var ) ) { vars.put( var, vars.size() ); } //Visit Connection constraints if ( sfc.connectives != null ) { for ( int i = 0; i < sfc.connectives.length; i++ ) { final ConnectiveConstraint cc = sfc.connectives[i]; InterpolationVariable ccVar = new InterpolationVariable( cc.getValue(), cc.getFieldType(), factPattern.getFactType(), cc.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.containsKey( ccVar ) ) { vars.put( ccVar, vars.size() ); } } } }
private void fixConnectiveConstraints(SingleFieldConstraint sfc) { if ( sfc.connectives == null ) { return; } for ( ConnectiveConstraint cc : sfc.connectives ) { if ( cc.getFieldName() == null ) { cc.setFieldName( sfc.getFieldName() ); cc.setFieldType( sfc.getFieldType() ); } } }
private void visitSingleFieldConstraint(SingleFieldConstraintEBLeftSide sfexp) { String genericType = sfexp.getExpressionLeftSide().getGenericType(); String factType = sfexp.getExpressionLeftSide().getPreviousClassType(); if ( factType == null ) { factType = sfexp.getExpressionLeftSide().getClassType(); } InterpolationVariable var = new InterpolationVariable( sfexp.getValue(), genericType, factType, sfexp.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == sfexp.getConstraintValueType() && !vars.containsKey( var ) ) { vars.put( var, vars.size() ); } //Visit Connection constraints if ( sfexp.connectives != null ) { for ( int i = 0; i < sfexp.connectives.length; i++ ) { final ConnectiveConstraint cc = sfexp.connectives[i]; InterpolationVariable ccVar = new InterpolationVariable( cc.getValue(), genericType, factType, cc.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.containsKey( ccVar ) ) { vars.put( ccVar, vars.size() ); } } } }
con.setFieldType( "String" ); con.connectives = new ConnectiveConstraint[1]; con.connectives[0] = new ConnectiveConstraint( "Car", "age", "String", "==", "x" ); con.connectives[0].setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); y.addConstraint( con );
private void fixConstraints(FactPattern fp, SingleFieldConstraint sfc) { sfc.setFactType( fp.getFactType() ); sfc.setFieldName( fixFieldName( sfc.getFieldName() ) ); if ( sfc.connectives == null ) { return; } for ( ConnectiveConstraint cc : sfc.connectives ) { cc.setFactType( fp.getFactType() ); cc.setFieldName( fixFieldName( cc.getFieldName() ) ); } }
/** * This adds a new connective. */ public void addNewConnective() { String fieldName = this.fieldName; String fieldType = this.fieldType; String factType = this.factType; if ( this.connectives == null ) { this.connectives = new ConnectiveConstraint[]{new ConnectiveConstraint( factType, fieldName, fieldType )}; } else { final ConnectiveConstraint[] newList = new ConnectiveConstraint[this.connectives.length + 1]; for ( int i = 0; i < this.connectives.length; i++ ) { newList[i] = this.connectives[i]; } newList[this.connectives.length] = new ConnectiveConstraint( factType, fieldName, fieldType ); this.connectives = newList; } }
private ConnectiveConstraint visitConnectiveConstraint(ConnectiveConstraint cc) { ConnectiveConstraint clone = new ConnectiveConstraint(); clone.setConstraintValueType( cc.getConstraintValueType() ); clone.setExpressionValue( (ExpressionFormLine) visit( cc.getExpressionValue() ) ); clone.setFieldName( cc.getFieldName() ); clone.setFieldType( cc.getFieldType() ); clone.setOperator( cc.getOperator() ); for ( Map.Entry<String, String> entry : cc.getParameters().entrySet() ) { clone.setParameter( entry.getKey(), entry.getValue() ); } clone.setValue( cc.getValue() ); return clone; }
X.setOperator( "==" ); X.connectives = new ConnectiveConstraint[1]; X.connectives[0] = new ConnectiveConstraint(); X.connectives[0].setConstraintValueType( ConnectiveConstraint.TYPE_LITERAL ); X.connectives[0].setOperator( "|| ==" ); X.connectives[0].setValue( "bar" ); comp.addConstraint( X );