MaxChangeSet implements CrdtAddRemoveSet<ElementType, Set<ElementType>, MaxChangeSet<ElementType>> { @Override public MaxChangeSet<ElementType> merge(MaxChangeSet<ElementType> other){ return new MaxChangeSet<>(this, other); } MaxChangeSet(); @SafeVarargs  MaxChangeSet(ElementType... elements);  MaxChangeSet(Set<ElementType> set);  MaxChangeSet(MaxChangeSet<ElementType> first, MaxChangeSet<ElementType> second);   MaxChangeSet(Map<ElementType, Integer> struct); MaxChangeSet<ElementType> add(ElementType e); MaxChangeSet<ElementType> remove(ElementType e); @Override MaxChangeSet<ElementType> merge(MaxChangeSet<ElementType> other); @Override Set<ElementType> value(); @Override MaxChangeSet<ElementType> optimize(); @Override boolean equals(Object obj);  }
@Test public void mergeTest(){ MaxChangeSet<Integer> set1 = new MaxChangeSet<Integer>().add(1); MaxChangeSet<Integer> set2 = new MaxChangeSet<Integer>().add(1).remove(1); Assert.assertEquals(set1.merge(set2), new MaxChangeSet<Integer>()); set1 = set1.add(1).add(1).add(1); Assert.assertEquals(set1.merge(set2), new MaxChangeSet<Integer>()); set1 = set1.remove(1).add(1); Assert.assertEquals(set1.merge(set2), new MaxChangeSet<>(1)); set2 = set2.remove(1).remove(1).remove(1); Assert.assertEquals(set1.merge(set2), new MaxChangeSet<>(1)); }