Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MappedBackedList handling of wasUpdated changes #87

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/tobiasdiez/easybind/MappedBackedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ protected void sourceChanged(ListChangeListener.Change<? extends F> change) {
}
nextPermutation(from, to, permutation);
} else if (change.wasUpdated()) {
backingList.set(change.getFrom(), mapper.apply(getSource().get(change.getFrom())));
nextUpdate(change.getFrom());
E old = backingList.set(change.getFrom(), mapper.apply(getSource().get(change.getFrom())));
nextSet(change.getFrom(), old);
} else {
if (change.wasRemoved()) {
int removePosition = change.getFrom();
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/com/tobiasdiez/easybind/MappedBackedListTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.tobiasdiez.easybind;

import javafx.beans.Observable;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.SortedList;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MappedBackedListTest {

@Test
public void testSortedListUpdatesWithMappedBackedList() {
ObservableList<IntegerProperty> list = FXCollections.observableArrayList(number -> new Observable[]{number});
ObservableList<Integer> mappedList = EasyBind.mapBacked(list, IntegerProperty::get);
SortedList<Integer> sortedList = new SortedList<>(mappedList);

IntegerProperty number = new SimpleIntegerProperty(1);
list.add(number);

assertEquals(1, sortedList.get(0));

number.set(2);

assertEquals(2, sortedList.get(0));
}
}