Browse Source

DATAMONGO-1136 - Polishing.

Polished equals(…) / hashCode() methods in GeoCommand.

Original pull request: #263.
pull/265/head
Oliver Gierke 11 years ago
parent
commit
3dd9b0a2b6
  1. 25
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/GeoCommand.java

25
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; package org.springframework.data.mongodb.core.query;
import static org.springframework.util.ObjectUtils.*;
import org.springframework.data.geo.Box; import org.springframework.data.geo.Box;
import org.springframework.data.geo.Circle; import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Polygon; import org.springframework.data.geo.Polygon;
import org.springframework.data.geo.Shape; import org.springframework.data.geo.Shape;
import org.springframework.data.mongodb.core.geo.Sphere; import org.springframework.data.mongodb.core.geo.Sphere;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/** /**
* Wrapper around a {@link Shape} to allow appropriate query rendering. * Wrapper around a {@link Shape} to allow appropriate query rendering.
@ -30,7 +31,7 @@ import org.springframework.util.ObjectUtils;
* @author Christoph Strobl * @author Christoph Strobl
* @since 1.5 * @since 1.5
*/ */
public class GeoCommand { public final class GeoCommand {
private final Shape shape; private final Shape shape;
private final String command; private final String command;
@ -91,9 +92,12 @@ public class GeoCommand {
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
int result = 0;
result += ObjectUtils.nullSafeHashCode(this.command); int result = 31;
result += ObjectUtils.nullSafeHashCode(this.shape);
result += 17 * nullSafeHashCode(this.command);
result += 17 * nullSafeHashCode(this.shape);
return result; return result;
} }
@ -107,18 +111,13 @@ public class GeoCommand {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj == null) {
return false;
}
if (!(obj instanceof GeoCommand)) { if (!(obj instanceof GeoCommand)) {
return false; return false;
} }
GeoCommand that = (GeoCommand) obj; 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);
}
} }

Loading…
Cancel
Save