Bug 500330 - equals generation with additional option
Summary: equals generation with additional option
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.7   Edit
Hardware: PC All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-26 08:48 EDT by Fernando Boaglio CLA
Modified: 2016-08-26 15:37 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fernando Boaglio CLA 2016-08-26 08:48:53 EDT

    
Comment 1 Fernando Boaglio CLA 2016-08-26 08:56:26 EDT
I would like to have an option in equals generation to consider empty Lists or Hashs the same thing as null lists/hashs. 

Equals example (for a "tags" List) today:

if (tags == null) {
 if (other.tags != null) { return false; }
} else if (!tags.equals(other.tags)) { return false; }

Equals example (for a "tags" List) with consider [empty list] == [null list] option enabled:

if ( (other.tags == null || other.tags.size() == 0) && (tags == null || tags.size() == 0)) {
return true;
} else if (tags == null || tags.size() == 0) {
if (other.tags != null || other.tags.size() > 0) { return false; }
} else if (!tags.equals(other.tags)) { return false; }


Thank you.
Comment 2 Stephan Herrmann CLA 2016-08-26 11:39:03 EDT
I personally am not sure, that's a coding style that JDT wants to actively support. Wouldn't consistently using empty lists instead of null make for much simpler and safer code?
Comment 3 Fernando Boaglio CLA 2016-08-26 15:37:47 EDT
You are right, but these objects come from ReST services and sometimes they are null or empty.
From the business point of view, it is the same thing; that´s why I ask for this feature.