ObservableMirrors { public static <T> ObservableSet<T> mirrorSet(ObservableSet<T> mirrored, AffinityExecutor runChangesIn) { @SuppressWarnings("unchecked") ObservableSet<T> result = FXCollections.observableSet(); result.addAll(mirrored); mirrored.addListener(new SetMirror<T>(result, runChangesIn)); return FXCollections.unmodifiableObservableSet(result); }  static ObservableList<T> mirrorList(ObservableList<T> mirrored, AffinityExecutor runChangesIn); static ObservableMap<K, V> mirrorMap(ObservableMap<K, V> mirrored, AffinityExecutor runChangesIn); static ObservableSet<T> mirrorSet(ObservableSet<T> mirrored, AffinityExecutor runChangesIn);  }
@Test public void mirroredSet() throws Exception { ObservableSet<String> source = FXCollections.observableSet(); source.add("alpha"); source.add("beta"); ObservableSet<String> dest = ObservableMirrors.mirrorSet(source, gate); assertEquals(0, gate.getTaskQueueSize()); assertEquals(2, dest.size()); source.add("delta"); assertEquals(1, gate.getTaskQueueSize()); assertEquals(2, dest.size()); gate.waitAndRun(); assertEquals(0, gate.getTaskQueueSize()); assertEquals(3, dest.size()); source.removeAll(ImmutableList.of("alpha", "beta")); assertEquals(2, gate.getTaskQueueSize()); gate.waitAndRun(); gate.waitAndRun(); assertEquals(1, dest.size()); assertTrue(dest.contains("delta")); }