DESCRIPTION

Bug 254570 - StructuredSelection should implement hashCode()

Change-Id: I39de2f9155e052a2823e96625d593382f3a553d2
Signed-off-by: Cash Galloway xxx@xxx.xxx


COMMENTS

author: Brenden Conley
date: 2017-01-09 08:51:56.000000000

Patch Set 10:

Build Started https://hudson.eclipse.org/platform/job/eclipse.platform.ui-Gerrit/11629/

-------------------------------------
author: Brenden Conley
date: 2017-01-09 09:19:11.000000000

Patch Set 10: Code-Review-1

Build Unstable 

https://hudson.eclipse.org/platform/job/eclipse.platform.ui-Gerrit/11629/ : UNSTABLE

-------------------------------------
author: Ryker Bauer
date: 2017-01-09 11:39:55.000000000

Patch Set 10:

(4 comments)

Line:64, bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeSelection.java -> Adding a comment explain this block of code will improve readability.

Line:28, tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/viewers/StructuredSelectionTest.java -> Improve readability by adding a comment.

Line:40, tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/viewers/StructuredSelectionTest.java -> Improve readability by adding a comment.

Line:162, bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredSelection.java -> if isEmpty() and comparer==null, this will return the hash code of a null Object.
- Is this the intended behavior?
- Perhaps we could use getClass().hashCode() instead?

-------------------------------------
author: Rayan Moreno
date: 2017-01-09 12:11:00.000000000

Patch Set 10:

(4 comments)

Line:64, bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeSelection.java -> Done

Line:28, tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/viewers/StructuredSelectionTest.java -> Done

Line:40, tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/viewers/StructuredSelectionTest.java -> Done

Line:162, bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredSelection.java -> Yes it is the intended behavior. I don't see the value to use getClass().hashCode() instead. Please elaborate why you think it should be replaced.

However, I see that I've used Objects.hash instead of Objects.hashCode() (the later takes an object while the former an array). While it does not change the behavior, it creates an array for nothing. Will change that in an upcoming review

-------------------------------------
author: Ryker Bauer
date: 2017-01-09 12:24:37.000000000

Patch Set 10:

(1 comment)

Mikael, thanks for your efforts!

Line:162, bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredSelection.java -> The only drawback I see is that in the "empty & null case", the StructuredSelection will return the same hash code as a generic null object. 
Hence, I was thinking, this might cause problems in comparisons because often, objects with the same hashcode are seen as equals.

-------------------------------------
author: Rayan Moreno
date: 2017-01-09 13:19:51.000000000

Patch Set 10:

(1 comment)

Line:162, bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredSelection.java -> No, hashCode is not designed to be used for comparison; equals() is. hashCode() is designed to facilitate the creation of hash based data structure. 

Having the same hash - aka a hash collision - as a "generic null object" (whatever this means) is, IMO, not an issue. The most visible trouble you get from hash collisions is decreasing performance with hash based data structures (like HashMap). 

But I can't see a use case where you will create a HashMap with keys of both StructuredSelections and other instance types (excl. subtypes). This would be the only case where your proposal would improve the performance of the underlying HashMap - no collision between  StructuredSelection instances with hashCode == 0 and other type of instances with hashCode == 0). And even if you do end up with such a case, the performance will decrease if you have *a lot* of empty structured selections / "generic null object"... 

If you really want it, I will make the change, but I think it will only make the code harder to read for no sensible Leon Ochoaefit.

-------------------------------------
author: Ryker Bauer
date: 2017-01-09 13:25:27.000000000

Patch Set 10:

(1 comment)

I see you point, and I agree with you now.

Line:162, bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredSelection.java -> Done

-------------------------------------
author: Gerrit Code Review
date: 2017-01-09 16:03:40.000000000

Change has been successfully merged into the git repository by Ryker Bauer

-------------------------------------
