Author: bagerman
Date: 2006-06-02 23:16:27 -0400 (Fri, 02 Jun 2006)
New Revision: 4587
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsFactHandle.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsRuleHandle.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/LeapsFactHandleTest.java
Removed:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/FactHandleImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/Handle.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/RuleHandle.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/FactTable.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsAgenda.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsFactHandleFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsTuple.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsWorkingMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/Token.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/TokenEvaluator.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/conflict/LoadOrderConflictResolver.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/conflict/RuleComplexityConflictResolver.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/conflict/RuleLoadOrderConflictResolver.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/conflict/RuleSalienceConflictResolver.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/ColumnConstraintsTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/FactHandleImplTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/HandleFactoryTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/LeapsTupleTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/LogicalAssertionTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/SchedulerTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/util/TableIteratorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/util/TableTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/leaps/util/TokenStackTest.java
Log:
adjusting leaps to work with common truth maintenance in abstract working memory
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java 2006-06-03 03:08:51 UTC (rev 4586)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java 2006-06-03 03:16:27 UTC (rev 4587)
@@ -97,15 +97,18 @@
for ( LogicalDependency node = (LogicalDependency) list.getFirst(); node != null; node = (LogicalDependency) node.getNext() ) {
final InternalFactHandle handle = (InternalFactHandle) node.getFactHandle();
final Set set = (Set) this.justifiedMap.get( handle.getId() );
- set.remove( node );
- if ( set.isEmpty() ) {
- this.justifiedMap.remove( handle.getId() );
- // this needs to be scheduled so we don't upset the current working memory operation
- this.WorkingMemory.queueRetractAction( handle,
- false,
- true,
- context.getRuleOrigin(),
- context.getActivationOrigin() );
+ if (set != null) {
+ set.remove( node );
+ if (set.isEmpty( )) {
+ this.justifiedMap.remove( handle.getId( ) );
+ // this needs to be scheduled so we don't upset the current
+ // working memory operation
+ this.WorkingMemory.queueRetractAction( handle,
+ false,
+ true,
+ context.getRuleOrigin( ),
+ context.getActivationOrigin( ) );
+ }
}
}
}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/FactHandleImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/FactHandleImpl.java 2006-06-03 03:08:51 UTC (rev 4586)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/FactHandleImpl.java 2006-06-03 03:16:27 UTC (rev 4587)
@@ -1,140 +0,0 @@
-package org.drools.leaps;
-
-/*
- * 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.
- */
-
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.drools.FactHandle;
-import org.drools.common.EqualityKey;
-import org.drools.common.InternalFactHandle;
-
-/**
- * class container for each object asserted / retracted into the system
- *
- * @author Alexander Bagerman
- *
- */
-public class FactHandleImpl extends Handle
- implements
- InternalFactHandle {
- /**
- *
- */
- private static final long serialVersionUID = -6453652241440771664L;
-
- private List activatedTuples = null;
-
- private List notTuples = null;
-
- private List existsTuples = null;
-
- private EqualityKey key = null;
-
- /**
- * actual object that is asserted to the system no getters just a direct
- * access to speed things up
- */
- public FactHandleImpl(final long id,
- final Object object) {
- super( id,
- object );
- }
-
- protected void addActivatedTuple(final LeapsTuple tuple) {
- if ( this.activatedTuples == null ) {
- this.activatedTuples = new LinkedList();
- }
- this.activatedTuples.add( tuple );
- }
-
- protected void addNotTuple(final LeapsTuple tuple,
- final int index) {
- if ( this.notTuples == null ) {
- this.notTuples = new LinkedList();
- }
- this.notTuples.add( new FactHandleTupleAssembly( tuple,
- index ) );
- }
-
- protected void addExistsTuple(final LeapsTuple tuple,
- final int index) {
- if ( this.existsTuples == null ) {
- this.existsTuples = new LinkedList();
- }
- this.existsTuples.add( new FactHandleTupleAssembly( tuple,
- index ) );
- }
-
- protected Iterator getActivatedTuples() {
- if ( this.activatedTuples != null ) {
- return this.activatedTuples.iterator();
- }
- return null;
- }
-
- protected Iterator getNotTupleAssemblies() {
- if ( this.notTuples != null ) {
- return this.notTuples.iterator();
- }
- return null;
- }
-
- protected Iterator getExistsTupleAssemblies() {
- if ( this.existsTuples != null ) {
- return this.existsTuples.iterator();
- }
- return null;
- }
-
- /**
- * @see FactHandle
- */
- public String toExternalForm() {
- return "f-" + this.getId();
- }
-
- /**
- * @see Object
- */
- public String toString() {
- return toExternalForm();
- }
-
- public EqualityKey getEqualityKey() {
- return this.key;
- }
-
- public void setEqualityKey(final EqualityKey key) {
- this.key = key;
- }
-
- public void setObject(final Object object) {
- // TODO Auto-generated method stub
- }
-
- public void invalidate() {
- // TODO Auto-generated method stub
-
- }
-
- public void setRecency(final long recency) {
- // TODO Auto-generated method stub
-
- }
-}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/FactTable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/FactTable.java 2006-06-03 03:08:51 UTC (rev 4586)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/FactTable.java 2006-06-03 03:16:27 UTC (rev 4587)
@@ -19,6 +19,7 @@
import java.util.Iterator;
import java.util.LinkedList;
+import org.drools.common.DefaultFactHandle;
import org.drools.common.PropagationContextImpl;
import org.drools.leaps.util.Table;
import org.drools.spi.PropagationContext;
@@ -62,9 +63,9 @@
* @param ruleConflictResolver
*/
public FactTable(final ConflictResolver conflictResolver) {
- super( conflictResolver.getFactConflictResolver() );
- this.rules = new RuleTable( conflictResolver.getRuleConflictResolver() );
- this.tuples = new LinkedList();
+ super( conflictResolver.getFactConflictResolver( ) );
+ this.rules = new RuleTable( conflictResolver.getRuleConflictResolver( ) );
+ this.tuples = new LinkedList( );
}
/**
@@ -73,9 +74,9 @@
* @param workingMemory
* @param ruleHandle
*/
- public void addRule(final LeapsWorkingMemory workingMemory,
- final RuleHandle ruleHandle) {
- if ( !this.rules.contains( ruleHandle ) ) {
+ public void addRule( final LeapsWorkingMemory workingMemory,
+ final LeapsRuleHandle ruleHandle ) {
+ if (!this.rules.contains( ruleHandle )) {
this.rules.add( ruleHandle );
// push facts back to stack if needed
this.checkAndAddFactsToStack( workingMemory );
@@ -87,14 +88,15 @@
*
* @param ruleHandle
*/
- public void removeRule(final RuleHandle ruleHandle) {
+ public void removeRule( final LeapsWorkingMemory workingMemory,
+ final LeapsRuleHandle ruleHandle ) {
this.rules.remove( ruleHandle );
// remove tuples that are still there
- final LinkedList list = new LinkedList();
+ final LinkedList list = new LinkedList( );
- for ( final Iterator it = this.getTuplesIterator(); it.hasNext(); ) {
- final LeapsTuple tuple = (LeapsTuple) it.next();
- if ( ruleHandle.getLeapsRule().getRule() != tuple.getLeapsRule().getRule() ) {
+ for (final Iterator it = this.getTuplesIterator( ); it.hasNext( );) {
+ final LeapsTuple tuple = (LeapsTuple) it.next( );
+ if (ruleHandle.getLeapsRule( ).getRule( ) != tuple.getLeapsRule( ).getRule( )) {
list.add( tuple );
}
}
@@ -110,27 +112,24 @@
* memory
*
*/
- private void checkAndAddFactsToStack(final LeapsWorkingMemory workingMemory) {
- if ( this.reseededStack ) {
+ private void checkAndAddFactsToStack( final LeapsWorkingMemory workingMemory ) {
+ if (this.reseededStack) {
this.setReseededStack( false );
- final PropagationContextImpl context = new PropagationContextImpl( workingMemory.nextPropagationIdCounter(),
+ final PropagationContextImpl context = new PropagationContextImpl( workingMemory.nextPropagationIdCounter( ),
PropagationContext.ASSERTION,
null,
null );
// let's only add facts below waterline - added before rule is added
// rest would be added to stack automatically
- // @todo why is this null? It breaks FactHandle hashCode - chaning to new Object() for now
- final Handle startFactHandle = new FactHandleImpl( workingMemory.getIdLastFireAllAt(),
- new Object() );
- for ( final Iterator it = this.tailIterator( startFactHandle,
- startFactHandle ); it.hasNext(); ) {
- final FactHandleImpl handle = (FactHandleImpl) it.next();
- workingMemory.pushTokenOnStack( handle,
- new Token( workingMemory,
- handle,
- context ) );
+ final DefaultFactHandle startFactHandle = new DefaultFactHandle( workingMemory.getIdLastFireAllAt( ),
+ new Object( ) );
+ for (final Iterator it = this.tailIterator( startFactHandle, startFactHandle ); it.hasNext( );) {
+ final LeapsFactHandle handle = (LeapsFactHandle) it.next( );
+ workingMemory.pushTokenOnStack( handle, new Token( workingMemory,
+ handle,
+ context ) );
}
}
}
@@ -141,7 +140,7 @@
* @param new
* value
*/
- public void setReseededStack(final boolean reseeded) {
+ public void setReseededStack( final boolean reseeded ) {
this.reseededStack = reseeded;
}
@@ -152,41 +151,42 @@
* @return iterator of positive rule handles
*/
public Iterator getRulesIterator() {
- return this.rules.iterator();
+ return this.rules.iterator( );
}
/**
* @see java.lang.Object
*/
public String toString() {
- final StringBuffer ret = new StringBuffer();
+ final StringBuffer ret = new StringBuffer( );
- for ( final Iterator it = this.iterator(); it.hasNext(); ) {
- final FactHandleImpl handle = (FactHandleImpl) it.next();
- ret.append( "\n" + handle + "[" + handle.getObject() + "]" );
+ for (final Iterator it = this.iterator( ); it.hasNext( );) {
+ final LeapsFactHandle handle = (LeapsFactHandle) it.next( );
+ ret.append( "\n" + handle + "[" + handle.getObject( ) + "]" );
}
ret.append( "\nTuples :" );
- for ( final Iterator it = this.tuples.iterator(); it.hasNext(); ) {
- ret.append( "\n" + it.next() );
+ for (final Iterator it = this.tuples.iterator( ); it.hasNext( );) {
+ ret.append( "\n" + it.next( ) );
}
ret.append( "\nRules :" );
- for ( final Iterator it = this.rules.iterator(); it.hasNext(); ) {
- final RuleHandle handle = (RuleHandle) it.next();
- ret.append( "\n\t" + handle.getLeapsRule().getRule().getName() + "[dominant - " + handle.getDominantPosition() + "]" );
+ for (final Iterator it = this.rules.iterator( ); it.hasNext( );) {
+ final LeapsRuleHandle handle = (LeapsRuleHandle) it.next( );
+ ret.append( "\n\t" + handle.getLeapsRule( ).getRule( ).getName( )
+ + "[dominant - " + handle.getDominantPosition( ) + "]" );
}
- return ret.toString();
+ return ret.toString( );
}
protected Iterator getTuplesIterator() {
- return this.tuples.iterator();
+ return this.tuples.iterator( );
}
- protected void addTuple(final LeapsTuple tuple) {
+ protected void addTuple( final LeapsTuple tuple ) {
this.tuples.add( tuple );
}
-}
\ No newline at end of file
+}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/Handle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/Handle.java 2006-06-03 03:08:51 UTC (rev 4586)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/Handle.java 2006-06-03 03:16:27 UTC (rev 4587)
@@ -1,100 +0,0 @@
-package org.drools.leaps;
-
-/*
- * 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.
- */
-
-import java.io.Serializable;
-
-import org.drools.FactHandle;
-
-/**
- * Leaps handle for use with facts and rules. Is used extensively by leaps
- * tables.
- *
- * @author Alexander Bagerman
- *
- */
-public class Handle
- implements
- Serializable {
- private static final long serialVersionUID = 1L;
-
- // object to handle
- final private Object object;
-
- final private long id;
-
- private int objectHashCode;
-
- /**
- * creates a handle for object
- *
- * @param id
- * that is used to identify the object
- * @param object
- * to handle
- */
- public Handle(final long id,
- final Object object) {
- this.id = id;
- this.object = object;
- this.objectHashCode = object.hashCode();
- }
-
- /**
- * @return id of the object
- */
- public long getId() {
- return this.id;
- }
-
- /**
- * Leaps handles considered equal if ids match and content points to the
- * same object.
- */
- public boolean equals(final Object that) {
- return this.id == ((Handle) that).id && this.object == ((Handle) that).object;
- }
-
- /**
- * @return object being handled
- */
- public Object getObject() {
- return this.object;
- }
-
- public int getObjectHashCode() {
- return this.objectHashCode;
- }
-
- public int hashCode() {
- return ( int ) this.id;
- }
-
- /**
- * @see FactHandle
- */
- public long getRecency() {
- return this.id;
- }
-
- /**
- * @see java.lang.Object
- */
- public String toString() {
- return "id=" + this.id + " [" + this.object + "]";
- }
-}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsAgenda.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsAgenda.java 2006-06-03 03:08:51 UTC (rev 4586)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsAgenda.java 2006-06-03 03:16:27 UTC (rev 4587)
@@ -16,6 +16,8 @@
* limitations under the License.
*/
+import java.util.List;
+
import org.drools.common.DefaultAgenda;
import org.drools.rule.Query;
import org.drools.spi.Activation;
@@ -39,19 +41,36 @@
this.workingMemory = workingMemory;
}
- public synchronized void fireActivation(final Activation activation) throws ConsequenceException {
- if ( activation.getRule() instanceof Query ) {
+ public synchronized void fireActivation( final Activation activation )
+ throws ConsequenceException {
+ if (activation.getRule( ) instanceof Query) {
// put query results to the working memory location
- this.workingMemory.addToQueryResults( activation.getRule().getName(),
- activation.getTuple() );
- } else {
- if ( activation.getRule().getActivationGroup() == null || (activation.getRule().getActivationGroup() != null && this.getActivationGroup( activation.getRule().getActivationGroup() ).isEmpty()) ) {
+ this.workingMemory.addToQueryResults( activation.getRule( ).getName( ),
+ activation.getTuple( ) );
+ }
+ else {
+ if (activation.getRule( ).getActivationGroup( ) == null
+ || ( activation.getRule( ).getActivationGroup( ) != null && this.getActivationGroup( activation.getRule( )
+ .getActivationGroup( ) )
+ .isEmpty( ) )) {
// fire regular rule
super.fireActivation( activation );
- if ( activation.getRule().getActivationGroup() != null ) {
- this.getActivationGroup( activation.getRule().getActivationGroup() );
+ if (activation.getRule( ).getActivationGroup( ) != null) {
+ this.getActivationGroup( activation.getRule( ).getActivationGroup( ) );
}
}
}
}
+
+ /**
+ * to accomodate the difference between rete and leaps in storing
+ * activations. we pull activations from rule to activations map
+ * we store in working memory to facilitate activations removal
+ * when rule is removed from the memory
+ *
+ */
+ public Activation[] getActivations() {
+ final List list = this.workingMemory.getActivations();
+ return (Activation[]) list.toArray( new Activation[list.size()] );
+ }
}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsFactHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsFactHandle.java 2006-06-03 03:08:51 UTC (rev 4586)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsFactHandle.java 2006-06-03 03:16:27 UTC (rev 4587)
@@ -0,0 +1,84 @@
+package org.drools.leaps;
+
+/*
+ * 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.
+ */
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.drools.common.DefaultFactHandle;
+
+/**
+ * class container for each object asserted / retracted into the system
+ *
+ * @author Alexander Bagerman
+ *
+ */
+public class LeapsFactHandle extends DefaultFactHandle {
+
+ private List activatedTuples = null;
+
+ private List notTuples = null;
+
+ private List existsTuples = null;
+
+ public LeapsFactHandle(final long id, final Object object) {
+ super( id, object );
+ }
+
+ protected void addActivatedTuple( final LeapsTuple tuple ) {
+ if (this.activatedTuples == null) {
+ this.activatedTuples = new LinkedList( );
+ }
+ this.activatedTuples.add( tuple );
+ }
+
+ protected void addNotTuple( final LeapsTuple tuple, final int index ) {
+ if (this.notTuples == null) {
+ this.notTuples = new LinkedList( );
+ }
+ this.notTuples.add( new FactHandleTupleAssembly( tuple, index ) );
+ }
+
+ protected void addExistsTuple( final LeapsTuple tuple, final int index ) {
+ if (this.existsTuples == null) {
+ this.existsTuples = new LinkedList( );
+ }
+ this.existsTuples.add( new FactHandleTupleAssembly( tuple, index ) );
+ }
+
+ protected Iterator getActivatedTuples() {
+ if (this.activatedTuples != null) {
+ return this.activatedTuples.iterator( );
+ }
+ return null;
+ }
+
+ protected Iterator getNotTupleAssemblies() {
+ if (this.notTuples != null) {
+ return this.notTuples.iterator( );
+ }
+ return null;
+ }
+
+ protected Iterator getExistsTupleAssemblies() {
+ if (this.existsTuples != null) {
+ return this.existsTuples.iterator( );
+ }
+ return null;
+ }
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsFactHandleFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsFactHandleFactory.java 2006-06-03 03:08:51 UTC (rev 4586)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsFactHandleFactory.java 2006-06-03 03:16:27 UTC (rev 4587)
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-import org.drools.common.DefaultFactHandle;
+import org.drools.common.EqualityKey;
import org.drools.common.InternalFactHandle;
import org.drools.spi.FactHandleFactory;
@@ -24,9 +24,7 @@
* @author Alexander Bagerman
*
*/
-class LeapsFactHandleFactory
- implements
- FactHandleFactory {
+class LeapsFactHandleFactory implements FactHandleFactory {
private static final long serialVersionUID = 8510623248591449450L;
private long counter;
@@ -41,9 +39,8 @@
*
* @see org.drools.reteoo.FactHandleFactory
*/
- public final InternalFactHandle newFactHandle(final Object object) {
- return new FactHandleImpl( this.getNextId(),
- object );
+ public final InternalFactHandle newFactHandle( final Object object ) {
+ return new LeapsFactHandle( this.getNextId( ), object );
}
/**
@@ -52,8 +49,7 @@
* @param object
* @return leaps handle
*/
- public final InternalFactHandle newFactHandle(final long newId,
- final Object object) {
+ public final InternalFactHandle newFactHandle( final long newId, final Object object ) {
return newFactHandle( object );
}
@@ -66,26 +62,32 @@
}
/**
- * does nothing in leaps context
+ * the same as in rete
*
* @see org.drools.reteoo.FactHandleFactory
*/
- public final void increaseFactHandleRecency(final InternalFactHandle factHandle) {
- ;
+ public final void increaseFactHandleRecency( final InternalFactHandle factHandle ) {
+ factHandle.setRecency( this.getNextId( ) );
}
- public void destroyFactHandle(final InternalFactHandle factHandle) {
- factHandle.invalidate();
+ /**
+ * instead of destroying we put EqualityKey back there
+ * because of the nature of Leaps processing delayed actions
+ *
+ * @see org.drools.reteoo.FactHandleFactory
+ */
+ public void destroyFactHandle( final InternalFactHandle factHandle ) {
+ factHandle.setEqualityKey( new EqualityKey( factHandle ) );
}
/**
* @see org.drools.reteoo.FactHandleFactory
*/
public FactHandleFactory newInstance() {
- return new LeapsFactHandleFactory();
+ return new LeapsFactHandleFactory( );
}
-
+
public Class getFactHandleType() {
- return FactHandleImpl.class;
+ return LeapsFactHandle.class;
}
-}
\ No newline at end of file
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsRuleHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsRuleHandle.java 2006-06-03 03:08:51 UTC (rev 4586)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsRuleHandle.java 2006-06-03 03:16:27 UTC (rev 4587)
@@ -0,0 +1,84 @@
+package org.drools.leaps;
+
+/*
+ * 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.
+ */
+
+import org.drools.common.DefaultFactHandle;
+
+/**
+ * class container for rules. Re-using defaultfact handle
+ *
+ * class container for rules used in the system. Handle is created for each
+ * leaps rule, dominant position (column/ce position), dominant position type
+ * (class at the column/ce position) or indicator if handle is for asserted or
+ * retracted tuple combination
+ *
+ * @author Alexander Bagerman
+ *
+ */
+public class LeapsRuleHandle extends DefaultFactHandle {
+
+ // ce position for which handle is created
+ private final int dominantPosition;
+
+ public LeapsRuleHandle(final long id, final LeapsRule rule,
+ final int dominantPosition) {
+ super( id, rule );
+ this.dominantPosition = dominantPosition;
+ }
+
+ /**
+ * @return leaps wrapped rule
+ */
+ public LeapsRule getLeapsRule() {
+ return (LeapsRule) this.getObject();
+ }
+
+ /**
+ * @return base column / ce position
+ */
+ public int getDominantPosition() {
+ return this.dominantPosition;
+ }
+
+ /**
+ * @see org.drools.rule.Rule
+ */
+ public int getRuleComplexity() {
+ return this.getLeapsRule().getRule().getDeclarations().length;
+ }
+
+ /**
+ * @see org.drools.rule.Rule
+ */
+ public int getSalience() {
+ return this.getLeapsRule().getRule().getSalience();
+ }
+
+ /**
+ * @see java.lang.Object
+ */
+ public boolean equals(final Object that) {
+ return super.equals( that ) && (this.getDominantPosition() == ((LeapsRuleHandle) that).getDominantPosition());
+ }
+
+ /**
+ * @see java.lang.Object
+ */
+ public String toString() {
+ return "R-" + this.getId() + " \"" + this.getLeapsRule().toString() + "\" [pos - " + this.dominantPosition + "]";
+ }
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsTuple.java 2006-06-03 03:08:51 UTC (rev 4586)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsTuple.java 2006-06-03 03:16:27 UTC (rev 4587)
@@ -40,11 +40,11 @@
private boolean readyForActivation;
- private final FactHandleImpl[] factHandles;
+ private final LeapsFactHandle[] factHandles;
- private FactHandleImpl[] blockingNotFactHandles = null;
+ private LeapsFactHandle[] blockingNotFactHandles = null;
- private FactHandleImpl[] existsFactHandles = null;
+ private LeapsFactHandle[] existsFactHandles = null;
private Activation activation;
@@ -53,7 +53,7 @@
/**
* agendaItem parts
*/
- LeapsTuple(final FactHandleImpl factHandles[],
+ LeapsTuple(final LeapsFactHandle factHandles[],
final LeapsRule leapsRule,
final PropagationContext context) {
this.factHandles = factHandles;
@@ -62,13 +62,13 @@
if ( this.leapsRule != null ) {
if ( this.leapsRule.containsNotColumns() ) {
- this.blockingNotFactHandles = new FactHandleImpl[this.leapsRule.getNotColumnConstraints().length];
+ this.blockingNotFactHandles = new LeapsFactHandle[this.leapsRule.getNotColumnConstraints().length];
for ( int i = 0; i < this.blockingNotFactHandles.length; i++ ) {
this.blockingNotFactHandles[i] = null;
}
}
if ( this.leapsRule.containsExistsColumns() ) {
- this.existsFactHandles = new FactHandleImpl[this.leapsRule.getExistsColumnConstraints().length];
+ this.existsFactHandles = new LeapsFactHandle[this.leapsRule.getExistsColumnConstraints().length];
for ( int i = 0; i < this.existsFactHandles.length; i++ ) {
this.existsFactHandles[i] = null;
}
@@ -213,7 +213,7 @@
return buffer.toString();
}
- protected void setBlockingNotFactHandle(final FactHandleImpl factHandle,
+ protected void setBlockingNotFactHandle(final LeapsFactHandle factHandle,
final int index) {
this.readyForActivation = false;
this.blockingNotFactHandles[index] = factHandle;
@@ -228,7 +228,7 @@
this.setReadyForActivation();
}
- protected void setExistsFactHandle(final FactHandleImpl factHandle,
+ protected void setExistsFactHandle(final LeapsFactHandle factHandle,
final int index) {
this.existsFactHandles[index] = factHandle;
this.setReadyForActivation();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsWorkingMemory.java 2006-06-03 03:08:51 UTC (rev 4586)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/leaps/LeapsWorkingMemory.java 2006-06-03 03:16:27 UTC (rev 4587)
@@ -50,6 +50,7 @@
import org.drools.spi.Duration;
import org.drools.spi.PropagationContext;
import org.drools.spi.Tuple;
+import org.drools.util.FastMap;
import org.drools.util.IdentityMap;
import org.drools.util.IteratorChain;
@@ -65,17 +66,15 @@
* @see java.io.Serializable
*
*/
-class LeapsWorkingMemory extends AbstractWorkingMemory
- implements
- EventSupport,
- PropertyChangeListener {
+class LeapsWorkingMemory extends AbstractWorkingMemory implements EventSupport,
+ PropertyChangeListener {
private static final long serialVersionUID = -2524904474925421759L;
private final Map queryResults;
- private final IdentityMap leapsRulesToHandlesMap = new IdentityMap();
+ private final IdentityMap leapsRulesToHandlesMap = new IdentityMap( );
- private final IdentityMap rulesActivationsMap = new IdentityMap();
+ private final IdentityMap rulesActivationsMap = new IdentityMap( );
/**
* Construct.
@@ -84,30 +83,18 @@
* The backing rule-base.
*/
public LeapsWorkingMemory(final InternalRuleBase ruleBase) {
- super( ruleBase,
- ruleBase.newFactHandleFactory() );
- this.queryResults = new HashMap();
+ super( ruleBase, ruleBase.newFactHandleFactory( ) );
+ this.queryResults = new HashMap( );
this.agenda = new LeapsAgenda( this );
}
- public List getObjects(final Class objectClass) {
- // @todo why can't this use assertMap and thus the AbstractWorkingMemory impl?
- final List list = new LinkedList();
- for ( final Iterator it = this.getFactTable( objectClass ).iterator(); it.hasNext(); ) {
- list.add( ((FactHandleImpl) it.next()).getObject() );
- }
+ public void doAssertObject( final InternalFactHandle factHandle,
+ final Object object,
+ final PropagationContext propagationContext )
+ throws FactException {
+
+ this.pushTokenOnStack( factHandle, new Token( this, factHandle, propagationContext ) );
- return list;
- }
-
- public void doAssertObject(final InternalFactHandle factHandle,
- final Object object,
- final PropagationContext propagationContext) throws FactException {
- this.pushTokenOnStack( factHandle,
- new Token( this,
- factHandle,
- propagationContext ) );
-
// determine what classes it belongs to put it into the "table" on
// class name key
final Class objectClass = object.getClass();
@@ -118,58 +105,61 @@
// inspect all tuples for exists and not conditions and activate
// /
// deactivate agenda items
- for ( final Iterator tuples = factTable.getTuplesIterator(); tuples.hasNext(); ) {
- final LeapsTuple tuple = (LeapsTuple) tuples.next();
- boolean tupleWasReadyForActivation = tuple.isReadyForActivation();
- if ( !tuple.isActivationNull() ) {
+ for (final Iterator tuples = factTable.getTuplesIterator( ); tuples.hasNext( );) {
+ final LeapsTuple tuple = (LeapsTuple) tuples.next( );
+ boolean tupleWasReadyForActivation = tuple.isReadyForActivation( );
+ if (!tuple.isActivationNull( )) {
// check not constraints only on activated tuples to see
// if
// we need to deactivate
- final ColumnConstraints[] not = tuple.getLeapsRule().getNotColumnConstraints();
- for ( int i = 0, length = not.length; i < length; i++ ) {
+ final ColumnConstraints[] not = tuple.getLeapsRule( )
+ .getNotColumnConstraints( );
+ for (int i = 0, length = not.length; i < length; i++) {
final ColumnConstraints constraint = not[i];
- if ( !tuple.isBlockingNotFactHandle( i ) && constraint.getClassType().isAssignableFrom( objectClass ) && constraint.isAllowed( factHandle,
- tuple,
- this ) ) {
- tuple.setBlockingNotFactHandle( (FactHandleImpl) factHandle,
- i );
- ((FactHandleImpl) factHandle).addNotTuple( tuple,
- i );
+ if (!tuple.isBlockingNotFactHandle( i )
+ && constraint.getClassType( )
+ .isAssignableFrom( objectClass )
+ && constraint.isAllowed( factHandle, tuple, this )) {
+ tuple.setBlockingNotFactHandle( (LeapsFactHandle) factHandle, i );
+ ( (LeapsFactHandle) factHandle ).addNotTuple( tuple, i );
}
}
// check and see if we need de-activate
- if ( !tuple.isReadyForActivation() ) {
- if ( tuple.getLeapsRule().getRule() instanceof Query ) {
+ if (!tuple.isReadyForActivation( )) {
+ if (tuple.getLeapsRule( ).getRule( ) instanceof Query) {
// put query results to the working memory
// location
- removeFromQueryResults( tuple.getLeapsRule().getRule().getName(),
- tuple );
- } else {
+ removeFromQueryResults( tuple.getLeapsRule( )
+ .getRule( )
+ .getName( ), tuple );
+ }
+ else {
// time to pull from agenda
invalidateActivation( tuple );
}
}
- } else {
+ }
+ else {
// check exists constraints and activate constraints
- final ColumnConstraints[] exists = tuple.getLeapsRule().getExistsColumnConstraints();
- for ( int i = 0, length = exists.length; i < length; i++ ) {
+ final ColumnConstraints[] exists = tuple.getLeapsRule( )
+ .getExistsColumnConstraints( );
+ for (int i = 0, length = exists.length; i < length; i++) {
final ColumnConstraints constraint = exists[i];
- if ( !tuple.isExistsFactHandle( i ) && constraint.getClassType().isAssignableFrom( objectClass ) && constraint.isAllowed( factHandle,
- tuple,
- this ) ) {
- tuple.setExistsFactHandle( (FactHandleImpl) factHandle,
- i );
- ((FactHandleImpl) factHandle).addExistsTuple( tuple,
- i );
+ if (!tuple.isExistsFactHandle( i )
+ && constraint.getClassType( )
+ .isAssignableFrom( objectClass )
+ && constraint.isAllowed( factHandle, tuple, this )) {
+ tuple.setExistsFactHandle( (LeapsFactHandle) factHandle, i );
+ ( (LeapsFactHandle) factHandle ).addExistsTuple( tuple, i );
}
}
// check and see if we need activate
// activate only if tuple was not ready for it before
- if ( tuple.isReadyForActivation() && !tupleWasReadyForActivation ) {
+ if (!tupleWasReadyForActivation && tuple.isReadyForActivation( )) {
// ready to activate
- tuple.setContext( new PropagationContextImpl( nextPropagationIdCounter(),
+ tuple.setContext( new PropagationContextImpl( nextPropagationIdCounter( ),
PropagationContext.ASSERTION,
- tuple.getLeapsRule().getRule(),
+ tuple.getLeapsRule( ).getRule( ),
null ) );
this.assertTuple( tuple );
@@ -186,55 +176,55 @@
*
* @see WorkingMemory
*/
- public void doRetract(final InternalFactHandle factHandle,
- final PropagationContext propagationContext) {
+ public void doRetract( final InternalFactHandle factHandle,
+ final PropagationContext propagationContext ) {
/*
* leaps specific actions
*/
// remove fact from all relevant fact tables container
- for ( final Iterator it = this.getFactTablesList( ((FactHandleImpl) factHandle).getObject().getClass() ).iterator(); it.hasNext(); ) {
- ((FactTable) it.next()).remove( factHandle );
+ for (final Iterator it = this.getFactTablesList( factHandle.getObject( ).getClass( ) )
+ .iterator( ); it.hasNext( );) {
+ ( (FactTable) it.next( ) ).remove( factHandle );
}
// 0. remove activated tuples
- final Iterator tuples = ((FactHandleImpl) factHandle).getActivatedTuples();
- for ( ; tuples != null && tuples.hasNext(); ) {
- final LeapsTuple tuple = (LeapsTuple) tuples.next();
- if ( tuple.getLeapsRule().getRule() instanceof Query ) {
+ final Iterator tuples = ( (LeapsFactHandle) factHandle ).getActivatedTuples( );
+ for (; tuples != null && tuples.hasNext( );) {
+ final LeapsTuple tuple = (LeapsTuple) tuples.next( );
+ if (tuple.getLeapsRule( ).getRule( ) instanceof Query) {
// put query results to the working memory location
- removeFromQueryResults( tuple.getLeapsRule().getRule().getName(),
- tuple );
- } else {
+ removeFromQueryResults( tuple.getLeapsRule( ).getRule( ).getName( ), tuple );
+ }
+ else {
// time to pull from agenda
invalidateActivation( tuple );
}
}
// 1. remove fact for nots and exists tuples
- final IdentityMap tuplesNotReadyForActivation = new IdentityMap();
+ final IdentityMap tuplesNotReadyForActivation = new IdentityMap( );
FactHandleTupleAssembly assembly;
LeapsTuple tuple;
Iterator it;
- it = ((FactHandleImpl) factHandle).getNotTupleAssemblies();
- if ( it != null ) {
- for ( ; it.hasNext(); ) {
- assembly = (FactHandleTupleAssembly) it.next();
- tuple = assembly.getTuple();
- if ( !tuple.isReadyForActivation() ) {
- tuplesNotReadyForActivation.put( tuple,
- tuple );
+ it = ( (LeapsFactHandle) factHandle ).getNotTupleAssemblies( );
+ if (it != null) {
+ for (; it.hasNext( );) {
+ assembly = (FactHandleTupleAssembly) it.next( );
+ tuple = assembly.getTuple( );
+ if (!tuple.isReadyForActivation( )) {
+ tuplesNotReadyForActivation.put( tuple, tuple );
}
- tuple.removeBlockingNotFactHandle( assembly.getIndex() );
- // @todo why is this null? It breaks FactHandle hashCode - chaning to new Object() for now
- TokenEvaluator.evaluateNotCondition( new FactHandleImpl( ((FactHandleImpl) factHandle).getId() + 1,
- new Object() ),
- assembly.getIndex(),
+ tuple.removeBlockingNotFactHandle( assembly.getIndex( ) );
+
+ TokenEvaluator.evaluateNotCondition( new LeapsFactHandle( factHandle.getRecency( ) + 1,
+ new Object( ) ),
+ assembly.getIndex( ),
tuple,
this );
}
}
- it = ((FactHandleImpl) factHandle).getExistsTupleAssemblies();
+ it = ((LeapsFactHandle) factHandle).getExistsTupleAssemblies();
if ( it != null ) {
for ( ; it.hasNext(); ) {
assembly = (FactHandleTupleAssembly) it.next();
@@ -243,10 +233,10 @@
tuplesNotReadyForActivation.put( tuple,
tuple );
}
- tuple.removeExistsFactHandle( assembly.getIndex() );
- TokenEvaluator.evaluateExistsCondition( new FactHandleImpl( ((FactHandleImpl) factHandle).getId() + 1,
- null ),
- assembly.getIndex(),
+ tuple.removeExistsFactHandle( assembly.getIndex( ) );
+ TokenEvaluator.evaluateExistsCondition( new LeapsFactHandle( factHandle.getRecency( ) + 1,
+ null ),
+ assembly.getIndex( ),
tuple,
this );
}
@@ -254,31 +244,35 @@
// 2. assert all tuples that are ready for activation or cancel ones
// that are no longer
final IteratorChain chain = new IteratorChain();
- it = ((FactHandleImpl) factHandle).getNotTupleAssemblies();
+ it = ((LeapsFactHandle) factHandle).getNotTupleAssemblies();
if ( it != null ) {
chain.addIterator( it );
}
- it = ((FactHandleImpl) factHandle).getExistsTupleAssemblies();
+ it = ((LeapsFactHandle) factHandle).getExistsTupleAssemblies();
if ( it != null ) {
chain.addIterator( it );
}
for ( ; chain.hasNext(); ) {
- tuple = ((FactHandleTupleAssembly) chain.next()).getTuple();
+ tuple = ( (FactHandleTupleAssembly) chain.next( ) ).getTuple( );
// can assert only tuples that were not eligible for activation
// before retraction
- if ( tuple.isReadyForActivation() && tuple.isActivationNull() && tuplesNotReadyForActivation.containsKey( tuple ) ) {
+ if (tuple.isReadyForActivation( ) && tuple.isActivationNull( )
+ && tuplesNotReadyForActivation.containsKey( tuple )) {
// ready to activate
- tuple.setContext( new PropagationContextImpl( nextPropagationIdCounter(),
+ tuple.setContext( new PropagationContextImpl( nextPropagationIdCounter( ),
PropagationContext.ASSERTION,
- tuple.getLeapsRule().getRule(),
+ tuple.getLeapsRule( )
+ .getRule( ),
null ) );
this.assertTuple( tuple );
- } else {
- if ( tuple.getLeapsRule().getRule() instanceof Query ) {
+ }
+ else {
+ if (tuple.getLeapsRule( ).getRule( ) instanceof Query) {
// put query results to the working memory location
- removeFromQueryResults( tuple.getLeapsRule().getRule().getName(),
+ removeFromQueryResults( tuple.getLeapsRule( ).getRule( ).getName( ),
tuple );
- } else {
+ }
+ else {
// time to pull from agenda
invalidateActivation( tuple );
}
@@ -286,7 +280,7 @@
}
// remove it from stack
- this.removeTokenFromStack( (FactHandleImpl) factHandle );
+ this.removeTokenFromStack( (LeapsFactHandle) factHandle );
}
/**
@@ -295,65 +289,99 @@
*
* @param tuple
*/
- private final void invalidateActivation(final LeapsTuple tuple) {
- final Activation activation = tuple.getActivation();
- if ( !tuple.isReadyForActivation() && !tuple.isActivationNull() ) {
+ private final void invalidateActivation( final LeapsTuple tuple ) {
+ final Activation activation = tuple.getActivation( );
+ if (!tuple.isReadyForActivation( ) && !tuple.isActivationNull( )) {
// invalidate agenda agendaItem
- if ( activation.isActivated() ) {
- activation.remove();
- getAgendaEventSupport().fireActivationCancelled( activation );
+ if (activation.isActivated( )) {
+ activation.remove( );
+ getAgendaEventSupport( ).fireActivationCancelled( activation );
}
//
tuple.setActivation( null );
}
- // remove logical dependency
- if ( activation != null ) {
+ if (activation != null) {
+ // remove logical dependency
this.tms.removeLogicalDependencies( activation,
- tuple.getContext(),
- tuple.getLeapsRule().getRule() );
+ tuple.getContext( ),
+ tuple.getLeapsRule( ).getRule( ) );
+
+ // remove from rule / activaitons map
+ FastMap activations = (FastMap) this.rulesActivationsMap.get( activation.getRule( ) );
+ if (activations != null) {
+ activations.remove( activation );
+ }
}
}
/**
+ * modify is implemented as half way retract / assert due to the truth maintenance issues.
+ *
* @see WorkingMemory
*/
- public void modifyObject(final FactHandle factHandle,
- final Object object,
- final Rule rule,
- final Activation activation) throws FactException {
- this.getLock().lock();
+ public void modifyObject( final FactHandle factHandle,
+ final Object object,
+ final Rule rule,
+ final Activation activation ) throws FactException {
+ this.getLock( ).lock( );
try {
- final int status = ((InternalFactHandle) factHandle).getEqualityKey().getStatus();
- final InternalFactHandle handle = (InternalFactHandle) factHandle;
+ final PropagationContext propagationContext = new PropagationContextImpl( this.propagationIdCounter++,
+ PropagationContext.MODIFICATION,
+ rule,
+ activation );
+ final int status = ( (InternalFactHandle) factHandle ).getEqualityKey( )
+ .getStatus( );
+
final Object originalObject = this.assertMap.remove( factHandle );
+ if (originalObject == null) {
+ throw new NoSuchFactObjectException( factHandle );
+ }
+ //
+ // do subset of retractObject( )
+ //
+ final InternalFactHandle handle = (InternalFactHandle) factHandle;
+ if (handle.getId( ) == -1) {
+ // can't retract an already retracted handle
+ return;
+ }
+ removePropertyChangeListener( handle );
- if ( originalObject == null ) {
- throw new NoSuchFactObjectException( handle );
+ doRetract( handle, propagationContext );
+
+ // Update the equality key, which maintains a list of stated
+ // FactHandles
+ final EqualityKey key = handle.getEqualityKey( );
+
+ key.removeFactHandle( handle );
+ handle.setEqualityKey( null );
+
+ // If the equality key is now empty, then remove it
+ if (key.isEmpty( )) {
+ this.tms.remove( key );
}
+ // produces NPE otherwise
+ this.handleFactory.destroyFactHandle( handle );
- this.retractObject( handle );
-
+ //
+ // and now assert
+ //
/* check to see if this is a logically asserted object */
- final FactHandleImpl handleImpl = (FactHandleImpl) this.assertObject( object,
- false,
- (status == EqualityKey.STATED) ? false : true,
- rule,
- activation );
+ this.assertObject( object, false, ( status == EqualityKey.STATED ) ? false
+ : true, rule, activation );
- this.workingMemoryEventSupport.fireObjectModified( new PropagationContextImpl( nextPropagationIdCounter(),
- PropagationContext.MODIFICATION,
- rule,
- activation ),
+ this.workingMemoryEventSupport.fireObjectModified( propagationContext,
handle,
- ((FactHandleImpl) handle).getObject(),
+ handle.getObject( ),
object );
- if ( !this.factQueue.isEmpty() ) {
- propagateQueuedActions();
+
+ if (!this.factQueue.isEmpty( )) {
+ propagateQueuedActions( );
}
- } finally {
- this.getLock().unlock();
}
+ finally {
+ this.getLock( ).unlock( );
+ }
}
/**
@@ -364,7 +392,7 @@
/**
* algorithm stack.
*/
- private final TokenStack mainStack = new TokenStack();
+ private final TokenStack mainStack = new TokenStack( );
/**
* generates or just return List of internal factTables that correspond a
@@ -372,20 +400,20 @@
*
* @return
*/
- protected final List getFactTablesList(final Class c) {
- final ArrayList list = new ArrayList();
+ protected final List getFactTablesList( final Class c ) {
+ final ArrayList list = new ArrayList( );
// interfaces
- final Class[] interfaces = c.getInterfaces();
- for ( int i = 0; i < interfaces.length; i++ ) {
+ final Class[] interfaces = c.getInterfaces( );
+ for (int i = 0; i < interfaces.length; i++) {
list.add( this.getFactTable( interfaces[i] ) );
}
// classes
Class bufClass = c;
- while ( bufClass != null ) {
+ while (bufClass != null) {
//
list.add( this.getFactTable( bufClass ) );
// and get the next class on the list
- bufClass = bufClass.getSuperclass();
+ bufClass = bufClass.getSuperclass( );
}
return list;
}
@@ -406,8 +434,8 @@
*
* @param fact handle
*/
- protected final void removeTokenFromStack(final FactHandleImpl factHandle) {
- this.mainStack.remove( factHandle.getId() );
+ protected final void removeTokenFromStack( final LeapsFactHandle factHandle ) {
...
[truncated message content] |