This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 66321

Summary: Create toString, equals, hashCode according to Class fields
Product: editor Reporter: sleepgod001 <sleepgod001>
Component: RefactoringAssignee: issues@java <issues>
Status: RESOLVED DUPLICATE    
Severity: blocker    
Priority: P1    
Version: 5.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description sleepgod001 2005-10-09 07:54:27 UTC
Hi,

You can refer to issue 60745.

What do you say if you can create the functionality like this.


  public int hashCode() { 
    int hash = 1;
    hash = hash * 31 + someNonNullField.hashCode();
    hash = hash * 31 
                + (someOtherField == null ? 0 : someOtherField.hashCode());
    return hash;
  }

You iterator all not-trasient members and generate the code, there have some
rules i believe you know as well. I list them here just for the safe side.

Calculate hashcode for data type
long, calculate (int)f ^ (f >>> 32)) 
float, Float.floatToIntBits(f) 
double, Double.doubleToLongBits(f)
Object, if is null, =0, or return its own hashCode()


Same thing to equals() and toString().

It would be a great help if you can apply it.

Thanks
Comment 1 rptmaestro 2006-06-26 15:41:21 UTC
Here is a look at what the competition provides in this area:

http://www.eclipsezone.com/eclipse/forums/t64643.html?start=0
Comment 2 Jan Becicka 2007-04-18 19:25:46 UTC

*** This issue has been marked as a duplicate of 60745 ***