@Test public void testStringData4() { final int count = 100000; final ObjectHashMap map = new ObjectHashMap(); assertNotNull( map ); for ( int idx = 0; idx < count; idx++ ) { final String key = "key" + idx; final String strval = "value" + idx; map.put( key, strval ); } final long start = System.currentTimeMillis(); final org.drools.core.util.Iterator itr = map.iterator(); Object val = null; while ( (val = itr.next()) != null ) { val.hashCode(); } final long end = System.currentTimeMillis(); System.out.println( "Custom ObjectHashMap iterate ET - " + ((end - start)) ); }
public int size() { return this.assertMap.size(); }
@Test public void testIntegerData() { final ObjectHashMap map = new ObjectHashMap(); assertNotNull( map ); final int count = 1000; for ( int idx = 0; idx < count; idx++ ) { final Integer key = new Integer( idx ); final Integer val = new Integer( idx ); map.put( key, val ); assertEquals( val, map.get( key ) ); } }
@Test public void testStringData2() { final int count = 100000; final ObjectHashMap map = new ObjectHashMap(); assertNotNull( map ); final long start = System.currentTimeMillis(); for ( int idx = 0; idx < count; idx++ ) { final String key = "key" + idx; final String strval = "value" + idx; map.put( key, strval ); } final long end = System.currentTimeMillis(); System.out.println( "Custom ObjectHashMap put(key,value) ET - " + ((end - start)) ); }
assertEquals( 2, equalityMap.size() ); // go1, neg are two different strings. org.drools.core.util.Iterator it = equalityMap.iterator(); EqualityKey key = ( EqualityKey ) (( ObjectEntry ) it.next() ).getValue(); while ( !key.getFactHandle().getObject().equals( "neg") ) { assertEquals( 0, getNegativeObjects(kSession).size() ); assertEquals( 0, key.getBeliefSet().size() ); assertEquals( 1, ep.getTruthMaintenanceSystem().getEqualityKeyMap().size() );
@Test(timeout = 10000 ) public void testDefeatOutcomePosNeg() { KieSession kSession = getSession( "org/drools/compiler/beliefsystem/defeasible/negDefeatPos.drl" ); ArrayList list = new ArrayList(); kSession.setGlobal( "list", list ); kSession.fireAllRules(); TruthMaintenanceSystem tms = ((NamedEntryPoint) kSession.getEntryPoint( "DEFAULT" )).getTruthMaintenanceSystem(); FactType Xtype = kSession.getKieBase().getFactType( "org.drools.defeasible", "X" ); ObjectHashMap keys = tms.getEqualityKeyMap(); Iterator iter = keys.iterator(); ObjectHashMap.ObjectEntry entry; while ( ( entry = ( ObjectHashMap.ObjectEntry) iter.next() ) != null ) { EqualityKey key = (EqualityKey) entry.getValue(); Class factClass = key.getFactHandle().getObject().getClass(); if ( factClass == Xtype.getFactClass() ) { checkStatus( key, 1, DefeasibilityStatus.DEFEASIBLY ); } else { fail( "Unrecognized object has been logically justified : " + factClass ); } } assertEquals( 2, kSession.getObjects().size() ); assertEquals( 1, getNegativeObjects(kSession).size() ); assertEquals( 1, list.size() ); assertTrue( list.contains( "-1" ) ); }
ObjectHashMap justifiedMap = context.wm.getTruthMaintenanceSystem().getJustifiedMap(); if (!assertMap.isEmpty() || !justifiedMap.isEmpty()) { EqualityKey[] keys = new EqualityKey[assertMap.size()]; org.drools.core.util.Iterator it = assertMap.iterator(); int i = 0; for (org.drools.core.util.ObjectHashMap.ObjectEntry entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next()) { it = justifiedMap.iterator(); i = 0; for (org.drools.core.util.ObjectHashMap.ObjectEntry entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next()) {
@Test public void testEmptyIterator() { final ObjectHashMap map = new ObjectHashMap(); final Iterator it = map.iterator(); for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) { fail( "Map is empty, there should be no iteration" ); } }
public InternalFactHandle getHandleForObject(Object object){ if ( object == null ) { return null; } else { return (InternalFactHandle) this.assertMap.get( object ); } }
private static ProtobufMessages.NodeMemory writeRIANodeMemory(final int nodeId, final Memory memory) { // for RIA nodes, we need to store the ID of the created handles RIAMemory mem = (RIAMemory) memory; if (!mem.memory.isEmpty()) { ProtobufMessages.NodeMemory.RIANodeMemory.Builder _ria = ProtobufMessages.NodeMemory.RIANodeMemory.newBuilder(); final org.drools.core.util.Iterator it = mem.memory.iterator(); // iterates over all propagated handles and assert them to the new sink for (ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next()) { LeftTuple leftTuple = (LeftTuple) entry.getKey(); InternalFactHandle handle = (InternalFactHandle) entry.getValue(); FactHandle _handle = ProtobufMessages.FactHandle.newBuilder() .setId(handle.getId()) .setRecency(handle.getRecency()) .build(); _ria.addContext(ProtobufMessages.NodeMemory.RIANodeMemory.RIAContext.newBuilder() .setTuple(PersisterHelper.createTuple(leftTuple)) .setResultHandle(_handle) .build()); } return ProtobufMessages.NodeMemory.newBuilder() .setNodeId(nodeId) .setNodeType(ProtobufMessages.NodeMemory.NodeType.RIA) .setRia(_ria.build()) .build(); } return null; }
public Object put(final Object key, final Object value) { return put( key, value, true ); }
WindowTupleList list = (WindowTupleList) memory.events.get(factHandle); if (isAllowed) { if (list != null) { list = new WindowTupleList((EventFactHandle) factHandle, this); context.setActiveWindowTupleList(list); memory.events.put(factHandle, list); this.sink.propagateAssertObject(factHandle, memory.events.remove(factHandle);
public SingleThreadedObjectStore(RuleBaseConfiguration conf, Lock lock) { this.behaviour = conf.getAssertBehaviour(); this.lock = lock; this.assertMap = new ObjectHashMap(); if ( AssertBehaviour.IDENTITY.equals(this.behaviour) ) { this.assertMap.setComparator( new IdentityAssertMapComparator() ); this.identityMap = assertMap; } else { this.assertMap.setComparator( new EqualityAssertMapComparator() ); this.identityMap = new ObjectHashMap(); this.identityMap.setComparator( new IdentityAssertMapComparator() ); } }
final Iterator iter = this.hashedSinkMap.newIterator(); ObjectHashMap.ObjectEntry entry = (ObjectHashMap.ObjectEntry) iter.next(); this.hashedSinkMap.remove( hashKey ); if ( this.hashedSinkMap.isEmpty() ) { this.hashedSinkMap = null;
public void addLogicalDependency(final InternalFactHandle handle, final Object value, final Activation activation, final PropagationContext context, final Rule rule, final ObjectTypeConf typeConf, final boolean read) throws FactException { final LogicalDependency node = beliefSystem.newLogicalDependency( activation, handle, value ); activation.getRule().setHasLogicalDependency( true ); activation.addLogicalDependency( node ); BeliefSet beliefSet = (BeliefSet) this.justifiedMap.get( handle.getId() ); if ( beliefSet == null ) { if ( context.getType() == PropagationContext.MODIFICATION ) { // if this was a update, chances are its trying to retract a logical assertion } beliefSet = beliefSystem.newBeliefSet(); this.justifiedMap.put( handle.getId(), beliefSet ); } if ( read ) { // used when deserialising beliefSystem.read( node, beliefSet, context, typeConf ); } else { beliefSystem.insert( node, beliefSet, context, typeConf ); } }
assertTrue(tms.getEqualityKeyMap().isEmpty()); } finally { ksession.dispose();
assertEquals( 1, equalityMap.size() ); // Only Person type is logical org.drools.core.util.Iterator it = equalityMap.iterator(); EqualityKey key = ( EqualityKey ) (( ObjectEntry ) it.next() ).getValue(); while ( !key.getFactHandle().getObject().equals( new Person( "darth") ) ) { it = equalityMap.iterator(); key = ( EqualityKey ) (( ObjectEntry ) it.next() ).getValue(); while ( !key.getFactHandle().getObject().equals( new Person( "darth") ) ) { it = equalityMap.iterator(); key = ( EqualityKey ) (( ObjectEntry ) it.next() ).getValue(); while ( !key.getFactHandle().getObject().equals( new Person( "darth") ) ) {
@Test(timeout = 10000 ) public void testDefeaterNeutrality() { KieSession kSession = getSession( "org/drools/compiler/beliefsystem/defeasible/defeaterOnly.drl" ); ArrayList list = new ArrayList(); kSession.setGlobal( "list", list ); kSession.fireAllRules(); TruthMaintenanceSystem tms = ((NamedEntryPoint) kSession.getEntryPoint( "DEFAULT" )).getTruthMaintenanceSystem(); FactType Xtype = kSession.getKieBase().getFactType( "org.drools.defeasible", "X" ); ObjectHashMap keys = tms.getEqualityKeyMap(); Iterator iter = keys.iterator(); ObjectHashMap.ObjectEntry entry; while ( ( entry = ( ObjectHashMap.ObjectEntry) iter.next() ) != null ) { EqualityKey key = (EqualityKey) entry.getValue(); Class factClass = key.getFactHandle().getObject().getClass(); if ( factClass == Xtype.getFactClass() ) { checkStatus( key, 1, DefeasibilityStatus.DEFEATEDLY ); } else { fail( "Unrecognized object has been logically justified : " + factClass ); } } for ( Object o : kSession.getObjects() ) { System.out.println( o ); } assertEquals( 0, list.size() ); assertEquals( 1, kSession.getFactCount() ); }