PropertyUtils { public static <T> ObservableList<T> combineLists(ObservableList<T> first, ObservableList<T> second) { ObservableList<T> combine = FXCollections.observableArrayList(); ListChangeListener<? super T> listener = c -> { while (c.next()) { if (c.wasAdded()) { combine.addAll(c.getAddedSubList()); } else if (c.wasRemoved()) { c.getRemoved().forEach(e -> combine.removeIf(t -> e == t)); } } }; combine.addAll(first); combine.addAll(second); first.addListener(listener); second.addListener(listener); return combine; } private  PropertyUtils(); static void bindBidirectionalWithConverter(
      Property<T> sourceProperty,
      Property<U> bindingTarget,
      Function<? super T, ? extends U> t2uConverter,
      Function<? super U, ? extends T> u2tConverter); static void bindWithConverter(
      Property<T> firstProperty,
      Property<U> secondProperty,
      Function<U, T> u2tConverter); static void bindToMapBidirectionally(Property<T> property,
                                                                  ObservableMap<K, V> map,
                                                                  K key,
                                                                  Function<V, T> v2t); static ObservableList<T> combineLists(ObservableList<T> first, ObservableList<T> second);  }
@Test @SuppressWarnings("LocalVariableName") public void testCombineLists() { ObservableList<String> a = FXCollections.observableArrayList("a"); ObservableList<String> b = FXCollections.observableArrayList("b"); ObservableList<String> combine = PropertyUtils.combineLists(a, b); assertEquals(2, combine.size()); assertEquals(a.get(0), combine.get(0)); assertEquals(b.get(0), combine.get(1)); }
@Test @SuppressWarnings("LocalVariableName") public void testCombineListsListeners() { ObservableList<String> a = FXCollections.observableArrayList("a"); ObservableList<String> b = FXCollections.observableArrayList("b"); ObservableList<String> combine = PropertyUtils.combineLists(a, b); a.add("A"); assertEquals(3, combine.size()); b.add("B"); assertEquals(4, combine.size()); assertEquals(a.get(1), combine.get(2)); assertEquals(b.get(1), combine.get(3)); a.clear(); b.clear(); assertEquals(0, combine.size()); }