public JavaUtilIterator(final LinkedList list, final boolean immutable) { this.list = list; this.nextNode = this.list.getFirst(); this.immutable = immutable; }
protected BetaNodeFieldConstraint[] convertToConstraints(LinkedList list) { final BetaNodeFieldConstraint[] array = new BetaNodeFieldConstraint[list.size()]; int i = 0; for ( LinkedListEntry entry = (LinkedListEntry) list.getFirst(); entry != null; entry = (LinkedListEntry) entry.getNext() ) { array[i++] = (BetaNodeFieldConstraint) entry.getObject(); } return array; } }
public void addLogicalDependency(final LogicalDependency node) { if ( this.justified == null ) { this.justified = new LinkedList<LogicalDependency>(); } this.justified.add( node ); }
@Test public void testRemoveFirst() { this.list.add( this.node1 ); this.list.add( this.node2 ); this.list.add( this.node3 ); assertSame( "List should return node1 on getFirst()", this.list.getFirst(), this.node1 ); this.list.removeFirst(); assertSame( "List should return node2 on getFirst()", this.list.getFirst(), this.node2 ); this.list.removeFirst(); assertSame( "List should return node3 on getFirst()", this.list.getFirst(), this.node3 ); this.list.removeFirst(); assertNull( "Empty list should return null on getFirst()", this.list.getFirst() ); }
@Test public void testSize() { this.list.add( this.node1 ); assertEquals( "LinkedList should have 1 node", this.list.size(), 1 ); this.list.add( this.node2 ); assertEquals( "LinkedList should have 2 nodes", this.list.size(), 2 ); this.list.add( this.node3 ); assertEquals( "LinkedList should have 3 nodes", this.list.size(), 3 ); }
/** * An Activation is no longer true so it no longer justifies any of the logical facts * it logically asserted. It iterates over the Activation's LinkedList of DependencyNodes * it retrieves the justitication set for each DependencyNode's FactHandle and removes * itself. If the Set is empty it retracts the FactHandle from the WorkingMemory. * * @param activation * @param context * @param rule * @throws FactException */ public void removeLogicalDependencies(final Activation activation, final PropagationContext context, final Rule rule) throws FactException { final LinkedList<LogicalDependency> list = activation.getLogicalDependencies(); if ( list == null || list.isEmpty() ) { return; } for ( LogicalDependency node = list.getFirst(); node != null; node = node.getNext() ) { removeLogicalDependency( activation, node, context ); } }
@Test public void testAdd() { this.list.add( this.node1 ); assertNull( "Node1 previous should be null", this.node1.getPrevious() ); this.node1.getNext() ); assertSame( "First node should be node1", this.list.getFirst(), this.node1 ); assertSame( "Last node should be node1", this.list.getLast(), this.node1 ); this.list.add( this.node2 ); assertSame( "node1 next should be node2", this.node1.getNext(), this.node1 ); assertSame( "First node should be node1", this.list.getFirst(), this.node1 ); assertSame( "Last node should be node2", this.list.getLast(), this.node2 ); this.list.add( this.node3 ); assertSame( "node2 next should be node3", this.node2.getNext(),
public void cancelRemainingPreviousLogicalDependencies() { if ( this.previousJustified != null ) { for ( LogicalDependency dep = (LogicalDependency) this.previousJustified.getFirst(); dep != null; dep = (LogicalDependency) dep.getNext() ) { this.workingMemory.getTruthMaintenanceSystem().removeLogicalDependency( activation, dep, activation.getPropagationContext() ); } } if ( this.previousBlocked != null ) { for ( LogicalDependency dep = this.previousBlocked.getFirst(); dep != null; ) { LogicalDependency tmp = dep.getNext(); this.previousBlocked.remove( dep ); AgendaItem justified = ( AgendaItem ) dep.getJustified(); justified.getBlockers().remove( dep.getJustifierEntry() ); if (justified.getBlockers().isEmpty() ) { // the match is no longer blocked, so stage it ((DefaultAgenda)workingMemory.getAgenda()).getStageActivationsGroup().addActivation( justified ); } dep = tmp; } } }
public void blockActivation(org.drools.runtime.rule.Activation act) { AgendaItem targetMatch = ( AgendaItem ) act; // iterate to find previous equal logical insertion LogicalDependency dep = null; if ( this.previousJustified != null ) { for ( dep = this.previousJustified.getFirst(); dep != null; dep = dep.getNext() ) { if ( targetMatch == dep.getJustified() ) { this.previousJustified.remove( dep ); break; } } } if ( dep == null ) { dep = new SimpleLogicalDependency( activation, targetMatch ); } this.activation.addBlocked( dep ); if ( targetMatch.getBlockers().size() == 1 && targetMatch.isActive() ) { // it wasn't blocked before, but is now, so we must remove it from all groups, so it cannot be executed. targetMatch.remove(); if ( targetMatch.getActivationGroupNode() != null ) { targetMatch.getActivationGroupNode().getActivationGroup().removeActivation( targetMatch ); } if ( targetMatch.getActivationNode() != null ) { final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) targetMatch.getActivationNode().getParentContainer(); ruleFlowGroup.removeActivation( targetMatch ); } } }
public void addBlocked(final LogicalDependency dep) { // Adds the blocked to the blockers list if ( this.blocked == null ) { this.blocked = new LinkedList<LogicalDependency>(); } this.blocked.add( dep ); // now ad the blocker to the blocked's list - we need to check that references are null first AgendaItem blocked = (AgendaItem)dep.getJustified(); if ( blocked.blockers == null ) { blocked.blockers = new LinkedList<LinkedListEntry<LogicalDependency>>(); blocked.blockers.add( dep.getJustifierEntry() ); } else if ( dep.getJustifierEntry().getNext() == null && dep.getJustifierEntry().getPrevious() == null && blocked.getBlockers().getFirst() != dep.getJustifierEntry() ) { blocked.blockers.add( dep.getJustifierEntry() ); } }
@Test public void testGetFirst() { assertNull( "Empty list should return null on getFirst()", this.list.getFirst() ); this.list.add( this.node1 ); assertSame( "List should return node1 on getFirst()", this.list.getFirst(), this.node1 ); this.list.add( this.node2 ); assertSame( "List should return node1 on getFirst()", this.list.getFirst(), this.node1 ); this.list.add( this.node3 ); assertSame( "List should return node1 on getFirst()", this.list.getFirst(), this.node1 ); }
public int size() { return this.list.size(); }
public Activation getNext() { Activation activation = null; while ( this.index <= lastIndex ) { LinkedList<LinkedListEntry<Activation>> list = this.array[this.index]; if ( list != null ) { activation = list.removeFirst().getObject(); if ( list.isEmpty()) { this.array[this.index++] = null; } this.size--; break; } this.index++; } return activation; }
@Test public void testRemoveLast() { this.list.add( this.node1 ); this.list.add( this.node2 ); this.list.add( this.node3 ); assertSame( "List should return node1 on getLast()", this.list.getLast(), this.node3 ); this.list.removeLast(); assertSame( "List should return node2 on getLast()", this.list.getLast(), this.node2 ); this.list.removeLast(); assertSame( "List should return node3 on getLast()", this.list.getLast(), this.node1 ); this.list.removeLast(); assertNull( "Empty list should return null on getLast()", this.list.getLast() ); }
public void remove() { if ( this.immutable ) { throw new UnsupportedOperationException( "This Iterator is immutable, you cannot call remove()" ); } if ( this.currentNode != null ) { this.list.remove( this.currentNode ); this.currentNode = null; } else { throw new IllegalStateException( "No item to remove. Call next() before calling remove()." ); } } }
public void setAutoDeactivate(final boolean autoDeactivate) { this.autoDeactivate = autoDeactivate; if ( autoDeactivate && this.active && this.list.isEmpty() ) { this.active = false; } }
@Before public void setUp() throws Exception { this.list = new LinkedList(); this.node1 = new AbstractBaseLinkedListNodeMock(); this.node2 = new AbstractBaseLinkedListNodeMock(); this.node3 = new AbstractBaseLinkedListNodeMock(); }