Guava equals, hashCode and toString generator

Compatible with IntelliJ IDEA
Apr 11, 2014
10 623
Generates equals and hashCode, as well as toString, utilising the Guava libraries
ALT+INSERT : equals & hashCode and toString options will be shown.

Given a class with the following fields:
private int field1;
private String field2;
private long field3;

The following methods would be generated:

@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    TestHarness that = (TestHarness) o;

    return Objects.equal(this.field1, that.field1) &&
            Objects.equal(this.field2, that.field2) &&
            Objects.equal(this.field3, that.field3);
}

@Override
public int hashCode() {
    return Objects.hashCode(field1, field2, field3);
}

@Override
public String toString() {
    return Objects.toStringHelper(this)
            .add("field1", field1)
            .add("field2", field2)
            .add("field3", field3)
            .toString();
}

Download plugin