From d25c09f219d953db08dc3f7fc24ee0089fae3231 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Wed, 15 Oct 2014 09:09:38 +0100 Subject: [PATCH] Use Apace Commons EqualsBuilder and HashCodeBuilder --- .../themoviedbapi/model/AbstractIdName.java | 28 ++++----- .../themoviedbapi/model/AlternativeTitle.java | 29 ++++----- .../omertron/themoviedbapi/model/Artwork.java | 53 +++++++---------- .../themoviedbapi/model/Collection.java | 45 ++++++-------- .../themoviedbapi/model/Language.java | 29 ++++----- .../omertron/themoviedbapi/model/MovieDb.java | 35 +++++------ .../omertron/themoviedbapi/model/Person.java | 59 ++++++++----------- .../themoviedbapi/model/PersonCast.java | 47 ++++++--------- .../themoviedbapi/model/PersonCrew.java | 43 ++++++-------- .../model/ProductionCountry.java | 29 ++++----- .../themoviedbapi/model/ReleaseInfo.java | 35 +++++------ .../omertron/themoviedbapi/model/Trailer.java | 38 ++++++------ .../themoviedbapi/model/Translation.java | 35 +++++------ 13 files changed, 215 insertions(+), 290 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/model/AbstractIdName.java b/src/main/java/com/omertron/themoviedbapi/model/AbstractIdName.java index 7da96057a..c4c745f5a 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/AbstractIdName.java +++ b/src/main/java/com/omertron/themoviedbapi/model/AbstractIdName.java @@ -6,6 +6,8 @@ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** * @@ -40,25 +42,23 @@ public class AbstractIdName extends AbstractJsonMapping { } @Override - public boolean equals(Object obj) { - if (obj == null) { + public boolean equals(final Object obj) { + if (obj instanceof AbstractIdName) { + final AbstractIdName other = (AbstractIdName) obj; + return new EqualsBuilder() + .append(name, other.name) + .append(id, other.id) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final AbstractIdName other = (AbstractIdName) obj; - if (this.id != other.id) { - return false; - } - return !(this.name == null ? other.name != null : !this.name.equals(other.name)); } @Override public int hashCode() { - int hash = 5; - hash = 37 * hash + this.id; - hash = 37 * hash + (this.name != null ? this.name.hashCode() : 0); - return hash; + return new HashCodeBuilder() + .append(id) + .append(name) + .toHashCode(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/AlternativeTitle.java b/src/main/java/com/omertron/themoviedbapi/model/AlternativeTitle.java index 14eb3c984..ed5027631 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/AlternativeTitle.java +++ b/src/main/java/com/omertron/themoviedbapi/model/AlternativeTitle.java @@ -21,6 +21,8 @@ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonProperty; import java.io.Serializable; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** * @author Stuart @@ -59,27 +61,22 @@ public class AlternativeTitle implements Serializable { @Override public boolean equals(Object obj) { - if (obj == null) { + if (obj instanceof AlternativeTitle) { + final AlternativeTitle other = (AlternativeTitle) obj; + return new EqualsBuilder() + .append(country, other.country) + .append(title, other.title) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final AlternativeTitle other = (AlternativeTitle) obj; - if (this.country == null ? other.country != null : !this.country.equals(other.country)) { - return false; - } - if (this.title == null ? other.title != null : !this.title.equals(other.title)) { - return false; - } - return true; } @Override public int hashCode() { - int hash = 7; - hash = 89 * hash + (this.country != null ? this.country.hashCode() : 0); - hash = 89 * hash + (this.title != null ? this.title.hashCode() : 0); - return hash; + return new HashCodeBuilder() + .append(country) + .append(title) + .toHashCode(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/Artwork.java b/src/main/java/com/omertron/themoviedbapi/model/Artwork.java index 519342604..18f63e773 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Artwork.java +++ b/src/main/java/com/omertron/themoviedbapi/model/Artwork.java @@ -20,6 +20,8 @@ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** * The artwork type information @@ -132,43 +134,30 @@ public class Artwork extends AbstractJsonMapping { @Override public boolean equals(Object obj) { - if (obj == null) { + if (obj instanceof Artwork) { + final Artwork other = (Artwork) obj; + return new EqualsBuilder() + .append(aspectRatio, other.aspectRatio) + .append(filePath, other.filePath) + .append(language, other.language) + .append(height, other.height) + .append(width, other.width) + .append(artworkType, other.artworkType) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final Artwork other = (Artwork) obj; - if (Float.floatToIntBits(this.aspectRatio) != Float.floatToIntBits(other.aspectRatio)) { - return false; - } - if (this.filePath == null ? other.filePath != null : !this.filePath.equals(other.filePath)) { - return false; - } - if (this.height != other.height) { - return false; - } - if (this.language == null ? other.language != null : !this.language.equals(other.language)) { - return false; - } - if (this.width != other.width) { - return false; - } - if (this.artworkType != other.artworkType) { - return false; - } - return true; } @Override public int hashCode() { - int hash = 3; - hash = 71 * hash + Float.floatToIntBits(this.aspectRatio); - hash = 71 * hash + (this.filePath != null ? this.filePath.hashCode() : 0); - hash = 71 * hash + this.height; - hash = 71 * hash + (this.language != null ? this.language.hashCode() : 0); - hash = 71 * hash + this.width; - hash = 71 * hash + (this.artworkType != null ? this.artworkType.hashCode() : 0); - return hash; + return new HashCodeBuilder() + .append(aspectRatio) + .append(filePath) + .append(height) + .append(width) + .append(language) + .append(artworkType) + .toHashCode(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/Collection.java b/src/main/java/com/omertron/themoviedbapi/model/Collection.java index 4bdefa61b..cf69b4585 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Collection.java +++ b/src/main/java/com/omertron/themoviedbapi/model/Collection.java @@ -22,6 +22,8 @@ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** * @author stuart.boston @@ -103,37 +105,28 @@ public class Collection extends AbstractJsonMapping { @Override public boolean equals(Object obj) { - if (obj == null) { + if (obj instanceof Collection) { + final Collection other = (Collection) obj; + return new EqualsBuilder() + .append(id, other.id) + .append(name, other.name) + .append(title, other.title) + .append(backdropPath, other.backdropPath) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final Collection other = (Collection) obj; - if (this.backdropPath == null ? other.backdropPath != null : !this.backdropPath.equals(other.backdropPath)) { - return false; - } - if (this.id != other.id) { - return false; - } - if (this.title == null ? other.title != null : !this.title.equals(other.title)) { - return false; - } - if (this.name == null ? other.name != null : !this.name.equals(other.name)) { - return false; - } - return true; } @Override public int hashCode() { - int hash = 7; - hash = 19 * hash + (this.backdropPath != null ? this.backdropPath.hashCode() : 0); - hash = 19 * hash + this.id; - hash = 19 * hash + (this.title != null ? this.title.hashCode() : 0); - hash = 19 * hash + (this.name != null ? this.name.hashCode() : 0); - hash = 19 * hash + (this.posterPath != null ? this.posterPath.hashCode() : 0); - hash = 19 * hash + (this.releaseDate != null ? this.releaseDate.hashCode() : 0); - return hash; + return new HashCodeBuilder() + .append(id) + .append(backdropPath) + .append(title) + .append(name) + .append(posterPath) + .append(releaseDate) + .toHashCode(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/Language.java b/src/main/java/com/omertron/themoviedbapi/model/Language.java index 9a6289ef5..fc129eef3 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Language.java +++ b/src/main/java/com/omertron/themoviedbapi/model/Language.java @@ -21,6 +21,8 @@ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** * @author stuart.boston @@ -55,27 +57,22 @@ public class Language extends AbstractJsonMapping { @Override public boolean equals(Object obj) { - if (obj == null) { + if (obj instanceof Language) { + final Language other = (Language) obj; + return new EqualsBuilder() + .append(isoCode, other.isoCode) + .append(name, other.name) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final Language other = (Language) obj; - if (this.isoCode == null ? other.isoCode != null : !this.isoCode.equals(other.isoCode)) { - return false; - } - if (this.name == null ? other.name != null : !this.name.equals(other.name)) { - return false; - } - return true; } @Override public int hashCode() { - int hash = 7; - hash = 71 * hash + (this.isoCode != null ? this.isoCode.hashCode() : 0); - hash = 71 * hash + (this.name != null ? this.name.hashCode() : 0); - return hash; + return new HashCodeBuilder() + .append(isoCode) + .append(name) + .toHashCode(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java index f15fb29ac..4ee7e5b02 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java @@ -31,6 +31,8 @@ import com.omertron.themoviedbapi.wrapper.WrapperReviews; import com.omertron.themoviedbapi.wrapper.WrapperTrailers; import com.omertron.themoviedbapi.wrapper.WrapperTranslations; import java.util.List; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** * Movie Bean @@ -397,32 +399,25 @@ public class MovieDb extends AbstractJsonMapping { // @Override public boolean equals(Object obj) { - if (obj == null) { + if (obj instanceof MovieDb) { + final MovieDb other = (MovieDb) obj; + return new EqualsBuilder() + .append(id, other.id) + .append(imdbID, other.imdbID) + .append(runtime, other.runtime) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final MovieDb other = (MovieDb) obj; - if (this.id != other.id) { - return false; - } - if (this.imdbID == null ? other.imdbID != null : !this.imdbID.equals(other.imdbID)) { - return false; - } - if (this.runtime != other.runtime) { - return false; - } - return true; } @Override public int hashCode() { - int hash = 5; - hash = 89 * hash + this.id; - hash = 89 * hash + (this.imdbID != null ? this.imdbID.hashCode() : 0); - hash = 89 * hash + this.runtime; - return hash; + return new HashCodeBuilder() + .append(id) + .append(imdbID) + .append(runtime) + .toHashCode(); } // } diff --git a/src/main/java/com/omertron/themoviedbapi/model/Person.java b/src/main/java/com/omertron/themoviedbapi/model/Person.java index 342f148fd..6ad67e2fb 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Person.java +++ b/src/main/java/com/omertron/themoviedbapi/model/Person.java @@ -23,6 +23,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** * @author stuart.boston @@ -263,47 +265,32 @@ public class Person extends AbstractJsonMapping { @Override public boolean equals(Object obj) { - if (obj == null) { + if (obj instanceof Person) { + final Person other = (Person) obj; + return new EqualsBuilder() + .append(id, other.id) + .append(name, other.name) + .append(profilePath, other.profilePath) + .append(personType, other.personType) + .append(department, other.department) + .append(job, other.job) + .append(character, other.character) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final Person other = (Person) obj; - if (this.id != other.id) { - return false; - } - if (this.name == null ? other.name != null : !this.name.equals(other.name)) { - return false; - } - if (this.profilePath == null ? other.profilePath != null : !this.profilePath.equals(other.profilePath)) { - return false; - } - if (this.personType != other.personType) { - return false; - } - if (this.department == null ? other.department != null : !this.department.equals(other.department)) { - return false; - } - if (this.job == null ? other.job != null : !this.job.equals(other.job)) { - return false; - } - if (this.character == null ? other.character != null : !this.character.equals(other.character)) { - return false; - } - return true; } @Override public int hashCode() { - int hash = 3; - hash = 37 * hash + this.id; - hash = 37 * hash + (this.name != null ? this.name.hashCode() : 0); - hash = 37 * hash + (this.profilePath != null ? this.profilePath.hashCode() : 0); - hash = 37 * hash + (this.personType != null ? this.personType.hashCode() : 0); - hash = 37 * hash + (this.department != null ? this.department.hashCode() : 0); - hash = 37 * hash + (this.job != null ? this.job.hashCode() : 0); - hash = 37 * hash + (this.character != null ? this.character.hashCode() : 0); - return hash; + return new HashCodeBuilder() + .append(id) + .append(name) + .append(profilePath) + .append(personType) + .append(department) + .append(job) + .append(character) + .toHashCode(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/PersonCast.java b/src/main/java/com/omertron/themoviedbapi/model/PersonCast.java index d60a565f2..5d0a0ac08 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/PersonCast.java +++ b/src/main/java/com/omertron/themoviedbapi/model/PersonCast.java @@ -21,6 +21,8 @@ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** * @author Stuart @@ -105,39 +107,28 @@ public class PersonCast extends AbstractJsonMapping { @Override public boolean equals(Object obj) { - if (obj == null) { + if (obj instanceof PersonCast) { + final PersonCast other = (PersonCast) obj; + return new EqualsBuilder() + .append(id, other.id) + .append(name, other.name) + .append(character, other.character) + .append(order, other.order) + .append(profilePath, other.profilePath) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final PersonCast other = (PersonCast) obj; - if (this.id != other.id) { - return false; - } - if (this.character == null ? other.character != null : !this.character.equals(other.character)) { - return false; - } - if (this.name == null ? other.name != null : !this.name.equals(other.name)) { - return false; - } - if (this.order != other.order) { - return false; - } - if (this.profilePath == null ? other.profilePath != null : !this.profilePath.equals(other.profilePath)) { - return false; - } - return true; } @Override public int hashCode() { - int hash = 7; - hash = 41 * hash + this.id; - hash = 41 * hash + (this.character != null ? this.character.hashCode() : 0); - hash = 41 * hash + (this.name != null ? this.name.hashCode() : 0); - hash = 41 * hash + this.order; - hash = 41 * hash + (this.profilePath != null ? this.profilePath.hashCode() : 0); - return hash; + return new HashCodeBuilder() + .append(id) + .append(character) + .append(name) + .append(order) + .append(profilePath) + .toHashCode(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/PersonCrew.java b/src/main/java/com/omertron/themoviedbapi/model/PersonCrew.java index 7ab62872a..87b5c573a 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/PersonCrew.java +++ b/src/main/java/com/omertron/themoviedbapi/model/PersonCrew.java @@ -21,6 +21,8 @@ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** * @author Stuart @@ -95,36 +97,27 @@ public class PersonCrew extends AbstractJsonMapping { @Override public boolean equals(Object obj) { - if (obj == null) { + if (obj instanceof PersonCrew) { + final PersonCrew other = (PersonCrew) obj; + return new EqualsBuilder() + .append(id, other.id) + .append(name, other.name) + .append(department, other.department) + .append(job, other.job) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final PersonCrew other = (PersonCrew) obj; - if (this.id != other.id) { - return false; - } - if (this.department == null ? other.department != null : !this.department.equals(other.department)) { - return false; - } - if (this.job == null ? other.job != null : !this.job.equals(other.job)) { - return false; - } - if (this.name == null ? other.name != null : !this.name.equals(other.name)) { - return false; - } - return true; } @Override public int hashCode() { - int hash = 7; - hash = 59 * hash + this.id; - hash = 59 * hash + (this.department != null ? this.department.hashCode() : 0); - hash = 59 * hash + (this.job != null ? this.job.hashCode() : 0); - hash = 59 * hash + (this.name != null ? this.name.hashCode() : 0); - hash = 59 * hash + (this.profilePath != null ? this.profilePath.hashCode() : 0); - return hash; + return new HashCodeBuilder() + .append(id) + .append(department) + .append(job) + .append(name) + .append(profilePath) + .toHashCode(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/ProductionCountry.java b/src/main/java/com/omertron/themoviedbapi/model/ProductionCountry.java index e36a5f91d..7b8b0358b 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/ProductionCountry.java +++ b/src/main/java/com/omertron/themoviedbapi/model/ProductionCountry.java @@ -21,6 +21,8 @@ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** * @author stuart.boston @@ -56,27 +58,22 @@ public class ProductionCountry extends AbstractJsonMapping { @Override public boolean equals(Object obj) { - if (obj == null) { + if (obj instanceof ProductionCountry) { + final ProductionCountry other = (ProductionCountry) obj; + return new EqualsBuilder() + .append(name, other.name) + .append(isoCode, other.isoCode) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final ProductionCountry other = (ProductionCountry) obj; - if (this.isoCode == null ? other.isoCode != null : !this.isoCode.equals(other.isoCode)) { - return false; - } - if (this.name == null ? other.name != null : !this.name.equals(other.name)) { - return false; - } - return true; } @Override public int hashCode() { - int hash = 7; - hash = 47 * hash + (this.isoCode != null ? this.isoCode.hashCode() : 0); - hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0); - return hash; + return new HashCodeBuilder() + .append(isoCode) + .append(name) + .toHashCode(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/ReleaseInfo.java b/src/main/java/com/omertron/themoviedbapi/model/ReleaseInfo.java index 95246b8f0..08a602b79 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/ReleaseInfo.java +++ b/src/main/java/com/omertron/themoviedbapi/model/ReleaseInfo.java @@ -20,6 +20,8 @@ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** * @author Stuart @@ -64,31 +66,24 @@ public class ReleaseInfo extends AbstractJsonMapping { @Override public boolean equals(Object obj) { - if (obj == null) { + if (obj instanceof ReleaseInfo) { + final ReleaseInfo other = (ReleaseInfo) obj; + return new EqualsBuilder() + .append(country, other.country) + .append(certification, other.certification) + .append(releaseDate, other.releaseDate) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final ReleaseInfo other = (ReleaseInfo) obj; - if (this.country == null ? other.country != null : !this.country.equals(other.country)) { - return false; - } - if (this.certification == null ? other.certification != null : !this.certification.equals(other.certification)) { - return false; - } - if (this.releaseDate == null ? other.releaseDate != null : !this.releaseDate.equals(other.releaseDate)) { - return false; - } - return true; } @Override public int hashCode() { - int hash = 3; - hash = 89 * hash + (this.country != null ? this.country.hashCode() : 0); - hash = 89 * hash + (this.certification != null ? this.certification.hashCode() : 0); - hash = 89 * hash + (this.releaseDate != null ? this.releaseDate.hashCode() : 0); - return hash; + return new HashCodeBuilder() + .append(country) + .append(certification) + .append(releaseDate) + .toHashCode(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/Trailer.java b/src/main/java/com/omertron/themoviedbapi/model/Trailer.java index 680c0f830..f6a420978 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Trailer.java +++ b/src/main/java/com/omertron/themoviedbapi/model/Trailer.java @@ -19,6 +19,9 @@ */ package com.omertron.themoviedbapi.model; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + /** * @author Stuart */ @@ -83,32 +86,25 @@ public class Trailer extends AbstractJsonMapping { @Override public boolean equals(Object obj) { - if (obj == null) { + if (obj instanceof Trailer) { + final Trailer other = (Trailer) obj; + return new EqualsBuilder() + .append(name, other.name) + .append(size, other.size) + .append(source, other.source) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final Trailer other = (Trailer) obj; - if (this.name == null ? other.name != null : !this.name.equals(other.name)) { - return false; - } - if (this.size == null ? other.size != null : !this.size.equals(other.size)) { - return false; - } - if (this.source == null ? other.source != null : !this.source.equals(other.source)) { - return false; - } - return true; } @Override public int hashCode() { - int hash = 7; - hash = 61 * hash + (this.name != null ? this.name.hashCode() : 0); - hash = 61 * hash + (this.size != null ? this.size.hashCode() : 0); - hash = 61 * hash + (this.source != null ? this.source.hashCode() : 0); - hash = 61 * hash + (this.website != null ? this.website.hashCode() : 0); - return hash; + return new HashCodeBuilder() + .append(name) + .append(size) + .append(source) + .append(website) + .toHashCode(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/Translation.java b/src/main/java/com/omertron/themoviedbapi/model/Translation.java index aad473cc7..6ba152ebe 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Translation.java +++ b/src/main/java/com/omertron/themoviedbapi/model/Translation.java @@ -20,6 +20,8 @@ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -66,32 +68,25 @@ public class Translation extends AbstractJsonMapping { @Override public boolean equals(Object obj) { - if (obj == null) { + if (obj instanceof Translation) { + final Translation other = (Translation) obj; + return new EqualsBuilder() + .append(name, other.name) + .append(englishName, other.englishName) + .append(isoCode, other.isoCode) + .isEquals(); + } else { return false; } - if (getClass() != obj.getClass()) { - return false; - } - final Translation other = (Translation) obj; - if (this.englishName == null ? other.englishName != null : !this.englishName.equals(other.englishName)) { - return false; - } - if (this.isoCode == null ? other.isoCode != null : !this.isoCode.equals(other.isoCode)) { - return false; - } - if (this.name == null ? other.name != null : !this.name.equals(other.name)) { - return false; - } - return true; } @Override public int hashCode() { - int hash = 3; - hash = 29 * hash + (this.englishName != null ? this.englishName.hashCode() : 0); - hash = 29 * hash + (this.isoCode != null ? this.isoCode.hashCode() : 0); - hash = 29 * hash + (this.name != null ? this.name.hashCode() : 0); - return hash; + return new HashCodeBuilder() + .append(englishName) + .append(isoCode) + .append(name) + .toHashCode(); } @Override