TwoPhaseSet implements CrdtAddRemoveSet<ElementType, Set<ElementType>, TwoPhaseSet<ElementType>> { @Override public TwoPhaseSet<ElementType> merge(TwoPhaseSet<ElementType> other){ return new TwoPhaseSet<>(this, other); } TwoPhaseSet(); @SafeVarargs  TwoPhaseSet(ElementType... elements);  TwoPhaseSet(Set<ElementType> set);  TwoPhaseSet(TwoPhaseSet<ElementType> first, TwoPhaseSet<ElementType> second);   TwoPhaseSet(Set<ElementType> added, Set<ElementType> removed); TwoPhaseSet<ElementType> add(ElementType e); TwoPhaseSet<ElementType> remove(ElementType e); @Override TwoPhaseSet<ElementType> merge(TwoPhaseSet<ElementType> other); @Override Set<ElementType> value(); @Override TwoPhaseSet<ElementType> optimize(); @Override boolean equals(Object obj);  }
@Test public void mergeTest(){ TwoPhaseSet<String> f = new TwoPhaseSet<>(sampleSet); TwoPhaseSet<String> s = new TwoPhaseSet<>("a", "c"); s = s.remove("a"); TwoPhaseSet<String> res = f.merge(s); Assert.assertEquals(res, new TwoPhaseSet<>(f, s)); Assert.assertEquals(res, new TwoPhaseSet<>("b", "c", "d")); }