From 3dd9b0a2b62156b51e1e7f03ae7b892f52315112 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 12 Jan 2015 19:39:18 +0100 Subject: [PATCH] DATAMONGO-1136 - Polishing. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Polished equals(…) / hashCode() methods in GeoCommand. Original pull request: #263. --- .../data/mongodb/core/query/GeoCommand.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/GeoCommand.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/GeoCommand.java index 651846570..66e3b89a3 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/GeoCommand.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/GeoCommand.java @@ -15,13 +15,14 @@ */ package org.springframework.data.mongodb.core.query; +import static org.springframework.util.ObjectUtils.*; + import org.springframework.data.geo.Box; import org.springframework.data.geo.Circle; import org.springframework.data.geo.Polygon; import org.springframework.data.geo.Shape; import org.springframework.data.mongodb.core.geo.Sphere; import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; /** * Wrapper around a {@link Shape} to allow appropriate query rendering. @@ -30,7 +31,7 @@ import org.springframework.util.ObjectUtils; * @author Christoph Strobl * @since 1.5 */ -public class GeoCommand { +public final class GeoCommand { private final Shape shape; private final String command; @@ -91,9 +92,12 @@ public class GeoCommand { */ @Override public int hashCode() { - int result = 0; - result += ObjectUtils.nullSafeHashCode(this.command); - result += ObjectUtils.nullSafeHashCode(this.shape); + + int result = 31; + + result += 17 * nullSafeHashCode(this.command); + result += 17 * nullSafeHashCode(this.shape); + return result; } @@ -107,18 +111,13 @@ public class GeoCommand { if (this == obj) { return true; } - if (obj == null) { - return false; - } + if (!(obj instanceof GeoCommand)) { return false; } GeoCommand that = (GeoCommand) obj; - if (!ObjectUtils.nullSafeEquals(this.command, that.command)) { - return false; - } - return ObjectUtils.nullSafeEquals(this.shape, that.shape); - } + return nullSafeEquals(this.command, that.command) && nullSafeEquals(this.shape, that.shape); + } }