diff --git a/drools-core/src/main/java/org/drools/core/reteoo/AbstractTuple.java b/drools-core/src/main/java/org/drools/core/reteoo/AbstractTuple.java index b1abe3d0aac..82abbe59fd9 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/AbstractTuple.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/AbstractTuple.java @@ -35,7 +35,7 @@ public abstract class AbstractTuple implements Tuple { protected Tuple stagedPrevious; private Tuple previous; - private AbstractTuple next; + private Tuple next; private Sink sink; @@ -112,11 +112,11 @@ public void setPrevious(Tuple previous) { this.previous = previous; } - public AbstractTuple getNext() { + public Tuple getNext() { return next; } - public void setNext(AbstractTuple next) { + public void setNext(Tuple next) { this.next = next; } diff --git a/drools-core/src/main/java/org/drools/core/reteoo/FromNode.java b/drools-core/src/main/java/org/drools/core/reteoo/FromNode.java index 272d3863c10..13875d2bf2e 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/FromNode.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/FromNode.java @@ -225,7 +225,7 @@ public void addToCreatedHandlesMap(final Map matches, // this is for the obscene case where two or more objects returned by "from" // have the same hash code and evaluate equals() to true, so we need to preserve // all of them to avoid leaks - rightTuple.setNext((AbstractTuple) existingMatch); + rightTuple.setNext( existingMatch ); } matches.put( object, rightTuple ); diff --git a/drools-core/src/main/java/org/drools/core/reteoo/Tuple.java b/drools-core/src/main/java/org/drools/core/reteoo/Tuple.java index 471434396c8..9a0c08838da 100644 --- a/drools-core/src/main/java/org/drools/core/reteoo/Tuple.java +++ b/drools-core/src/main/java/org/drools/core/reteoo/Tuple.java @@ -31,7 +31,7 @@ * Is able to return the FactHandleImpl members of the partial match for the requested pattern. * The pattern refers to the index position of the FactHandleImpl in the underlying implementation. */ -public interface Tuple extends BaseTuple, Serializable, Entry { +public interface Tuple extends BaseTuple, Serializable, Entry { short NONE = 0; short INSERT = 1; diff --git a/drools-core/src/main/java/org/drools/core/util/index/TupleList.java b/drools-core/src/main/java/org/drools/core/util/index/TupleList.java index d31445f4a43..7e8adb94ce2 100644 --- a/drools-core/src/main/java/org/drools/core/util/index/TupleList.java +++ b/drools-core/src/main/java/org/drools/core/util/index/TupleList.java @@ -19,7 +19,6 @@ import java.io.Serializable; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.AbstractTuple; import org.drools.core.reteoo.TupleMemory; import org.drools.core.reteoo.Tuple; import org.drools.core.util.Entry; @@ -86,8 +85,8 @@ public void removeAdd(Tuple tuple) { return; } - AbstractTuple previous = (AbstractTuple) tuple.getPrevious(); - AbstractTuple next = tuple.getNext(); + Tuple previous = tuple.getPrevious(); + Tuple next = tuple.getNext(); if (previous == null) { next.setPrevious( null ); this.first = next; @@ -96,7 +95,7 @@ public void removeAdd(Tuple tuple) { next.setPrevious( previous ); } - this.last.setNext((AbstractTuple) tuple); + this.last.setNext( tuple ); tuple.setPrevious( this.last ); tuple.setNext( null ); this.last = tuple; @@ -104,7 +103,7 @@ public void removeAdd(Tuple tuple) { public void add(final Tuple tuple) { if ( this.last != null ) { - this.last.setNext( (AbstractTuple) tuple ); + this.last.setNext( tuple ); tuple.setPrevious( this.last ); this.last = tuple; } else { @@ -118,7 +117,7 @@ public void add(final Tuple tuple) { public void remove(final Tuple tuple) { Tuple previous = tuple.getPrevious(); - AbstractTuple next = tuple.getNext(); + Tuple next = tuple.getNext(); if ( previous != null && next != null ) { // remove from middle diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FromTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FromTest.java index 251af445882..9000e25deaa 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FromTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FromTest.java @@ -16,6 +16,18 @@ package org.drools.model.codegen.execmodel; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + import org.drools.model.codegen.execmodel.FunctionsTest.Pojo; import org.drools.model.codegen.execmodel.domain.Address; import org.drools.model.codegen.execmodel.domain.Adult; @@ -1538,61 +1550,4 @@ public void setStrValue(String strValue) { } } - - @Test - public void testFromGlobalWithDuplicates() { - String str = - "import java.util.concurrent.atomic.AtomicInteger;\n" + - "import " + NamedPerson.class.getCanonicalName() + ";\n" + - "global java.util.List list \n" + - "rule R when \n" + - " $i : AtomicInteger()\n" + - " $o : NamedPerson(age > $i.get()) from list\n" + - "then \n" + - " insert($o); \n" + - "end "; - - KieSession ksession = getKieSession(str); - - List strings = Arrays.asList(new NamedPerson("Mario", 1), new NamedPerson("Mario", 2)); - - ksession.setGlobal("list", strings); - - AtomicInteger i = new AtomicInteger(0); - FactHandle fh = ksession.insert(i); - - assertThat(ksession.fireAllRules()).isEqualTo(2); - - i.incrementAndGet(); - ksession.update(fh, i); - - assertThat(ksession.fireAllRules()).isEqualTo(1); - } - - public static class NamedPerson { - private final String name; - private final int age; - - public NamedPerson(String name, int age) { - this.name = name; - this.age = age; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - NamedPerson myPerson = (NamedPerson) o; - return Objects.equals(name, myPerson.name); - } - - @Override - public int hashCode() { - return Objects.hash(name); - } - - public int getAge() { - return age; - } - } } diff --git a/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/constraints/LambdaGroupByAccumulate.java b/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/constraints/LambdaGroupByAccumulate.java index 2f38710cb4b..a5d618fca03 100644 --- a/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/constraints/LambdaGroupByAccumulate.java +++ b/drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/constraints/LambdaGroupByAccumulate.java @@ -110,7 +110,7 @@ public Object accumulate(Object workingMemoryContext, Object context, GroupByContext groupByContext = ( GroupByContext ) context; LeftTuple leftTupleMatch = (LeftTuple) match; TupleList tupleList = groupByContext.getGroup(workingMemoryContext, innerAccumulate, - leftTupleMatch, getKey(leftTupleMatch, handle, (ReteEvaluator) valueResolver), (ReteEvaluator) valueResolver); + (Tuple) match, getKey( (Tuple) match, handle, (ReteEvaluator) valueResolver), (ReteEvaluator) valueResolver); return accumulate(workingMemoryContext, match, handle, groupByContext, tupleList, valueResolver); } @@ -126,7 +126,7 @@ public Object accumulate(Object workingMemoryContext, BaseTuple match, FactHandl @Override public boolean tryReverse(Object workingMemoryContext, Object context, BaseTuple leftTuple, FactHandle handle, BaseTuple match, ValueResolver valueResolver) { - LeftTuple tupleMatch = (LeftTuple) match; + Tuple tupleMatch = (Tuple) match; TupleList memory = tupleMatch.getMemory(); AccumulateContextEntry entry = memory.getContext(); boolean reversed = innerAccumulate.tryReverse(workingMemoryContext, entry, leftTuple, handle, match, valueResolver);