private IPattern findByFactPattern(List<IPattern> patterns, String boundName) { if ( boundName == null ) { return null; } for ( IPattern ifp : patterns ) { if ( ifp instanceof FactPattern ) { FactPattern fp = (FactPattern) ifp; if ( fp.getBoundName() != null && fp.getBoundName().equals( boundName ) ) { return fp; } } else if ( ifp instanceof FromEntryPointFactPattern ) { FromEntryPointFactPattern fefp = (FromEntryPointFactPattern) ifp; FactPattern fp = fefp.getFactPattern(); if ( fp.getBoundName() != null && fp.getBoundName().equals( boundName ) ) { return fp; } } } return null; }
private IPattern findByFactPattern(List<IPattern> patterns, String boundName) { if ( boundName == null ) { return null; } for ( IPattern ifp : patterns ) { if ( ifp instanceof FactPattern ) { FactPattern fp = (FactPattern) ifp; if ( fp.getBoundName() != null && fp.getBoundName().equals( boundName ) ) { return fp; } } else if ( ifp instanceof FromEntryPointFactPattern ) { FromEntryPointFactPattern fefp = (FromEntryPointFactPattern) ifp; FactPattern fp = fefp.getFactPattern(); if ( fp.getBoundName() != null && fp.getBoundName().equals( boundName ) ) { return fp; } } } return null; }
/** * This will return the FactPattern that a variable is bound Eto. * * @param var * The bound fact variable (NOT bound field). * @return null or the FactPattern found. */ public FactPattern getLHSBoundFact(final String var) { if ( this.lhs == null ) { return null; } for ( int i = 0; i < this.lhs.length; i++ ) { IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; if ( p.getBoundName() != null && var.equals( p.getBoundName() ) ) { return p; } } } return null; }
/** * This will return a List<String> of all FactPattern bindings * * @return The bindings or an empty list if no bindings are found. */ public List<String> getLHSBoundFacts() { if ( this.lhs == null ) { return Collections.emptyList(); } final List<String> list = new ArrayList<String>(); for ( int i = 0; i < this.lhs.length; i++ ) { IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; if ( p.getBoundName() != null ) { list.add( p.getBoundName() ); } } } return list; }
/** * This will return a List<String> of all FactPattern bindings * * @return The bindings or an empty list if no bindings are found. */ public List<String> getLHSBoundFacts() { if ( this.lhs == null ) { return Collections.emptyList(); } final List<String> list = new ArrayList<String>(); for ( int i = 0; i < this.lhs.length; i++ ) { IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; if ( p.getBoundName() != null ) { list.add( p.getBoundName() ); } } } return list; }
/** * This will return the FactPattern that a variable is bound Eto. * * @param var * The bound fact variable (NOT bound field). * @return null or the FactPattern found. */ public FactPattern getLHSBoundFact(final String var) { if ( this.lhs == null ) { return null; } for ( int i = 0; i < this.lhs.length; i++ ) { IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; if ( p.getBoundName() != null && var.equals( p.getBoundName() ) ) { return p; } } } return null; }
public ExpressionVariable(FactPattern fact) { super(fact.getBoundName(), fact.getFactType(), fact.getFactType()); if (!fact.isBound()) { throw new RuntimeException("the fact is not bounded: " + fact); } this.fact = fact; }
public ExpressionVariable(FactPattern fact) { super(fact.getBoundName(), fact.getFactType(), fact.getFactType()); if (!fact.isBound()) { throw new RuntimeException("the fact is not bounded: " + fact); } this.fact = fact; }
private void generateFactPattern( FactPattern pattern ) { if ( pattern.isNegated() ) { buf.append( "not " ); } else if ( pattern.isBound() ) { bindingsPatterns.put( pattern.getBoundName(), pattern ); buf.append( pattern.getBoundName() ); buf.append( " : " ); } if ( pattern.getFactType() != null ) { buf.append( pattern.getFactType() ); } buf.append( "( " ); // top level constraints if ( pattern.constraintList != null ) { generateConstraints( pattern ); } buf.append( ")" ); //Add CEP window definition CEPWindow window = pattern.getWindow(); if ( window.isDefined() ) { buf.append( " " ); buf.append( window.getOperator() ); buf.append( buildOperatorParameterDRL( window.getParameters() ) ); } }
private void generateFactPattern( FactPattern pattern ) { if ( pattern.isNegated() ) { buf.append( "not " ); } else if ( pattern.isBound() ) { bindingsPatterns.put( pattern.getBoundName(), pattern ); buf.append( pattern.getBoundName() ); buf.append( " : " ); } if ( pattern.getFactType() != null ) { buf.append( pattern.getFactType() ); } buf.append( "( " ); // top level constraints if ( pattern.constraintList != null ) { generateConstraints( pattern ); } buf.append( ")" ); //Add CEP window definition CEPWindow window = pattern.getWindow(); if ( window.isDefined() ) { buf.append( " " ); buf.append( window.getOperator() ); buf.append( buildOperatorParameterDRL( window.getParameters() ) ); } }
@Override public List<String> getLHSBoundFacts() { Set<String> facts = new HashSet<String>(); for ( CompositeColumn< ? extends BaseColumn> col : dtable.getConditions() ) { if ( col instanceof Pattern52 ) { Pattern52 p = (Pattern52) col; if ( p.isBound() ) { facts.add( p.getBoundName() ); } } else if ( col instanceof BRLConditionColumn ) { BRLConditionColumn brl = (BRLConditionColumn) col; for ( IPattern p : brl.getDefinition() ) { if ( p instanceof FactPattern ) { final FactPattern fp = (FactPattern) p; if ( fp.isBound() ) { facts.add( fp.getBoundName() ); } } } } } facts.addAll( super.getLHSBoundFacts() ); return new ArrayList<String>( facts ); }
@Override public List<String> getLHSBoundFacts() { Set<String> facts = new HashSet<String>(); for ( CompositeColumn< ? extends BaseColumn> col : dtable.getConditions() ) { if ( col instanceof Pattern52 ) { Pattern52 p = (Pattern52) col; if ( p.isBound() ) { facts.add( p.getBoundName() ); } } else if ( col instanceof BRLConditionColumn ) { BRLConditionColumn brl = (BRLConditionColumn) col; for ( IPattern p : brl.getDefinition() ) { if ( p instanceof FactPattern ) { final FactPattern fp = (FactPattern) p; if ( fp.isBound() ) { facts.add( fp.getBoundName() ); } } } } } facts.addAll( super.getLHSBoundFacts() ); return new ArrayList<String>( facts ); }
public String getBoundFactType(String boundName) { for ( CompositeColumn< ? > cc : this.conditionPatterns ) { if ( cc instanceof Pattern52 ) { Pattern52 p = (Pattern52) cc; if ( p.isBound() && p.getBoundName().equals( boundName ) ) { return p.getFactType(); } } else if ( cc instanceof BRLConditionColumn ) { BRLConditionColumn brl = (BRLConditionColumn) cc; for ( IPattern p : brl.getDefinition() ) { if ( p instanceof FactPattern ) { FactPattern fp = (FactPattern) p; if ( fp.isBound() && fp.getBoundName().equals( boundName ) ) { return fp.getFactType(); } } } } } return new String(); }
public String getBoundFactType(String boundName) { for ( CompositeColumn< ? > cc : this.conditionPatterns ) { if ( cc instanceof Pattern52 ) { Pattern52 p = (Pattern52) cc; if ( p.isBound() && p.getBoundName().equals( boundName ) ) { return p.getFactType(); } } else if ( cc instanceof BRLConditionColumn ) { BRLConditionColumn brl = (BRLConditionColumn) cc; for ( IPattern p : brl.getDefinition() ) { if ( p instanceof FactPattern ) { FactPattern fp = (FactPattern) p; if ( fp.isBound() && fp.getBoundName().equals( boundName ) ) { return fp.getFactType(); } } } } } return new String(); }
@Override public FactPattern getLHSBoundFact(String var) { for ( CompositeColumn< ? extends BaseColumn> col : dtable.getConditions() ) { if ( col instanceof Pattern52 ) { Pattern52 p = (Pattern52) col; if ( p.isBound() && p.getBoundName().equals( var ) ) { return new Pattern52FactPatternAdaptor( p ); } } else if ( col instanceof BRLConditionColumn ) { BRLConditionColumn brl = (BRLConditionColumn) col; for ( IPattern p : brl.getDefinition() ) { if ( p instanceof FactPattern ) { final FactPattern fp = (FactPattern) p; if ( fp.isBound() && fp.getBoundName().equals( var ) ) { return fp; } } } } } return super.getLHSBoundFact( var ); }
if ( p.isBound() && var.equals( p.getBoundName() ) ) { return p.getFactType();
@Override public FactPattern getLHSBoundFact(String var) { for ( CompositeColumn< ? extends BaseColumn> col : dtable.getConditions() ) { if ( col instanceof Pattern52 ) { Pattern52 p = (Pattern52) col; if ( p.isBound() && p.getBoundName().equals( var ) ) { return new Pattern52FactPatternAdaptor( p ); } } else if ( col instanceof BRLConditionColumn ) { BRLConditionColumn brl = (BRLConditionColumn) col; for ( IPattern p : brl.getDefinition() ) { if ( p instanceof FactPattern ) { final FactPattern fp = (FactPattern) p; if ( fp.isBound() && fp.getBoundName().equals( var ) ) { return fp; } } } } } return super.getLHSBoundFact( var ); }
private FactPattern visitFactPattern(FactPattern pattern) { FactPattern clone = new FactPattern(); clone.setBoundName( pattern.getBoundName() ); clone.setFactType( pattern.getFactType() ); clone.setNegated( pattern.isNegated() ); CEPWindow cloneCEPWindow = new CEPWindow(); cloneCEPWindow.setOperator( pattern.getWindow().getOperator() ); cloneCEPWindow.setParameters( cloneCEPWindowParameters( pattern.getWindow() ) ); clone.setWindow( cloneCEPWindow ); for ( FieldConstraint fc : pattern.getFieldConstraints() ) { clone.addConstraint( (FieldConstraint) visit( fc ) ); } return clone; }
private FactPattern visitFactPattern(FactPattern pattern) { FactPattern clone = new FactPattern(); clone.setBoundName( pattern.getBoundName() ); clone.setFactType( pattern.getFactType() ); clone.setNegated( pattern.isNegated() ); CEPWindow cloneCEPWindow = new CEPWindow(); cloneCEPWindow.setOperator( pattern.getWindow().getOperator() ); cloneCEPWindow.setParameters( cloneCEPWindowParameters( pattern.getWindow() ) ); clone.setWindow( cloneCEPWindow ); for ( FieldConstraint fc : pattern.getFieldConstraints() ) { clone.addConstraint( (FieldConstraint) visit( fc ) ); } return clone; }
@Test public void testFactPattern_Basics() { RuleModel model = new RuleModel(); model.lhs = new IPattern[1]; FactPattern fp0 = new FactPattern(); fp0.setBoundName( "$t0" ); fp0.setFactType( "FT0" ); fp0.setNegated( true ); model.lhs[0] = fp0; RuleModelCloneVisitor cloneVisitor = new RuleModelCloneVisitor(); RuleModel clone = cloneVisitor.visitRuleModel( model ); assertEquals( 1, clone.lhs.length ); assertNotSame( model.lhs[0], clone.lhs[0] ); assertNotNull( clone.lhs[0] ); assertTrue( clone.lhs[0] instanceof FactPattern ); FactPattern fp0Clone = (FactPattern) clone.lhs[0]; assertEquals( fp0.getBoundName(), fp0Clone.getBoundName() ); assertEquals( fp0.getFactType(), fp0Clone.getFactType() ); assertEquals( fp0.isNegated(), fp0Clone.isNegated() ); }