use of org.whole.lang.commands.ICommand in project whole by wholeplatform.
the class HistoryManager method reduce.
// TODO called by model to delta Stream if changes.size > model.size
protected List<ICommand> reduce(List<ICommand> commands) {
if (commands.isEmpty())
return commands;
List<ICommand> list = new ArrayList<ICommand>();
for (int i = 0, size = commands.size(); i < size; i++) {
ICommand command = commands.get(i);
if (CommandKind.COMPOUND == command.getKind()) {
for (ICommand child : ((CompoundCommand) command).commands) list.add(child);
} else
list.add(command);
}
int index = list.size() - 1;
while (index > 0) {
ICommand lastCommand = list.get(index--);
if (CommandKind.CHANGE == lastCommand.getKind()) {
IEntity lastSource = lastCommand.getSource();
FeatureDescriptor lastSourceFD = lastCommand.getSourceFeatureDescriptor();
int firstIndex = index;
while (firstIndex >= 0) {
ICommand firstCommand = list.get(firstIndex);
if (CommandKind.CHANGE != firstCommand.getKind() || firstCommand.getSource() != lastSource || firstCommand.getSourceFeatureDescriptor() != lastSourceFD)
break;
else
firstIndex--;
}
if (firstIndex < index) {
if (lastSourceFD == null)
lastCommand.setOldObject(list.get(firstIndex + 1).getOldObject());
else
lastCommand.setOldEntity(list.get(firstIndex + 1).getOldEntity());
for (int i = firstIndex + 1; i <= index; i++) list.remove(firstIndex + 1).dispose();
index = firstIndex;
}
}
}
return list;
// iterate over model tree to exclude overridden commands
// for each command discard overridden prevCommands
}
use of org.whole.lang.commands.ICommand in project whole by wholeplatform.
the class LifecycleAPITest method testCommit.
@Test
public void testCommit() {
ITransaction transaction = ReflectionFactory.getTransaction(model);
IEntity e1 = model.wGet(0);
IEntity e2 = model.wGet(3);
transaction.begin();
e1.wSetValue("newLangName");
ICommand c1 = ((InternalIEntity) e1).wGetLastCommand();
e2.wSetValue("newNamespace");
ICommand c2 = ((InternalIEntity) e2).wGetLastCommand();
String langName = e1.wStringValue();
int size = history.getUndoSize();
assertTrue(c1.getExecutionTime() <= c2.getExecutionTime());
transaction.commit();
assertEquals(e1.wStringValue(), langName);
assertTrue(history.getUndoSize() < size);
assertEquals(c1.getExecutionTime(), c2.getExecutionTime());
}
Aggregations