TwoPhaseSet implements CrdtAddRemoveSet<ElementType, Set<ElementType>, TwoPhaseSet<ElementType>> { @Override public TwoPhaseSet<ElementType> optimize(){ return new TwoPhaseSet<>(value(), removed); } 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 optimizeTest(){ TwoPhaseSet<String> set = new TwoPhaseSet<>(sampleSet); set = set.remove("b"); Assert.assertEquals(set.optimize(), set); Assert.assertTrue(set.optimize().getAdded().size() < set.getAdded().size()); }