From c34d4a1157acbf3c16a8645b3af04fb549247724 Mon Sep 17 00:00:00 2001 From: mstr2 <43553916+mstr2@users.noreply.github.com> Date: Tue, 14 Jan 2025 01:44:52 +0100 Subject: [PATCH 1/2] failing tests --- .../java/test/javafx/scene/ParentTest.java | 18 ++++++++++++++++++ .../Parent_structuralPseudoClasses_Test.java | 2 -- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/javafx.graphics/src/test/java/test/javafx/scene/ParentTest.java b/modules/javafx.graphics/src/test/java/test/javafx/scene/ParentTest.java index 20b157d46bd..1ca39d3b038 100644 --- a/modules/javafx.graphics/src/test/java/test/javafx/scene/ParentTest.java +++ b/modules/javafx.graphics/src/test/java/test/javafx/scene/ParentTest.java @@ -33,6 +33,8 @@ import com.sun.javafx.scene.input.PickResultChooser; import java.util.Collection; +import java.util.Comparator; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import javafx.scene.Group; import javafx.scene.GroupShim; @@ -277,6 +279,22 @@ public void testRemoveAddDiferentChild() { assertEquals(5, ((NGGroup)NodeHelper.getPeer(g)).getChildren().size()); } + @Test + public void testSortChildren() { + Rectangle rect1 = new Rectangle(); + rect1.setId("1"); + Rectangle rect2 = new Rectangle(); + rect2.setId("2"); + Rectangle rect3 = new Rectangle(); + rect3.setId("3"); + + Group g = new Group(); + g.getChildren().addAll(rect3, rect1, rect2); + g.getChildren().sort(Comparator.comparing(node -> node.getId())); + + assertEquals(List.of(rect1, rect2, rect3), g.getChildren()); + } + @Test public void testGetChildrenUnmodifiable() { Rectangle rect1 = new Rectangle(); diff --git a/modules/javafx.graphics/src/test/java/test/javafx/scene/Parent_structuralPseudoClasses_Test.java b/modules/javafx.graphics/src/test/java/test/javafx/scene/Parent_structuralPseudoClasses_Test.java index 897068e118d..ff324296546 100644 --- a/modules/javafx.graphics/src/test/java/test/javafx/scene/Parent_structuralPseudoClasses_Test.java +++ b/modules/javafx.graphics/src/test/java/test/javafx/scene/Parent_structuralPseudoClasses_Test.java @@ -30,7 +30,6 @@ import javafx.css.PseudoClass; import javafx.scene.Group; import javafx.scene.Node; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -212,7 +211,6 @@ void multipleNodes_removeInteriorRange() { } @Test - @Disabled("JDK-8233179") void multipleNodes_permutation() { var group = new Group(); var child1 = new Group(); From 978d2dd2ee1741f3e6d3a2ce567ee7fa128e1032 Mon Sep 17 00:00:00 2001 From: mstr2 <43553916+mstr2@users.noreply.github.com> Date: Tue, 14 Jan 2025 01:45:36 +0100 Subject: [PATCH 2/2] Implement sorting for VetoableListDecorator --- .../collections/VetoableListDecorator.java | 17 ++++++++++++++++- .../collections/VetoableObservableListTest.java | 10 +++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/javafx.base/src/main/java/com/sun/javafx/collections/VetoableListDecorator.java b/modules/javafx.base/src/main/java/com/sun/javafx/collections/VetoableListDecorator.java index 2b73be7bfc3..07d471e2e80 100644 --- a/modules/javafx.base/src/main/java/com/sun/javafx/collections/VetoableListDecorator.java +++ b/modules/javafx.base/src/main/java/com/sun/javafx/collections/VetoableListDecorator.java @@ -29,6 +29,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.List; @@ -39,7 +40,7 @@ import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; -public abstract class VetoableListDecorator implements ObservableList { +public abstract class VetoableListDecorator implements ObservableList, SortableList { private final ObservableList list; private int modCount; @@ -100,6 +101,20 @@ public void removeListener(InvalidationListener listener) { helper = ListListenerHelper.removeListener(helper, listener); } + @Override + public final void doSort(Comparator comparator) { + var sortedList = new ArrayList<>(list); + sortedList.sort(comparator); + onProposedChange(Collections.unmodifiableList(sortedList), 0, size()); + try { + modCount++; + list.setAll(sortedList); + } catch(Exception e) { + modCount--; + throw e; + } + } + @Override public boolean addAll(E... elements) { return addAll(Arrays.asList(elements)); diff --git a/modules/javafx.base/src/test/java/test/javafx/collections/VetoableObservableListTest.java b/modules/javafx.base/src/test/java/test/javafx/collections/VetoableObservableListTest.java index a5026ff1443..1f79e5c44f2 100644 --- a/modules/javafx.base/src/test/java/test/javafx/collections/VetoableObservableListTest.java +++ b/modules/javafx.base/src/test/java/test/javafx/collections/VetoableObservableListTest.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.List; @@ -569,7 +570,14 @@ public void testSubListCreatedOnChangeValid() { assertEquals(1, subLists.size()); subLists.get(0).size(); // Assert not throwing Exception subLists.clear(); - } + @Test + public void testSort() { + list.setAll("d", "b", "a", "c"); + calls.clear(); + list.sort(Comparator.naturalOrder()); + assertEquals(List.of("a", "b", "c", "d"), list); + assertSingleCall(new String[] {"a", "b", "c", "d"}, new int[] {0, 4}); + } }