Package org.drools.util

Examples of org.drools.util.HierarchyEncoder


                konst = cacheConstructor( key, core, trait );
            }
        }

        T proxy = null;
        HierarchyEncoder hier = ruleBase.getConfiguration().getComponentFactory().getTraitRegistry().getHierarchy();
        try {
            switch ( mode ) {
                case MAP    :   proxy = konst.newInstance( core, core._getDynamicProperties(), hier.getCode( trait.getName() ), hier.getBottom(), logical );
                    break;
                case TRIPLES:   proxy = konst.newInstance( core, ruleBase.getTripleStore(), getTripleFactory(), hier.getCode( trait.getName() ), hier.getBottom(), logical );
                    break;
                default     :   throw new RuntimeException( " This should not happen : unexpected property wrapping method " + mode );
            }

            return proxy;
View Full Code Here


                core._setTraitMap( null );
                return thing;
            } else if ( core.hasTrait( trait.getName() ) ) {
                removedTypes = core.removeTrait( trait.getName() );
            } else {
                HierarchyEncoder hier = ((ReteooRuleBase) this.workingMemory.getRuleBase()).getConfiguration().getComponentFactory().getTraitRegistry().getHierarchy();
                BitSet code = hier.getCode( trait.getName() );
                removedTypes = core.removeTrait( code );
            }

            removedTypes = new ArrayList<Thing<K>>( removedTypes );
            for ( Thing t : removedTypes ) {
View Full Code Here

                konst = cacheConstructor( key, core, trait );
            }
        }

        T proxy = null;
        HierarchyEncoder hier = ruleBase.getConfiguration().getComponentFactory().getTraitRegistry().getHierarchy();
        try {
            switch ( mode ) {
                case MAP    :   proxy = konst.newInstance( core, core._getDynamicProperties(), hier.getCode( trait.getName() ), hier.getBottom(), logical );
                    break;
                case TRIPLES:   proxy = konst.newInstance( core, ruleBase.getTripleStore(), getTripleFactory(), hier.getCode( trait.getName() ), hier.getBottom(), logical );
                    break;
                default     :   throw new RuntimeException( " This should not happen : unexpected property wrapping method " + mode );
            }

            return proxy;
View Full Code Here

                core._setTraitMap( null );
                return thing;
            } else if ( core.hasTrait( trait.getName() ) ) {
                removedTypes = core.removeTrait( trait.getName() );
            } else {
                HierarchyEncoder hier = ((ReteooRuleBase) this.workingMemory.getRuleBase()).getConfiguration().getComponentFactory().getTraitRegistry().getHierarchy();
                BitSet code = hier.getCode( trait.getName() );
                removedTypes = core.removeTrait( code );
            }

            removedTypes = new ArrayList<Thing<K>>( removedTypes );
            for ( Thing t : removedTypes ) {
View Full Code Here



    @Test
    public void testHierEncoderTrivial() {
        HierarchyEncoder encoder = new HierarchyEncoderImpl();

        encoder.encode( "A", Collections.EMPTY_LIST );
        encoder.encode( "B", Arrays.asList( "A" ) );
        encoder.encode( "C", Arrays.asList( "B" ) );
        encoder.encode( "D", Arrays.asList( "B", "C" ) );

        System.out.println( encoder );

        assertEqualsparseBitSet( "0" ), encoder.getCode( "A" ) );
        assertEqualsparseBitSet( "1" ), encoder.getCode( "B" ) );
        assertEqualsparseBitSet( "11" ), encoder.getCode( "C" ) );
        assertEqualsparseBitSet( "111" ), encoder.getCode( "D" ) );
    }
View Full Code Here

        assertEqualsparseBitSet( "111" ), encoder.getCode( "D" ) );
    }

    @Test
    public void testHierManyRoots() {
        HierarchyEncoder encoder = new HierarchyEncoderImpl();

        encoder.encode( "A", Collections.EMPTY_LIST );
        encoder.encode( "B", Collections.EMPTY_LIST );
        encoder.encode( "C", Collections.EMPTY_LIST );
        encoder.encode( "D", Collections.EMPTY_LIST );
        encoder.encode( "E", Collections.EMPTY_LIST );

        System.out.println( encoder );

        assertEqualsparseBitSet( "1" ), encoder.getCode( "A" ) );
        assertEqualsparseBitSet( "10" ), encoder.getCode( "B" ) );
        assertEqualsparseBitSet( "100" ), encoder.getCode( "C" ) );
        assertEqualsparseBitSet( "1000" ), encoder.getCode( "D" ) );
        assertEqualsparseBitSet( "10000" ), encoder.getCode( "E" ) );

        assertEquals( 5, encoder.size() );
        assertEquals( 5, encoder.getSortedMembers().size() );
        assertEquals( 5, encoder.getSortedMap().size() );

    }
View Full Code Here

    }


    @Test
    public void testHierALotOfClasses() {
        HierarchyEncoder encoder = new HierarchyEncoderImpl();
        int N = 1194;

        encoder.encode( "A", Collections.EMPTY_LIST );
        for ( int j = 1; j < N; j++ ) {
            encoder.encode( "X" + j, Arrays.asList( "A" ) );
        }

        assertEquals( N, encoder.size() );
        BitSet code = encoder.getCode( "X" + ( N -1 ) );
        assertEquals( 1, code.cardinality() );
        assertTrue( code.get( N - 2 ) );
    }
