Fixed VC deserialization and double negations in
CollectionBuilder.Group

Change-Id: Iabfc12324f443a71421fa6f06d3d97dfd58a124b
diff --git a/Changes b/Changes
index 3949571..dbea656 100644
--- a/Changes
+++ b/Changes
@@ -13,6 +13,8 @@
     - [bugfix] Fix wrong behaviour of negative constraints in and-Groups
       of VCs (#42; diewald)
     - [feature] Adding loading namedVC from gz (margaretha)
+    - [bugfix] Fixed VC deserialization and double negations in 
+      CollectionBuilder.group (margaretha)
 
 0.57 2018-04-05
     - [feature] Support text queries in metadata
diff --git a/src/main/java/de/ids_mannheim/korap/KrillCollection.java b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
index ddea3f0..33811a5 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
@@ -241,18 +241,13 @@
                         match = json.get("match").asText();
                     }
 
-                    CollectionBuilder.Group group = null;
-                    if (match.equals("match:eq")) {
-                        group = this.cb.orGroup();
-                        for (JsonNode value : json.get("value")) {
-                            group.with(cb.term(key, value.asText()));
-                        }
+                    CollectionBuilder.Group group = this.cb.orGroup();
+                    for (JsonNode value : json.get("value")) {
+                        group.with(cb.term(key, value.asText()));
                     }
-                    else if (match.equals("match:ne")) {
-                        group = this.cb.andGroup();
-                        for (JsonNode value : json.get("value")) {
-                            group.with(cb.term(key, value.asText()).not());
-                        }
+                    
+                    if (match.equals("match:ne")) {
+                        return group.not();
                     }
                     return group;
                 }
diff --git a/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java b/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java
index f235fe0..3e231bc 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java
@@ -260,14 +260,17 @@
 	
     public class Group implements CollectionBuilder.Interface {
         private boolean isOptional = false;
-        private boolean isNegative = true;
+        private boolean isNegative = false;
 
 
         public boolean isNegative () {
             return this.isNegative;
         };
 
-
+        public void setNegative (boolean isNegative) {
+            this.isNegative = isNegative;
+        }
+        
         public boolean isOptional () {
             return this.isOptional;
         };
@@ -285,8 +288,6 @@
             if (cb == null)
                 return this;
 
-            if (!cb.isNegative())
-                this.isNegative = false;
             this.operands.add(cb);
             return this;
         };
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestCollectionBuilder.java b/src/test/java/de/ids_mannheim/korap/collection/TestCollectionBuilder.java
index c9c7711..213fb86 100644
--- a/src/test/java/de/ids_mannheim/korap/collection/TestCollectionBuilder.java
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestCollectionBuilder.java
@@ -198,10 +198,12 @@
         assertTrue(kbi.isNegative());
 
         kbi = kc.andGroup().with(kc.term("author", "tree").not());
+        kbi.not();
         assertEquals("author:tree", kbi.toString());
         assertTrue(kbi.isNegative());
 
         kbi = kc.orGroup().with(kc.term("author", "tree").not());
+        kbi.not();
         assertEquals("author:tree", kbi.toString());
         assertTrue(kbi.isNegative());
     };