From 4154ef5bf6de5eb69bbb5d29f382bfb8df2ab773 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 30 Dec 2015 07:56:33 +0200 Subject: Make GeneratedPropertyItem equals self (#19426) Change-Id: Ieccb53a402dd6669fb684b0ef8e18e4c8778c58e --- .../data/util/GeneratedPropertyContainer.java | 33 ++++++++++++++++++++++ .../util/GeneratedPropertyContainerBasicTest.java | 3 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/server/src/com/vaadin/data/util/GeneratedPropertyContainer.java b/server/src/com/vaadin/data/util/GeneratedPropertyContainer.java index f50ff01fc6..cea1e27ee9 100644 --- a/server/src/com/vaadin/data/util/GeneratedPropertyContainer.java +++ b/server/src/com/vaadin/data/util/GeneratedPropertyContainer.java @@ -165,6 +165,39 @@ public class GeneratedPropertyContainer extends AbstractContainer implements throw new UnsupportedOperationException( "GeneratedPropertyItem does not support removing properties"); } + + /** + * Tests if the given object is the same as the this object. Two Items + * from the same container with the same ID are equal. + * + * @param obj + * an object to compare with this object + * @return true if the given object is the same as this + * object, false if not + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj == null + || !obj.getClass().equals(GeneratedPropertyItem.class)) { + return false; + } + final GeneratedPropertyItem li = (GeneratedPropertyItem) obj; + return getContainer() == li.getContainer() + && itemId.equals(li.itemId); + } + + @Override + public int hashCode() { + return itemId.hashCode(); + } + + private GeneratedPropertyContainer getContainer() { + return GeneratedPropertyContainer.this; + } }; /** diff --git a/server/tests/src/com/vaadin/data/util/GeneratedPropertyContainerBasicTest.java b/server/tests/src/com/vaadin/data/util/GeneratedPropertyContainerBasicTest.java index b9c2a0ab22..90ec893f4d 100644 --- a/server/tests/src/com/vaadin/data/util/GeneratedPropertyContainerBasicTest.java +++ b/server/tests/src/com/vaadin/data/util/GeneratedPropertyContainerBasicTest.java @@ -38,8 +38,7 @@ public class GeneratedPropertyContainerBasicTest extends } public void testContainerOrdered() { - // Fails because of #19246 - // testContainerOrdered(createContainer()); + testContainerOrdered(createContainer()); } public void testContainerIndexed() { -- cgit v1.2.3