View Full Code Here



    @Test
    public void testHierEncoderSimpleInheritance() {
        HierarchyEncoder encoder = new HierarchyEncoderImpl();

        encoder.encode( "A", Collections.EMPTY_LIST );
        encoder.encode( "B", Arrays.asList( "A" ) );
        encoder.encode( "C", Arrays.asList( "A" ) );
        encoder.encode( "D", Arrays.asList( "B" ) );
        encoder.encode( "E", Arrays.asList( "B" ) );
        encoder.encode( "F", Arrays.asList( "C" ) );
        encoder.encode( "G", Arrays.asList( "C" ) );

        System.out.println( encoder );

        assertEquals( parseBitSet("0"), encoder.getCode("A"));
        assertEqualsparseBitSet( "1" ), encoder.getCode( "B" ) );
        assertEqualsparseBitSet( "10" ), encoder.getCode( "C" ) );
        assertEqualsparseBitSet( "101" ), encoder.getCode( "D" ) );
        assertEqualsparseBitSet( "1001" ), encoder.getCode( "E" ) );
        assertEqualsparseBitSet( "110" ), encoder.getCode( "F" ) );
        assertEqualsparseBitSet( "1010" ), encoder.getCode( "G" ) );
    }
View Full Code Here



    @Test
    public void testHierEncoderAnotherSimpleInheritance() {
        HierarchyEncoder encoder = new HierarchyEncoderImpl();

        encoder.encode( "R", Collections.EMPTY_LIST );
        encoder.encode( "A1", Arrays.asList( "R" ) );
        encoder.encode( "A2", Arrays.asList( "R" ) );
        encoder.encode( "A3", Arrays.asList( "R" ) );
        encoder.encode( "B1", Arrays.asList( "R" ) );
        encoder.encode( "B2", Arrays.asList( "R" ) );
        encoder.encode( "B3", Arrays.asList( "R" ) );
        encoder.encode( "B4", Arrays.asList( "B1", "B2" ) );
        encoder.encode( "B5", Arrays.asList( "B1", "B3" ) );
        encoder.encode( "B6", Arrays.asList( "B2", "B3" ) );
        encoder.encode( "B7", Arrays.asList( "B4", "B5", "B6" ) );

        System.out.println( encoder );

        assertEquals( parseBitSet( "0"), encoder.getCode("R"));
        assertEqualsparseBitSet( "1" ), encoder.getCode( "A1" ) );
        assertEqualsparseBitSet( "10" ), encoder.getCode( "A2" ) );
        assertEqualsparseBitSet( "100" ), encoder.getCode( "A3" ) );
        assertEqualsparseBitSet( "1000" ), encoder.getCode( "B1" ) );
        assertEqualsparseBitSet( "10000" ), encoder.getCode( "B2" ) );
        assertEqualsparseBitSet( "100000" ), encoder.getCode( "B3" ) );
        assertEqualsparseBitSet( "11000" ), encoder.getCode( "B4" ) );
        assertEqualsparseBitSet( "101000" ), encoder.getCode( "B5" ) );
        assertEqualsparseBitSet( "110000" ), encoder.getCode( "B6" ) );
        assertEqualsparseBitSet( "111000" ), encoder.getCode( "B7" ) );
    }
View Full Code Here



    @Test
    public void testHierEncoderAnotherSimpleInheritanceChangeOrder() {
        HierarchyEncoder encoder = new HierarchyEncoderImpl();

        encoder.encode( "R", Collections.EMPTY_LIST );

        encoder.encode( "B1", Arrays.asList( "R" ) );
        encoder.encode( "B2", Arrays.asList( "R" ) );
        encoder.encode( "B3", Arrays.asList( "R" ) );
        encoder.encode( "B4", Arrays.asList( "B1", "B2" ) );
        encoder.encode( "B5", Arrays.asList( "B1", "B3" ) );
        encoder.encode( "B6", Arrays.asList( "B2", "B3" ) );
        encoder.encode( "B7", Arrays.asList( "B4", "B5", "B6" ) );

        encoder.encode( "A1", Arrays.asList( "R" ) );
        encoder.encode( "A2", Arrays.asList( "R" ) );
        encoder.encode( "A3", Arrays.asList( "R" ) );

        System.out.println( encoder );

        assertEquals( parseBitSet( "0"), encoder.getCode("R"));
        assertEqualsparseBitSet( "1" ), encoder.getCode( "B1" ) );
        assertEqualsparseBitSet( "10" ), encoder.getCode( "B2" ) );
        assertEqualsparseBitSet( "100" ), encoder.getCode( "B3" ) );

        assertEqualsparseBitSet( "11" ), encoder.getCode( "B4" ) );
        assertEqualsparseBitSet( "101" ), encoder.getCode( "B5" ) );
        assertEqualsparseBitSet( "110" ), encoder.getCode( "B6" ) );
        assertEqualsparseBitSet( "111" ), encoder.getCode( "B7" ) );
        assertEqualsparseBitSet( "1000" ), encoder.getCode( "A1" ) );
        assertEqualsparseBitSet( "10000" ), encoder.getCode( "A2" ) );
        assertEqualsparseBitSet( "100000" ), encoder.getCode( "A3" ) );
    }
View Full Code Here

TOP

Related Classes of org.drools.util.HierarchyEncoder

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.