GuavaEclipsePlugin / GuavaEclipsePluginParent

"Guava Eclipse Plugin" is an eclipse plugin which will generate following methods using Google guava utility classes or jdk utility classes toString() [STRG + SHIFT + 4] - equals(Object object) & hashCode() [STRG + SHIFT + 5] - compareTo(...) [STRG + SHIFT + 6]
https://guavaeclipseplugin.github.io/
10 stars 4 forks source link

generated equals method for Object Arrays is to much #14

Closed arolfes closed 9 years ago

arolfes commented 9 years ago

when you have a member array variable which is complex, there wrapping into another object array is unnecessary

example:

public class SampleBean {
    private int[][] intValue;

    private String[] strValue;

    @Override
    public int hashCode() {
        return Arrays.deepHashCode(new Object[] { intValue, strValue });
    }

    @Override
    public boolean equals(Object object) {
        if (object != null && getClass() == object.getClass()) {
            SampleBean that = (SampleBean) object;
            return Arrays.deepEquals(new Object[] { this.intValue }, new Object[] { that.intValue })
                    && Arrays.deepEquals(new Object[] { this.strValue }, new Object[] { that.strValue });
        }
        return false;
    }

}

better would be

@Override
public boolean equals(Object object) {
    if (object != null && getClass() == object.getClass()) {
        SampleBean that = (SampleBean) object;
        return Arrays.deepEquals(new Object[] { this.intValue }, new Object[] { that.intValue })
                && Arrays.deepEquals(this.strValue, that.strValue);
    }
    return false;
}