Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion org.jiayun.commons4e/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-Name: Commons4E
Bundle-SymbolicName: org.jiayun.commons4e; singleton=true
Bundle-Version: 1.1.11
Bundle-Version: 1.1.11.f1
Bundle-ClassPath: commons4e.jar
Bundle-Activator: org.jiayun.commons4e.Commons4ePlugin
Bundle-Vendor: JiaYun
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,39 @@ private String createEqualsMethod(final IType objectClass,
content.append("@Override\n");
}
content.append("public boolean equals(final Object other) {\n");
content.append("if (other == null) return false;\n");
if (compareReferences) {
content.append("if (this == other) return true;");
}
content.append("if ( !(other instanceof ");
content.append(objectClass.getElementName());
content.append(") ) return false;\n");
content.append(objectClass.getElementName());
content.append(" castOther = (");
content.append(objectClass.getElementName());
content.append(") other;\n");
// by definition a.equals(b) == b.equals(a) (symmetric), using instanceOf can't assure this
// example:
// class A {
// int field1;
// public A(int x) { field1 = x };
// }
// class B extends A {
// int field2;
// public A(int x, int y) { super(x); field2 = y };
// }
// ...
// A a = new A(1)
// B b = new B(1, 2);
// a.equals(b); // true
// b.equals(a); // false
//
// from jdk javadoc for equals:
// (equals) It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.

// content.append("if ( !(other instanceof ");
// content.append(objectClass.getElementName());
// content.append(") ) return false;\n");
content.append("if (!(other.getClass() == this.getClass())) return false;\n");

content.append(objectClass.getElementName());
content.append(" castOther = (");
content.append(objectClass.getElementName());
content.append(") other;\n");

content.append("return new EqualsBuilder()");
if (appendSuper) {
content.append(".appendSuper(super.equals(other))");
Expand Down