gr.uom.java.xmi.diff.UMLAnnotationListDiff Maven / Gradle / Ivy
package gr.uom.java.xmi.diff;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.tuple.Pair;
import gr.uom.java.xmi.UMLAnnotation;
public class UMLAnnotationListDiff {
private Set removedAnnotations;
private Set addedAnnotations;
private Set annotationDiffs;
private Set> commonAnnotations;
public UMLAnnotationListDiff(List annotations1, List annotations2) {
this.removedAnnotations = new LinkedHashSet();
this.addedAnnotations = new LinkedHashSet();
this.annotationDiffs = new LinkedHashSet();
this.commonAnnotations = new LinkedHashSet>();
Set> matchedAnnotations = new LinkedHashSet>();
for(UMLAnnotation annotation1 : annotations1) {
boolean found = false;
for(UMLAnnotation annotation2 : annotations2) {
if(annotation1.equals(annotation2)) {
matchedAnnotations.add(Pair.of(annotation1, annotation2));
found = true;
break;
}
}
if(!found) {
for(UMLAnnotation annotation2 : annotations2) {
if(annotation1.getTypeName().equals(annotation2.getTypeName())) {
matchedAnnotations.add(Pair.of(annotation1, annotation2));
found = true;
break;
}
}
}
if(!found) {
removedAnnotations.add(annotation1);
}
}
for(UMLAnnotation annotation2 : annotations2) {
boolean found = false;
for(UMLAnnotation annotation1 : annotations1) {
if(annotation1.equals(annotation2)) {
matchedAnnotations.add(Pair.of(annotation1, annotation2));
found = true;
break;
}
}
if(!found) {
for(UMLAnnotation annotation1 : annotations1) {
if(annotation1.getTypeName().equals(annotation2.getTypeName())) {
matchedAnnotations.add(Pair.of(annotation1, annotation2));
found = true;
break;
}
}
}
if(!found) {
addedAnnotations.add(annotation2);
}
}
for(Pair pair : matchedAnnotations) {
UMLAnnotationDiff annotationDiff = new UMLAnnotationDiff(pair.getLeft(), pair.getRight());
if(!annotationDiff.isEmpty() && !annotationDiffs.contains(annotationDiff)) {
annotationDiffs.add(annotationDiff);
}
else if(!commonAnnotations.contains(pair)){
commonAnnotations.add(pair);
}
}
}
public Set getRemovedAnnotations() {
return removedAnnotations;
}
public Set getAddedAnnotations() {
return addedAnnotations;
}
public Set getAnnotationDiffs() {
return annotationDiffs;
}
public Set> getCommonAnnotations() {
return commonAnnotations;
}
public boolean isEmpty() {
return removedAnnotations.isEmpty() && addedAnnotations.isEmpty() && annotationDiffs.isEmpty();
}
}