use of org.drools.core.spi.Tuple in project drools by kiegroup.
the class DurationTimer method createTrigger.
public Trigger createTrigger(Activation item, InternalWorkingMemory wm) {
long timestamp;
if (eventFactHandle != null) {
Tuple leftTuple = item.getTuple();
EventFactHandle fh = (EventFactHandle) leftTuple.get(eventFactHandle);
timestamp = fh.getStartTimestamp();
} else {
timestamp = wm.getTimerService().getCurrentTime();
}
String[] calendarNames = item.getRule().getCalendars();
Calendars calendars = wm.getCalendars();
return createTrigger(timestamp, calendarNames, calendars);
}
use of org.drools.core.spi.Tuple in project drools by kiegroup.
the class WorkingMemoryLogger method extractDeclarations.
/**
* Creates a string representation of the declarations of an activation.
* This is a list of name-value-pairs for each of the declarations in the
* tuple of the activation. The name is the identifier (=name) of the
* declaration, and the value is a toString of the value of the
* parameter, followed by the id of the fact between parentheses.
*
* @param match The match from which the declarations should be extracted
* @return A String represetation of the declarations of the activation.
*/
private String extractDeclarations(Match match) {
final StringBuilder result = new StringBuilder();
List<String> declarations = match.getDeclarationIds();
Map<String, Declaration> declsMap = ((AgendaItem) match).getTerminalNode().getSubRule().getOuterDeclarations();
for (int i = 0; i < declarations.size(); i++) {
String declaration = declarations.get(i);
Declaration decl = declsMap.get(declaration);
InternalFactHandle handle = ((Tuple) match).get(decl);
if (!handle.isValid()) {
continue;
}
Object value = decl.getValue(null, handle.getObject());
result.append(declaration);
result.append("=");
if (value == null) {
// this should never occur
result.append("null");
} else {
result.append(value);
}
if (i < declarations.size() - 1) {
result.append("; ");
}
}
return result.toString();
}
use of org.drools.core.spi.Tuple in project drools by kiegroup.
the class Scenario method assertEquals.
public void assertEquals(TupleSets<LeftTuple> expected, TupleSets<LeftTuple> actual, boolean testInsert, boolean testDelete, boolean testUpdate) {
Tuple expectedTuple;
Tuple actualTuple;
if (testInsert) {
if (expected.getInsertFirst() != null) {
expectedTuple = expected.getInsertFirst();
actualTuple = actual.getInsertFirst();
int i = 0;
for (; expectedTuple != null; expectedTuple = expectedTuple.getStagedNext()) {
Assert.assertTrue("insert " + i + ":\n" + actualTuple + "\nis not the expected\n" + expectedTuple, equals(expectedTuple, actualTuple));
actualTuple = actualTuple.getStagedNext();
i++;
}
assertNull("Insert excpected more", actualTuple);
} else if (actual.getInsertFirst() != null) {
fail("Expected nothing, but insert existed");
}
}
if (testDelete) {
if (expected.getDeleteFirst() != null) {
expectedTuple = expected.getDeleteFirst();
actualTuple = actual.getDeleteFirst();
int i = 0;
for (; expectedTuple != null; expectedTuple = expectedTuple.getStagedNext()) {
Assert.assertTrue("delete " + i + ":\n" + actualTuple + "\nis not the expected\n" + expectedTuple, equals(expectedTuple, actualTuple));
actualTuple = actualTuple.getStagedNext();
i++;
}
assertNull("Delete excpected more", actualTuple);
} else if (actual.getDeleteFirst() != null) {
fail("Expected nothing, but delete existed");
}
}
if (testUpdate) {
if (expected.getUpdateFirst() != null) {
expectedTuple = expected.getUpdateFirst();
actualTuple = actual.getUpdateFirst();
int i = 0;
for (; expectedTuple != null; expectedTuple = expectedTuple.getStagedNext()) {
Assert.assertTrue("update " + i + ":\n" + actualTuple + "\nis not the expected\n" + expectedTuple, equals(expectedTuple, actualTuple));
actualTuple = actualTuple.getStagedNext();
i++;
}
assertNull("Update excpected more", actualTuple);
} else if (actual.getUpdateFirst() != null) {
fail("Expected nothing, but update existed");
}
}
}
use of org.drools.core.spi.Tuple in project drools by kiegroup.
the class Scenario method equalsRightMemory.
public void equalsRightMemory(List<RightTuple> rightTuples) {
TupleMemory rtm = bm.getRightTupleMemory();
int length = 0;
for (RightTuple expectedRightTuple : rightTuples) {
FastIterator it = betaNode.getRightIterator(rtm);
Tuple actualRightTuple = null;
for (actualRightTuple = BetaNode.getFirstTuple(rtm, it); actualRightTuple != null; actualRightTuple = (RightTuple) it.next(actualRightTuple)) {
if (expectedRightTuple.equals(actualRightTuple)) {
length++;
break;
}
}
if (actualRightTuple == null) {
fail("Could not find RightTuple: " + expectedRightTuple);
}
}
if (rightTuples.size() != rtm.size()) {
fail("RightTuple memory size did not match: " + length);
}
}
Aggregations