Created
June 24, 2012 03:31
-
-
Save typekpb/2981380 to your computer and use it in GitHub Desktop.
Comparison to Lombok
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// eclipse generated methods way | |
public class Schedule implements Serializable { | |
... | |
@Override | |
public int hashCode() { | |
final int prime = 31; | |
int result = 1; | |
result = prime * result + ((bgImage == null) ? 0 : bgImage.hashCode()); | |
result = prime * result + (blank ? 1231 : 1237); | |
result = prime * result + (clear ? 1231 : 1237); | |
result = prime * result + (live ? 1231 : 1237); | |
result = prime * result + ((name == null) ? 0 : name.hashCode()); | |
result = prime * result | |
+ ((presentations == null) ? 0 : presentations.hashCode()); | |
return result; | |
} | |
@Override | |
public boolean equals(Object obj) { | |
if (this == obj) | |
return true; | |
if (obj == null) | |
return false; | |
if (getClass() != obj.getClass()) | |
return false; | |
Schedule other = (Schedule) obj; | |
if (bgImage == null) { | |
if (other.bgImage != null) | |
return false; | |
} else if (!bgImage.equals(other.bgImage)) | |
return false; | |
if (blank != other.blank) | |
return false; | |
if (clear != other.clear) | |
return false; | |
if (live != other.live) | |
return false; | |
if (name == null) { | |
if (other.name != null) | |
return false; | |
} else if (!name.equals(other.name)) | |
return false; | |
if (presentations == null) { | |
if (other.presentations != null) | |
return false; | |
} else if (!presentations.equals(other.presentations)) | |
return false; | |
return true; | |
} | |
@Override | |
public String toString() { | |
return "Schedule [presentations=" + presentations + ", bgImage=" | |
+ bgImage + ", name=" + name + ", blank=" + blank + ", clear=" | |
+ clear + ", live=" + live + "]"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lombok way | |
@ToString | |
@EqualsAndHashCode | |
public class Schedule implements Serializable { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// manual way using Equals/ToString/HashCode Builders | |
public class Schedule implements Serializable { | |
... | |
@Override | |
public int hashCode() { | |
return new HashCodeBuilder() | |
.append(this.getPresentations()) | |
.append(this.getBgImage()) | |
.append(this.getName()) | |
.append(this.isBlank()) | |
.append(this.isClear()) | |
.append(this.isLive()) | |
.toHashCode(); | |
} | |
@Override | |
public boolean equals(Object obj) { | |
if ( !(obj instanceof Schedule) ) return false; | |
Schedule castOther = (Schedule) obj; | |
return new EqualsBuilder() | |
.append(this.getPresentations(), castOther.getPresentations()) | |
.append(this.getBgImage(), castOther.getBgImage()) | |
.append(this.getName(), castOther.getName()) | |
.append(this.isBlank(), castOther.isBlank()) | |
.append(this.isClear(), castOther.isClear()) | |
.append(this.isLive(), castOther.isLive()) | |
.isEquals(); | |
} | |
@Override | |
public String toString() { | |
return new ToStringBuilder(this) | |
.append("\n presentations", this.getPresentations()) | |
.append("\n bgImage", this.getBgImage()) | |
.append("\n name", this.getName()) | |
.append("\n blank", this.isBlank()) | |
.append("\n clear", this.isClear()) | |
.append("\n live", this.isLive()) | |
.append("\n") | |
.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment