Set<CommandEntry> oldCommandEntries = oldInvocation.getCommandEntries();
SortedSet<CommandEntry> sortedOldCommandEntries = new TreeSet<CommandEntry>(new CommandEntryManager.CommandEntryComparator());
sortedOldCommandEntries.addAll(oldCommandEntries);
for (CommandEntry oldCommandEntry : sortedOldCommandEntries) {
CommandEntryExtender extender = commandEntryManager.createCommandEntryExtender(oldCommandEntry);
CommandEntry duplicatedCommandEntry = extender.duplicateCommandEntry(newInvocation.getGroup(),mappingSet);
Set<InteractionList> invocations = new TreeSet<InteractionList>();
invocations.add(newInvocation);
duplicatedCommandEntry.setInteractionLists(invocations);
commandEntryManager.create(duplicatedCommandEntry); // also sets the ID for sorting
newCommandEntries.add(duplicatedCommandEntry);