LogicTransformer { public GroupElement[] transform( final GroupElement cloned, Map<String, Class<?>> globals ) throws InvalidPatternException { boolean hasNamedConsequenceAndIsStream = processTree( cloned ); cloned.pack(); GroupElement[] ands; if ( cloned.isAnd() ) { ands = new GroupElement[]{cloned}; } else if ( cloned.isOr() ) { ands = splitOr( cloned ); } else { final GroupElement wrapper = GroupElementFactory.newAndInstance(); wrapper.addChild( cloned ); ands = new GroupElement[]{wrapper}; } for ( GroupElement and : ands ) { this.fixClonedDeclarations( and, globals ); and.setRoot( true ); } return hasNamedConsequenceAndIsStream ? processNamedConsequences(ands) : ands; } protected  LogicTransformer(); static LogicTransformer getInstance(); GroupElement[] transform( final GroupElement cloned, Map<String, Class<?>> globals ); static int[] toIntArray(List<Integer> list);  }
@Test public void testTransform() throws IOException, ClassNotFoundException, InvalidPatternException { final ObjectType type = new ClassObjectType( String.class ); final Pattern a = new Pattern( 0, type, "a" ); final Pattern b = new Pattern( 1, type, "b" ); final Pattern c = new Pattern( 2, type, "c" ); final Pattern d = new Pattern( 3, type, "d" ); final Pattern e = new Pattern( 4, type, "e" ); final Pattern f = new Pattern( 5, type, "f" ); final Pattern g = new Pattern( 6, type, "g" ); final Pattern h = new Pattern( 7, type, "h" ); final GroupElement and = GroupElementFactory.newAndInstance(); final GroupElement and1 = GroupElementFactory.newAndInstance(); and1.addChild( a ); final GroupElement or1 = GroupElementFactory.newOrInstance(); or1.addChild( b ); or1.addChild( c ); and1.addChild( or1 ); and.addChild( and1 ); final GroupElement or2 = GroupElementFactory.newOrInstance(); or2.addChild( d ); or2.addChild( e ); and.addChild( or2 ); final GroupElement and2 = GroupElementFactory.newAndInstance(); final GroupElement not1 = GroupElementFactory.newNotInstance(); not1.addChild( f ); final GroupElement or3 = GroupElementFactory.newOrInstance(); or3.addChild( g ); final GroupElement not2 = GroupElementFactory.newNotInstance(); not2.addChild( h ); or3.addChild( not2 ); and2.addChild( not1 ); and2.addChild( or3 ); and.addChild( and2 ); final GroupElement[] ands = LogicTransformer.getInstance().transform( and, Collections.EMPTY_MAP ); final File testFile = new File("target/test/LogicTransformerTest_correct_transform1.dat"); testFile.getParentFile().mkdirs(); DroolsStreamUtils.streamOut(new FileOutputStream(testFile), ands); final GroupElement[] correctResultAnds = (GroupElement[]) DroolsStreamUtils.streamIn( new FileInputStream(testFile)); for ( int j = 0; j < ands.length; j++ ) { assertEquals( correctResultAnds[j], ands[j] ); } }