本文整理了Java中org.kie.api.runtime.rule.Match
类的一些代码示例,展示了Match
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Match
类的具体详情如下:
包路径:org.kie.api.runtime.rule.Match
类名称:Match
暂无
代码示例来源:origin: kiegroup/jbpm
public boolean accept(Match activation) {
return !"Cancel".equals(activation.getRule().getName());
}
}
代码示例来源:origin: org.drools/drools-compiler
@Override
public void onDeleteMatch( Match match ) {
String rule = match.getRule().getName();
if (rule.equals( "Negative" )) {
list.remove("-" + match.getDeclarationValue( "$n" ));
}
}
} );
代码示例来源:origin: org.kie/kie-api
public void printFacts( PrintStream pStream ){
Collection< ? extends FactHandle> handles = match.getFactHandles();
for( FactHandle handle: handles ) {
Object object = workingMemory.getObject( handle );
if( object != null ){
pStream.println( " Fact " + object.getClass().getSimpleName() +
": " + object.toString() );
}
}
}
代码示例来源:origin: kiegroup/jbpm
protected boolean checkDeclarationMatch(Match match, String matchVariable) {
if (matchVariable == null) {
// no extra check is needed
return true;
}
Object dec = match.getDeclarationIds().contains("$" + matchVariable) ? match.getDeclarationValue("$" + matchVariable) : match.getDeclarationValue(matchVariable);
Object var = getVariable(matchVariable);
boolean check = var.equals(dec);
return check;
}
代码示例来源:origin: org.drools/drools-compiler
@Test(timeout=10000)
public void testIsAOperator() {
String source = "org/drools/compiler/factmodel/traits/testTraitIsA2.drl";
KieSession ksession = getSession( source );
TraitFactory.setMode( mode, ksession.getKieBase() );
AgendaEventListener ael = mock( AgendaEventListener.class );
ksession.addEventListener( ael );
Person student = new Person( "student", 18 );
ksession.insert( student );
ksession.fireAllRules();
ArgumentCaptor<AfterMatchFiredEvent> cap = ArgumentCaptor.forClass( AfterMatchFiredEvent.class );
verify( ael,
times( 3 ) ).afterMatchFired( cap.capture() );
List<AfterMatchFiredEvent> values = cap.getAllValues();
assertThat( values.get( 0 ).getMatch().getRule().getName(),
is( "create student" ) );
assertThat( values.get( 1 ).getMatch().getRule().getName(),
is( "print student" ) );
assertThat( values.get( 2 ).getMatch().getRule().getName(),
is( "print school" ) );
}
代码示例来源:origin: org.drools/drools-compiler
private void testAgendaFilter(final AgendaFilter agendaFilter, final String expectedMatchingRuleName) {
final String str = "package org.drools.compiler\n" +
"rule Aaa when then end\n" +
"rule Bbb when then end\n";
final KieBase kbase = loadKnowledgeBaseFromString(str);
final KieSession ksession = createKnowledgeSession(kbase);
final org.kie.api.event.rule.AgendaEventListener ael = mock(org.kie.api.event.rule.AgendaEventListener.class);
ksession.addEventListener(ael);
final int rules = ksession.fireAllRules(agendaFilter);
assertEquals(1, rules);
final ArgumentCaptor<org.kie.api.event.rule.AfterMatchFiredEvent> arg = ArgumentCaptor.forClass(org.kie.api.event.rule.AfterMatchFiredEvent.class);
verify(ael).afterMatchFired(arg.capture());
assertThat(arg.getValue().getMatch().getRule().getName(), is(expectedMatchingRuleName));
}
}
代码示例来源:origin: org.drools/drools-compiler
kbase.addPackages( kbuilder.getKnowledgePackages() );
KieSession ksession = kbase.newKieSession();
AgendaEventListener ael = mock( AgendaEventListener.class );
ksession.addEventListener( ael );
ksession.fireAllRules();
verify( ael, never() ).afterMatchFired( any( AfterMatchFiredEvent.class ) );
assertFalse( kbuilder.getErrors().toString(), kbuilder.hasErrors() );
ksession.fireAllRules();
ArgumentCaptor<AfterMatchFiredEvent> capt = ArgumentCaptor.forClass( AfterMatchFiredEvent.class );
verify( ael, times(1) ).afterMatchFired( capt.capture() );
assertThat( "R1", is( capt.getValue().getMatch().getRule().getName() ) );
ksession.fireAllRules();
verify( ael, times(2) ).afterMatchFired( capt.capture() );
assertThat( "R2", is( capt.getAllValues().get( 2 ).getMatch().getRule().getName() ) );
ksession.dispose();
代码示例来源:origin: org.drools/drools-reteoo
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
Match activation = cap.getValue().getMatch();
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
is( 18 ) );
assertThat( ((Number) activation.getDeclarationValue( "$min" )).intValue(),
is( 3 ) );
assertThat( ((Number) activation.getDeclarationValue( "$avg" )).intValue(),
is( 6 ) );
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
is( 24 ) );
assertThat( ((Number) activation.getDeclarationValue( "$min" )).intValue(),
is( 5 ) );
assertThat( ((Number) activation.getDeclarationValue( "$avg" )).intValue(),
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
is( 32 ) );
assertThat( ((Number) activation.getDeclarationValue( "$min" )).intValue(),
is( 15 ) );
assertThat( ((Number) activation.getDeclarationValue( "$avg" )).intValue(),
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
is( 17 ) );
assertThat( ((Number) activation.getDeclarationValue( "$min" )).intValue(),
is( 17 ) );
assertThat( ((Number) activation.getDeclarationValue( "$avg" )).intValue(),
代码示例来源:origin: org.drools/drools-compiler
final org.kie.api.event.rule.AgendaEventListener ael = mock(org.kie.api.event.rule.AgendaEventListener.class);
ksession.addEventListener(ael);
c3.addCheese(new Cheese("muzzarella", 30));
ksession.insert(c1);
ksession.insert(c2);
ksession.insert(c3);
ksession.fireAllRules();
final ArgumentCaptor<AfterMatchFiredEvent> captor = ArgumentCaptor.forClass(org.kie.api.event.rule.AfterMatchFiredEvent.class);
verify(ael, times(2)).afterMatchFired(captor.capture());
final List<org.kie.api.event.rule.AfterMatchFiredEvent> values = captor.getAllValues();
assertThat(values.get(0).getMatch().getObjects().get(0), is(c1));
assertThat(values.get(1).getMatch().getObjects().get(0), is(c2));
ksession.dispose();
代码示例来源:origin: org.drools/drools-compiler
kbase.addPackages( Collections.singletonList( kpkg ) );
KieSession ksession = kbase.newKieSession();
AgendaEventListener ael = mock( AgendaEventListener.class );
ksession.addEventListener( ael );
ksession.insert( new StockTick(1, "RHT", 80, 1 ) );
ksession.insert( new StockTick(2, "RHT", 100, 10 ) );
int rules = ksession.fireAllRules();
assertEquals( 1, rules );
ArgumentCaptor<AfterMatchFiredEvent> cap = ArgumentCaptor.forClass( AfterMatchFiredEvent.class );
verify( ael ).afterMatchFired(cap.capture());
assertThat( ((Number) cap.getValue().getMatch().getDeclarationValue( "$sum" )).intValue(), is( 180 ) );
assertThat( ((Number) cap.getValue().getMatch().getDeclarationValue( "$cnt" )).intValue(), is( 2 ) );
代码示例来源:origin: org.drools/drools-reteoo
org.kie.api.event.rule.AgendaEventListener ael = mock( org.kie.api.event.rule.AgendaEventListener.class );
ksession.addEventListener( ael );
ksession.fireAllRules();
ArgumentCaptor<org.kie.api.event.rule.AfterMatchFiredEvent> captor = ArgumentCaptor.forClass( org.kie.api.event.rule.AfterMatchFiredEvent.class );
verify( ael, times( 2 ) ).afterMatchFired(captor.capture());
List<org.kie.api.event.rule.AfterMatchFiredEvent> values = captor.getAllValues();
assertThat( (Cheesery) values.get( 0 ).getMatch().getObjects().get( 0 ), is( c1 ) );
assertThat( (Cheesery) values.get( 1 ).getMatch().getObjects().get( 0 ), is( c2 ) );
代码示例来源:origin: org.drools/drools-compiler
ksession.addEventListener( new AgendaEventListener() {
ksession.setGlobal( "list",
list );
ksession.insert( "go1" );
FactHandle go2 = ksession.insert( "go2" );
ksession.fireAllRules();
cancelled.size() );
assertEquals( "rule1",
((MatchCancelledEvent) cancelled.get( 0 )).getMatch().getRule().getName() );
ksession.dispose();
代码示例来源:origin: org.drools/drools-compiler
@Test
public void testPopulatedSingleRuleNoSharingWithSubnetworkAtStart() throws Exception {
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
InternalWorkingMemory wm = ((InternalWorkingMemory)kbase.newKieSession());
wm.insert(new A(1));
wm.insert(new A(2));
wm.insert(new D(1));
wm.insert(new E(1));
wm.insert(new C(2));
wm.fireAllRules();
kbase.addPackages( buildKnowledgePackage("r1", " A() not( B() and C() ) D() E()\n") );
List list = new ArrayList();
wm.setGlobal("list", list);
wm.fireAllRules();
assertEquals(2, list.size() );
assertEquals( "r1", ((Match)list.get(0)).getRule().getName() );
assertEquals( "r1", ((Match)list.get(1)).getRule().getName() );
kbase.removeRule("org.kie", "r1");
wm.insert(new A(1));
wm.fireAllRules();
assertEquals(2, list.size() );
}
代码示例来源:origin: org.drools/drools-core
pkg.addRule( rule );
kbase.addPackages( Collections.singleton(pkg) );
ksession.addEventListener( agendaEventListener );
assertEquals( 1, ksession.getAgendaEventListeners().size() );
MatchCreatedEvent createdEvent = (MatchCreatedEvent) agendaList.get( 0 );
assertSame( cheddarHandle,
createdEvent.getMatch().getFactHandles().toArray()[0] );
createdEvent = (MatchCreatedEvent) agendaList.get( 0 );
assertSame( cheddarHandle,
createdEvent.getMatch().getFactHandles().toArray()[0] );
agendaList.clear();
assertNotNull( ((InternalFactHandle) cancelledEvent.getMatch().getFactHandles().toArray()[0]).getObject() );
final BeforeMatchFiredEvent beforeEvent = (BeforeMatchFiredEvent) agendaList.get( 0 );
assertSame( cheddarHandle,
beforeEvent.getMatch().getFactHandles().toArray()[0] );
final AfterMatchFiredEvent afterEvent = (AfterMatchFiredEvent) agendaList.get( 1 );
assertSame( cheddarHandle,
afterEvent.getMatch().getFactHandles().toArray()[0] );
final AgendaGroupPoppedEvent poppedEvent = (AgendaGroupPoppedEvent) agendaList.get( 2 );
assertEquals( "test group",
代码示例来源:origin: org.kie/kie-api
@Override
public String getMessage() {
StringBuilder sb = new StringBuilder( "Exception executing consequence for " );
Rule rule = null;
if( match != null && ( rule = match.getRule() ) != null ){
String packageName = rule.getPackageName();
String ruleName = rule.getName();
sb.append( "rule \"" ).append( ruleName ).append( "\" in " ).append( packageName );
} else {
sb.append( "rule, name unknown" );
}
sb.append( ": " ).append( super.getMessage() );
return sb.toString();
}
代码示例来源:origin: deepu105/drools-demo
@Override
public void afterMatchFired(AfterMatchFiredEvent event) {
Rule rule = event.getMatch().getRule();
String ruleName = rule.getName();
Map<String, Object> ruleMetaDataMap = rule.getMetaData();
activationList.add(new Activation(ruleName));
StringBuilder sb = new StringBuilder("Rule fired: " + ruleName);
if (ruleMetaDataMap.size() > 0) {
sb.append("\n With [" + ruleMetaDataMap.size() + "] meta-data:");
for (String key : ruleMetaDataMap.keySet()) {
sb.append("\n key=" + key + ", value="
+ ruleMetaDataMap.get(key));
}
}
log.debug(sb.toString());
}
代码示例来源:origin: icclab/cyclops
@Override
public void afterMatchFired(AfterMatchFiredEvent event) {
logger.log(LogConstants.RULE, String.format("Rule match fired for: \"%s\", on following objects: %s", event.getMatch().getRule().getName(), new Gson().toJson(event.getMatch().getObjects())));
super.afterMatchFired(event);
}
}
代码示例来源:origin: kiegroup/jbpm
public boolean accept(Match activation) {
RuleImpl rule = (RuleImpl)activation.getRule();
if (currentSalience == null){
currentSalience = rule.getSalience() != null ? Integer.valueOf(rule.getSalience().toString()) : 0;
}
boolean nocancel = currentSalience >= Integer.valueOf(rule.getSalience().toString());
if(!nocancel){
logger.info("cancelling -> {}", rule.getName());
}
return nocancel;
}
}
代码示例来源:origin: org.drools/drools-compiler
@Override
public void onUpdateMatch( Match match ) {
list.add("onUpdateMatch: " + match.getDeclarationValue( "$age" ));
}
} );
代码示例来源:origin: org.drools/knowledge-api
public List<Object> getObjects() {
return delegate.getObjects();
}
内容来源于网络,如有侵权,请联系作者删除!