forked from apache/incubator-kie-drools
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for expressions with 4 and 5 variables + fix forall in ex…
…ecutable model
- Loading branch information
1 parent
3354409
commit c1ba8c3
Showing
13 changed files
with
247 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
.../drools-canonical-model/src/main/java/org/drools/model/constraints/SingleConstraint4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.drools.model.constraints; | ||
|
||
import org.drools.model.Variable; | ||
import org.drools.model.functions.LambdaPrinter; | ||
import org.drools.model.functions.Predicate4; | ||
import org.drools.model.functions.PredicateN; | ||
import org.drools.model.impl.ModelComponent; | ||
import org.drools.model.view.Expr4ViewItemImpl; | ||
|
||
public class SingleConstraint4<A, B, C, D> extends AbstractSingleConstraint { | ||
|
||
private final Variable<A> var1; | ||
private final Variable<B> var2; | ||
private final Variable<C> var3; | ||
private final Variable<D> var4; | ||
private final Predicate4<A, B, C, D> predicate; | ||
|
||
public SingleConstraint4( Variable<A> var1, Variable<B> var2, Variable<C> var3, Variable<D> var4, Predicate4<A, B, C, D> predicate) { | ||
super( LambdaPrinter.print(predicate) ); | ||
this.var1 = var1; | ||
this.var2 = var2; | ||
this.var3 = var3; | ||
this.var4 = var4; | ||
this.predicate = predicate; | ||
} | ||
|
||
public SingleConstraint4( String exprId, Variable<A> var1, Variable<B> var2, Variable<C> var3, Variable<D> var4, Predicate4<A, B, C, D> predicate) { | ||
super(exprId); | ||
this.var1 = var1; | ||
this.var2 = var2; | ||
this.var3 = var3; | ||
this.var4 = var4; | ||
this.predicate = predicate; | ||
} | ||
|
||
public SingleConstraint4( Expr4ViewItemImpl<A, B, C, D> expr) { | ||
this(expr.getExprId(), expr.getFirstVariable(), expr.getSecondVariable(), expr.getThirdVariable(), expr.getForthVariable(), expr.getPredicate()); | ||
setReactiveProps( expr.getReactiveProps() ); | ||
} | ||
|
||
@Override | ||
public Variable[] getVariables() { | ||
return new Variable[]{var1, var2, var3}; | ||
} | ||
|
||
@Override | ||
public PredicateN getPredicate() { | ||
return objs -> { | ||
return predicate.test((A) objs[0], (B) objs[1], (C) objs[2], (D) objs[3]); | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean isEqualTo( ModelComponent o ) { | ||
if ( this == o ) return true; | ||
if ( o == null || getClass() != o.getClass() ) return false; | ||
|
||
SingleConstraint4<?, ?, ?, ?> that = ( SingleConstraint4<?, ?, ?, ?> ) o; | ||
|
||
if ( !ModelComponent.areEqualInModel( var1, that.var1 ) ) return false; | ||
if ( !ModelComponent.areEqualInModel( var2, that.var2 ) ) return false; | ||
if ( !ModelComponent.areEqualInModel( var3, that.var3 ) ) return false; | ||
if ( !ModelComponent.areEqualInModel( var4, that.var4 ) ) return false; | ||
return predicate.equals( that.predicate ); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
.../drools-canonical-model/src/main/java/org/drools/model/constraints/SingleConstraint5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.drools.model.constraints; | ||
|
||
import org.drools.model.Variable; | ||
import org.drools.model.functions.LambdaPrinter; | ||
import org.drools.model.functions.Predicate5; | ||
import org.drools.model.functions.PredicateN; | ||
import org.drools.model.impl.ModelComponent; | ||
import org.drools.model.view.Expr5ViewItemImpl; | ||
|
||
public class SingleConstraint5<A, B, C, D, E> extends AbstractSingleConstraint { | ||
|
||
private final Variable<A> var1; | ||
private final Variable<B> var2; | ||
private final Variable<C> var3; | ||
private final Variable<D> var4; | ||
private final Variable<E> var5; | ||
private final Predicate5<A, B, C, D, E> predicate; | ||
|
||
public SingleConstraint5( Variable<A> var1, Variable<B> var2, Variable<C> var3, Variable<D> var4, Variable<E> var5, Predicate5<A, B, C, D, E> predicate) { | ||
super( LambdaPrinter.print(predicate) ); | ||
this.var1 = var1; | ||
this.var2 = var2; | ||
this.var3 = var3; | ||
this.var4 = var4; | ||
this.var5 = var5; | ||
this.predicate = predicate; | ||
} | ||
|
||
public SingleConstraint5( String exprId, Variable<A> var1, Variable<B> var2, Variable<C> var3, Variable<D> var4, Variable<E> var5, Predicate5<A, B, C, D, E> predicate) { | ||
super(exprId); | ||
this.var1 = var1; | ||
this.var2 = var2; | ||
this.var3 = var3; | ||
this.var4 = var4; | ||
this.var5 = var5; | ||
this.predicate = predicate; | ||
} | ||
|
||
public SingleConstraint5( Expr5ViewItemImpl<A, B, C, D, E> expr) { | ||
this(expr.getExprId(), expr.getFirstVariable(), expr.getSecondVariable(), expr.getThirdVariable(), expr.getForthVariable(), expr.getFifthVariable(), expr.getPredicate()); | ||
setReactiveProps( expr.getReactiveProps() ); | ||
} | ||
|
||
@Override | ||
public Variable[] getVariables() { | ||
return new Variable[]{var1, var2, var3}; | ||
} | ||
|
||
@Override | ||
public PredicateN getPredicate() { | ||
return objs -> { | ||
return predicate.test((A) objs[0], (B) objs[1], (C) objs[2], (D) objs[3], (E) objs[4]); | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean isEqualTo( ModelComponent o ) { | ||
if ( this == o ) return true; | ||
if ( o == null || getClass() != o.getClass() ) return false; | ||
|
||
SingleConstraint5<?, ?, ?, ?, ?> that = ( SingleConstraint5<?, ?, ?, ?, ?> ) o; | ||
|
||
if ( !ModelComponent.areEqualInModel( var1, that.var1 ) ) return false; | ||
if ( !ModelComponent.areEqualInModel( var2, that.var2 ) ) return false; | ||
if ( !ModelComponent.areEqualInModel( var3, that.var3 ) ) return false; | ||
if ( !ModelComponent.areEqualInModel( var4, that.var4 ) ) return false; | ||
if ( !ModelComponent.areEqualInModel( var4, that.var4 ) ) return false; | ||
if ( !ModelComponent.areEqualInModel( var5, that.var5 ) ) return false; | ||
return predicate.equals( that.predicate ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
drools-model/drools-canonical-model/src/main/java/org/drools/model/view/ExprNViewItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2005 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.drools.model.view; | ||
|
||
public interface ExprNViewItem<T> extends ExprViewItem<T> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.