class 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()) {
          // Only remove the actual elements that were removed from the list
          // Otherwise all instances of an element would be removed, which is not the desired behavior
          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();

}