From: <jbo...@li...> - 2006-04-19 20:52:50
|
Author: mar...@jb... Date: 2006-04-19 16:52:43 -0400 (Wed, 19 Apr 2006) New Revision: 3806 Removed: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/InstrumentedRule.java Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/GroupElement.java labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/LogicTransformer.java Log: -GroupElement now removes redundant conditional elements, this is part of the rework work that will take place in 3.1 Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/GroupElement.java =================================================================== --- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/GroupElement.java 2006-04-19 20:36:39 UTC (rev 3805) +++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/GroupElement.java 2006-04-19 20:52:43 UTC (rev 3806) @@ -35,6 +35,24 @@ * @param child */ public void addChild(Object child) { + // @todo : I've commented this out for 3.0, but we want this working for 3.1 +// if ( child instanceof Not ) { +// Not not = ( Not ) child; +// Object notChild = not.getChild(); +// if ( notChild instanceof Or ) { +// Or or = (Or) notChild; +// And and = new And(); +// for ( Iterator it = or.getChildren().iterator(); it.hasNext(); ) { +// Not newNot = new Not(); +// newNot.addChild( it.next() ); +// and.addChild( newNot ); +// } +// child = and; +// } else if ( notChild instanceof And ) { +// +// } +// } + if ( child instanceof GroupElement && ( child instanceof And || child instanceof Or ) ) { GroupElement group = ( GroupElement ) child; Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/LogicTransformer.java =================================================================== --- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/LogicTransformer.java 2006-04-19 20:36:39 UTC (rev 3805) +++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/LogicTransformer.java 2006-04-19 20:52:43 UTC (rev 3806) @@ -1,4 +1,5 @@ package org.drools.rule; + /* * Copyright 2005 JBoss Inc * @@ -15,8 +16,6 @@ * limitations under the License. */ - - import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -224,12 +223,16 @@ parent.getChildren().addAll( newChildren ); } + void checkForAndRemoveSingleBranch(GroupElement parent) { + + } + GroupElement applyOrTransformation(GroupElement parent, GroupElement child) throws InvalidPatternException { - OrTransformation transformation = null; + Transformation transformation = null; Map map = (HashMap) this.orTransformations.get( parent.getClass() ); if ( map != null ) { - transformation = (OrTransformation) map.get( child.getClass() ); + transformation = (Transformation) map.get( child.getClass() ); } if ( transformation == null ) { @@ -239,7 +242,7 @@ return transformation.transform( parent ); } - interface OrTransformation { + interface Transformation { GroupElement transform(GroupElement element) throws InvalidPatternException; } @@ -272,7 +275,7 @@ */ class AndOrTransformation implements - OrTransformation { + Transformation { public GroupElement transform(GroupElement and) throws InvalidPatternException { Or or = new Or(); @@ -388,25 +391,26 @@ */ class ExistOrTransformation implements - OrTransformation { + Transformation { public GroupElement transform(GroupElement exist) throws InvalidPatternException { - if ( !(exist.getChildren().get( 0 ) instanceof Or) ) { - throw new RuntimeException( "ExistOrTransformation expected '" + Or.class.getName() + "' but instead found '" + exist.getChildren().get( 0 ).getClass().getName() + "'" ); - } - - /* - * we know a Not only ever has one child, and the previous algorithm - * has confirmed the child is an OR - */ - Or or = (Or) exist.getChildren().get( 0 ); - And and = new And(); - for ( Iterator it = or.getChildren().iterator(); it.hasNext(); ) { - Exists newExist = new Exists(); - newExist.addChild( it.next() ); - and.addChild( newExist ); - } - return and; + throw new InvalidPatternException( "You cannot nest an OR within an Exists" ); +// if ( !(exist.getChildren().get( 0 ) instanceof Or) ) { +// throw new RuntimeException( "ExistOrTransformation expected '" + Or.class.getName() + "' but instead found '" + exist.getChildren().get( 0 ).getClass().getName() + "'" ); +// } +// +// /* +// * we know a Not only ever has one child, and the previous algorithm +// * has confirmed the child is an OR +// */ +// Or or = (Or) exist.getChildren().get( 0 ); +// And and = new And(); +// for ( Iterator it = or.getChildren().iterator(); it.hasNext(); ) { +// Exists newExist = new Exists(); +// newExist.addChild( it.next() ); +// and.addChild( newExist ); +// } +// return and; } } @@ -433,26 +437,62 @@ */ public class NotOrTransformation implements - OrTransformation { + Transformation { public GroupElement transform(GroupElement not) throws InvalidPatternException { - if ( !(not.getChildren().get( 0 ) instanceof Or) ) { - throw new RuntimeException( "NotOrTransformation expected '" + Or.class.getName() + "' but instead found '" + not.getChildren().get( 0 ).getClass().getName() + "'" ); - } - /* - * we know a Not only ever has one child, and the previous algorithm - * has confirmed the child is an OR - */ - Or or = (Or) not.getChildren().get( 0 ); - And and = new And(); - for ( Iterator it = or.getChildren().iterator(); it.hasNext(); ) { - Not newNot = new Not(); - newNot.addChild( it.next() ); - and.addChild( newNot ); - } - return and; + throw new InvalidPatternException( "You cannot nest an OR within an Not" ); + // @todo for 3.1 +// if ( !(not.getChildren().get( 0 ) instanceof Or) ) { +// throw new RuntimeException( "NotOrTransformation expected '" + Or.class.getName() + "' but instead found '" + not.getChildren().get( 0 ).getClass().getName() + "'" ); +// } +// +// /* +// * we know a Not only ever has one child, and the previous algorithm +// * has confirmed the child is an OR +// */ +// Or or = (Or) not.getChildren().get( 0 ); +// And and = new And(); +// for ( Iterator it = or.getChildren().iterator(); it.hasNext(); ) { +// Not newNot = new Not(); +// newNot.addChild( it.next() ); +// and.addChild( newNot ); +// } +// return and; } } + //@todo for 3.1 +// public class NotAndTransformation +// implements +// Transformation { +// +// public GroupElement transform(GroupElement not) throws InvalidPatternException { +// if ( !(not.getChildren().get( 0 ) instanceof And) ) { +// throw new RuntimeException( "NotAndTransformation expected '" + And.class.getName() + "' but instead found '" + not.getChildren().get( 0 ).getClass().getName() + "'" ); +// } +// +// /* +// * we know a Not only ever has one child, and the previous algorithm +// * has confirmed the child is an And +// */ +// And and = (And) not.getChildren().get( 0 ); +// for ( Iterator it = and.getChildren().iterator(); it.hasNext(); ) { +// Object object1 = it.next(); +// +// for ( Iterator it2 = and.getChildren().iterator(); it.hasNext(); ) { +// Object object2 = it.next(); +// if ( object2 != object1 ) { +// +// } +// } +// +// Not newNot = new Not(); +// newNot.addChild( it.next() ); +// and.addChild( newNot ); +// } +// +// return and; +// } +// } } \ No newline at end of file Deleted: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/InstrumentedRule.java =================================================================== --- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/InstrumentedRule.java 2006-04-19 20:36:39 UTC (rev 3805) +++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/InstrumentedRule.java 2006-04-19 20:52:43 UTC (rev 3806) @@ -1,45 +0,0 @@ -package org.drools.rule; -/* - * Copyright 2005 JBoss Inc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - - - - -public class InstrumentedRule extends Rule { - public Boolean isValid; - - public InstrumentedRule(String name) { - super( name ); - } - - public void isValid(boolean isValid) { - if ( isValid ) { - this.isValid = Boolean.TRUE; - } else { - this.isValid = Boolean.FALSE; - } - } - - public boolean isValid() { - if ( this.isValid == null ) { - return super.isValid(); - } - - return this.isValid.booleanValue(); - } - -} \ No newline at end of file |