use of org.drools.model.NamedModelItem in project drools by kiegroup.
the class CanonicalKieModule method addModifiedItemsToChangeSet.
private void addModifiedItemsToChangeSet(ResourceChangeSet changeSet, ResourceChange.Type type, List<? extends NamedModelItem> oldItems, List<? extends NamedModelItem> newItems) {
if (oldItems.isEmpty()) {
if (!newItems.isEmpty()) {
for (NamedModelItem newItem : newItems) {
changeSet.getChanges().add(new ResourceChange(ChangeType.ADDED, type, newItem.getName()));
}
}
return;
} else if (newItems.isEmpty()) {
for (NamedModelItem oldItem : oldItems) {
changeSet.getChanges().add(new ResourceChange(ChangeType.REMOVED, type, oldItem.getName()));
}
return;
}
oldItems.sort(Comparator.comparing(NamedModelItem::getName));
newItems.sort(Comparator.comparing(NamedModelItem::getName));
Iterator<? extends NamedModelItem> oldRulesIterator = oldItems.iterator();
Iterator<? extends NamedModelItem> newRulesIterator = newItems.iterator();
NamedModelItem currentOld = oldRulesIterator.next();
NamedModelItem currentNew = newRulesIterator.next();
while (true) {
int compare = currentOld.getName().compareTo(currentNew.getName());
if (compare == 0) {
if (!areEqualInModel(currentOld, currentNew)) {
changeSet.getChanges().add(new ResourceChange(ChangeType.UPDATED, type, currentOld.getName()));
}
if (oldRulesIterator.hasNext()) {
currentOld = oldRulesIterator.next();
} else {
break;
}
if (newRulesIterator.hasNext()) {
currentNew = newRulesIterator.next();
} else {
break;
}
} else if (compare < 0) {
changeSet.getChanges().add(new ResourceChange(ChangeType.REMOVED, type, currentOld.getName()));
if (oldRulesIterator.hasNext()) {
currentOld = oldRulesIterator.next();
} else {
break;
}
} else {
changeSet.getChanges().add(new ResourceChange(ChangeType.ADDED, type, currentNew.getName()));
if (newRulesIterator.hasNext()) {
currentNew = newRulesIterator.next();
} else {
break;
}
}
}
while (oldRulesIterator.hasNext()) {
changeSet.getChanges().add(new ResourceChange(ChangeType.REMOVED, type, oldRulesIterator.next().getName()));
}
while (newRulesIterator.hasNext()) {
changeSet.getChanges().add(new ResourceChange(ChangeType.ADDED, type, newRulesIterator.next().getName()));
}
}
Aggregations