[jboss-jira] [JBoss JIRA] (DROOLS-2837) Avoid switching by putting the leftInputAdapterNode in an Hashmap

Luca Molteni (JIRA) issues at jboss.org
Mon Aug 6 11:18:00 EDT 2018


Luca Molteni created DROOLS-2837:
------------------------------------

             Summary: Avoid switching by putting the leftInputAdapterNode in an Hashmap
                 Key: DROOLS-2837
                 URL: https://issues.jboss.org/browse/DROOLS-2837
             Project: Drools
          Issue Type: Enhancement
            Reporter: Luca Molteni
            Assignee: Luca Molteni


In this test:

testAlphaConstraintsSwitchBigDecimal

Let's go from this


private java.util.Map ToNodeId = new java.util.HashMap();

        ToNodeId.put(new java.math.BigDecimal("0"), 4);
        ToNodeId.put(new java.math.BigDecimal("2"), 10);
        ToNodeId.put(new java.math.BigDecimal("1"), 7);

public final void assertObject(org.drools.core.common.InternalFactHandle handle,org.drools.core.spi.PropagationContext context,org.drools.core.common.InternalWorkingMemory wm){
        org.drools.modelcompiler.domain.Person fact = (org.drools.modelcompiler.domain.Person)handle.getObject();
        Integer NodeId = (Integer)ToNodeId.get(readAccessor.getValue(fact));
        if(NodeId != null) {
        switch(NodeId.intValue()) {
        case 4 :
        leftInputAdapterNode5.assertObject(handle,context,wm);
        break;
        case 7 :
        leftInputAdapterNode8.assertObject(handle,context,wm);
        break;
        case 10 :
        leftInputAdapterNode11.assertObject(handle,context,wm);
        break;
        }
        }
        }


to This

private java.util.Map ToNodeId=new java.util.HashMap();
        ToNodeId.put(new java.math.BigDecimal("0"),leftInputAdapterNode5);
        ToNodeId.put(new java.math.BigDecimal("2"),leftInputAdapterNode11);
        ToNodeId.put(new java.math.BigDecimal("1"),leftInputAdapterNode8);

public final void assertObject(org.drools.core.common.InternalFactHandle handle,org.drools.core.spi.PropagationContext context,org.drools.core.common.InternalWorkingMemory wm){
        org.drools.modelcompiler.domain.Person fact=(org.drools.modelcompiler.domain.Person)handle.getObject();
        org.drools.core.reteoo.LeftInputAdapterNode lia=(Integer)ToNodeId.get(readAccessor.getValue(fact));
        if(lia!=null){
        lia.assertOject(handle,context,wm);
        }

Therefore avoiding the switch



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the jboss-jira mailing list