ref #7600 implementing setAnnotations()
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 4 Sep 2018 13:13:56 +0000 (15:13 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 4 Sep 2018 13:14:08 +0000 (15:14 +0200)
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/AnnotatableEntity.java

index f15e7a78ccbb4c688b1e197982c3754c33b78a64..a42e72b185d14cc04cda64d30c689b31912cbf84 100644 (file)
@@ -9,7 +9,9 @@
 
 package eu.etaxonomy.cdm.model.common;
 
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import java.util.UUID;
 
@@ -123,6 +125,25 @@ public abstract class AnnotatableEntity extends VersionableEntity implements IAn
                }
        }
 
+        public void setAnnotations(Set<Annotation> annotations) {
+        List<Annotation> currentAnnotations = new ArrayList<>(annotations);
+        List<Annotation> annotationsSeen = new ArrayList<>();
+        for(Annotation a : annotations){
+            if(a == null){
+                continue;
+            }
+            if(!currentAnnotations.contains(a)){
+                addAnnotation(a);
+            }
+            annotationsSeen.add(a);
+        }
+        for(Annotation a : currentAnnotations){
+            if(!annotationsSeen.contains(a)){
+                removeAnnotation(a);
+            }
+        }
+    }
+
 //********************** CLONE *****************************************/