changeset 7816:607e673d8907

RT-38382: [Tab] Regression caused by bad hashCode in Tab class
author jgiles
date Fri, 22 Aug 2014 11:13:58 +1200
parents 7e5530151aee
children fb4402463363
files modules/controls/src/main/java/javafx/scene/control/Tab.java modules/controls/src/test/java/javafx/scene/control/TabPaneTest.java
diffstat 2 files changed, 44 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/control/Tab.java	Fri Aug 22 10:25:53 2014 +1200
+++ b/modules/controls/src/main/java/javafx/scene/control/Tab.java	Fri Aug 22 11:13:58 2014 +1200
@@ -842,49 +842,6 @@
     }
 
 
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-
-        Tab tab = (Tab) o;
-
-        Node thisContent = getContent();
-        Node otherContent = tab.getContent();
-        if (thisContent != null ? !thisContent.equals(otherContent) : otherContent != null)
-            return false;
-
-        Node thisGraphic = getGraphic();
-        Node otherGraphic = tab.getGraphic();
-        if (thisGraphic != null ? !thisGraphic.equals(otherGraphic) : otherGraphic != null)
-            return false;
-
-        if (isSelected() != tab.isSelected())
-            return false;
-
-        TabPane thisTabPane = getTabPane();
-        TabPane otherTabPane = tab.getTabPane();
-        if (thisTabPane != null ? !thisTabPane.equals(otherTabPane) : otherTabPane != null)
-            return false;
-
-        String thisText = getText();
-        String otherText = tab.getText();
-        if (thisText != null ? !thisText.equals(otherText) : otherText != null)
-            return false;
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int result = isSelected() ? 1 : 0;
-        result = 31 * result + (getTabPane() != null ? getTabPane().hashCode() : 0);
-        result = 31 * result + (getText() != null ? getText().hashCode() : 0);
-        result = 31 * result + (getGraphic() != null ? getGraphic().hashCode() : 0);
-        result = 31 * result + (getContent() != null ? getContent().hashCode() : 0);
-        return result;
-    }
-
     /***************************************************************************
      *                                                                         *
      * Stylesheet Handling                                                     *
--- a/modules/controls/src/test/java/javafx/scene/control/TabPaneTest.java	Fri Aug 22 10:25:53 2014 +1200
+++ b/modules/controls/src/test/java/javafx/scene/control/TabPaneTest.java	Fri Aug 22 11:13:58 2014 +1200
@@ -70,6 +70,12 @@
 import com.sun.javafx.scene.input.KeyCodeMap;
 import com.sun.javafx.tk.Toolkit;
 
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
 public class TabPaneTest {
     private TabPane tabPane;//Empty string
     private Toolkit tk;
@@ -979,4 +985,42 @@
         disabled.setDisable(false);
         assertFalse(btn.isDisabled());
     }
+
+    @Test public void test_rt_38382_noAddToTabPane() {
+        test_rt_38382(false);
+    }
+
+    @Test public void test_rt_38382_addToTabPane() {
+        test_rt_38382(true);
+    }
+
+    public void test_rt_38382(boolean addToTabPane) {
+        final List<String> names = Arrays.asList(
+                "Biomass",
+                "Exploitable Population Biomass",
+                "MSY",
+                "Yield",
+                "Recruitment",
+                "Catch",
+                "Effort");
+        final Map<Tab, List<String>> fooMap = new HashMap<>();
+        final List<Tab> tabList = new LinkedList<>();
+        for (String name : names) {
+            final Tab tab = new Tab();
+            tab.setText(name);
+            fooMap.put(tab, new LinkedList<>());
+            tabList.add(tab);
+        }
+        TabPane tabPane = new TabPane();
+
+        if (addToTabPane) {
+            tabPane.getTabs().setAll(tabList);
+        }
+
+        fooMap.entrySet().forEach(entry -> {
+            final Tab tab = entry.getKey();
+            assertTrue(tabList.contains(tab));
+            assertTrue(fooMap.containsKey(tab));
+        });
+    }
 }