Package org.drools.util

Examples of org.drools.util.ObjectHashMap


     *            The working memory session.
     */
    public void assertObject(final InternalFactHandle handle,
                             final PropagationContext context,
                             final InternalWorkingMemory workingMemory) {
        final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );

        Object object = handle.getObject();

        ObjectTypeConf ojectTypeConf;
        if ( object instanceof Fact ) {
            String key = ((Fact) object).getFactTemplate().getName();
            ojectTypeConf = (ObjectTypeConf) memory.get( key );
            if ( ojectTypeConf == null ) {
                ojectTypeConf = new FactTemplateTypeConf( ((Fact) object).getFactTemplate(),
                                                          this.ruleBase );
                memory.put( key,
                            ojectTypeConf,
                            false );
            }
            object = key;
        } else {
            Class cls = null;
            if ( object instanceof ShadowProxy ) {
                cls = ((ShadowProxy) object).getShadowedObject().getClass();
            } else {
                cls = object.getClass();
            }

            ojectTypeConf = (ObjectTypeConf) memory.get( cls );
            if ( ojectTypeConf == null ) {
                ojectTypeConf = new ClassObjectTypeConf( cls,
                                                         this.ruleBase );
                memory.put( cls,
                            ojectTypeConf,
                            false );
            }

            // checks if shadow is enabled
View Full Code Here


     *            The working memory session.
     */
    public void retractObject(final InternalFactHandle handle,
                              final PropagationContext context,
                              final InternalWorkingMemory workingMemory) {
        final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );

        final Object object = handle.getObject();

        ObjectTypeConf objectTypeConf;
        if ( object instanceof ShadowProxy ) {
            objectTypeConf = (ObjectTypeConf) memory.get( ((ShadowProxy) object).getShadowedObject().getClass() );
        } else {
            objectTypeConf = (ObjectTypeConf) memory.get( object.getClass() );
        }

        ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();

        if ( cachedNodes == null ) {
View Full Code Here

    public ObjectHashMap getObjectTypeNodes() {
        return this.objectTypeNodes;
    }

    public Object createMemory(final RuleBaseConfiguration config) {
        return new ObjectHashMap();
    }
View Full Code Here

    public void updateSink(final ObjectSink sink,
                           final PropagationContext context,
                           final InternalWorkingMemory workingMemory) {
        // JBRULES-612: the cache MUST be invalidated when a new node type is added to the network, so iterate and reset all caches.
        final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );
        Iterator it = memory.iterator();
        final ObjectTypeNode node = (ObjectTypeNode) sink;

        ObjectType newObjectType = node.getObjectType();

        for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
View Full Code Here

        assertEquals( id,
                      objectTypeNode.getId() );

        final Field field = Rete.class.getDeclaredField( "objectTypeNodes" );
        field.setAccessible( true );
        final ObjectHashMap map = (ObjectHashMap) field.get( source );

        assertEquals( 0,
                      map.size() );

        objectTypeNode.attach();

        assertEquals( 1,
                      map.size() );

        assertSame( objectTypeNode,
                    map.get( objectType ) );
    }
View Full Code Here

                                                                  3 );
        stringTypeNode.attach();

        final Field field = Rete.class.getDeclaredField( "objectTypeNodes" );
        field.setAccessible( true );
        final ObjectHashMap map = (ObjectHashMap) field.get( rete );

        // Check the ObjectTypeNodes are correctly added to Rete
        assertEquals( 2,
                      map.size() );

        assertNotNull( map.get( new ClassObjectType( Object.class ) ) );
        assertNotNull( map.get( new ClassObjectType( String.class ) ) );
    }
View Full Code Here

                                                       PropagationContext.ASSERTION,
                                                       null,
                                                       null ),
                           workingMemory );

        final ObjectHashMap map = (ObjectHashMap) workingMemory.getNodeMemory( rete );
        ClassObjectTypeConf conf = (ClassObjectTypeConf) map.get( ArrayList.class );
        assertLength( 3,
                      conf.getObjectTypeNodes() );

        conf = (ClassObjectTypeConf) map.get( LinkedList.class );
        assertLength( 3,
                      conf.getObjectTypeNodes() );

    }
View Full Code Here

        // double check that the Listreference is the same as the one we created, i.e. engine should try and recreate it
        assertSame( listOtn,
                    rete.getObjectTypeNodes().get( new ClassObjectType( List.class ) ) );

        // ArrayConf should match two ObjectTypenodes for List and ArrayList
        ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( rete );
        ObjectTypeConf arrayConf = (ObjectTypeConf) memory.get( ArrayList.class );
        final ObjectTypeNode arrayOtn = arrayConf.getConcreteObjectTypeNode();
        assertEquals( 2,
                      arrayConf.getObjectTypeNodes().length );
       
        // Check it contains List and ArrayList
View Full Code Here

        final int index = fieldIndex.getIndex();

        final List list = new ArrayList();

        if ( this.hashedSinkMap == null ) {
            this.hashedSinkMap = new ObjectHashMap();
        }

        for ( ObjectSinkNode sink = this.hashableSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode() ) {
            final AlphaNode alphaNode = (AlphaNode) sink;
            final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
View Full Code Here

            this.tms = new TruthMaintenanceSystem( this );
        } else {
            this.tms = null;
        }

        this.assertMap = new ObjectHashMap();
        final RuleBaseConfiguration conf = this.ruleBase.getConfiguration();

        if ( conf.getAssertBehaviour() == AssertBehaviour.IDENTITY ) {
            this.assertMap.setComparator( new IdentityAssertMapComparator() );
            this.identityMap = assertMap;
        } else {
            this.assertMap.setComparator( new EqualityAssertMapComparator() );
            this.identityMap = new ObjectHashMap();
            this.identityMap.setComparator( new IdentityAssertMapComparator() );
        }

        // Only takes effect if are using idententity behaviour for assert       
        if ( conf.getLogicalOverride() == LogicalOverride.DISCARD ) {
View Full Code Here

TOP

Related Classes of org.drools.util.ObjectHashMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.