changeset 7755:7e5530151aee

RT-38382: [Tab] Regression caused by bad hashCode in Tab class (Partial fix as there is no test application available but I'm fairly confident this doesn't fix the entire issue mentioned in RT-38382).
author jgiles
date Fri, 22 Aug 2014 10:25:53 +1200
parents 72e18dfa5a2a
children 607e673d8907
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, 22 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/control/Tab.java	Thu Aug 21 12:46:00 2014 -0700
+++ b/modules/controls/src/main/java/javafx/scene/control/Tab.java	Fri Aug 22 10:25:53 2014 +1200
@@ -849,15 +849,27 @@
 
         Tab tab = (Tab) o;
 
-        if (content != null ? !content.equals(tab.content) : tab.content != null)
+        Node thisContent = getContent();
+        Node otherContent = tab.getContent();
+        if (thisContent != null ? !thisContent.equals(otherContent) : otherContent != null)
             return false;
-        if (graphic != null ? !graphic.equals(tab.graphic) : tab.graphic != null)
+
+        Node thisGraphic = getGraphic();
+        Node otherGraphic = tab.getGraphic();
+        if (thisGraphic != null ? !thisGraphic.equals(otherGraphic) : otherGraphic != null)
             return false;
-        if (selected != null ? !selected.equals(tab.selected) : tab.selected != null)
+
+        if (isSelected() != tab.isSelected())
             return false;
-        if (tabPane != null ? !tabPane.equals(tab.tabPane) : tab.tabPane != null)
+
+        TabPane thisTabPane = getTabPane();
+        TabPane otherTabPane = tab.getTabPane();
+        if (thisTabPane != null ? !thisTabPane.equals(otherTabPane) : otherTabPane != null)
             return false;
-        if (text != null ? !text.equals(tab.text) : tab.text != null)
+
+        String thisText = getText();
+        String otherText = tab.getText();
+        if (thisText != null ? !thisText.equals(otherText) : otherText != null)
             return false;
 
         return true;
@@ -865,11 +877,11 @@
 
     /** {@inheritDoc} */
     @Override public int hashCode() {
-        int result = selected != null ? selected.hashCode() : 0;
-        result = 31 * result + (tabPane != null ? tabPane.hashCode() : 0);
-        result = 31 * result + (text != null ? text.hashCode() : 0);
-        result = 31 * result + (graphic != null ? graphic.hashCode() : 0);
-        result = 31 * result + (content != null ? content.hashCode() : 0);
+        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;
     }
 
--- a/modules/controls/src/test/java/javafx/scene/control/TabPaneTest.java	Thu Aug 21 12:46:00 2014 -0700
+++ b/modules/controls/src/test/java/javafx/scene/control/TabPaneTest.java	Fri Aug 22 10:25:53 2014 +1200
@@ -70,10 +70,6 @@
 import com.sun.javafx.scene.input.KeyCodeMap;
 import com.sun.javafx.tk.Toolkit;
 
-/**
- *
- * @author srikalyc
- */
 public class TabPaneTest {
     private TabPane tabPane;//Empty string
     private Toolkit tk;