Skip to content
Browse files

JAVA-744: Added MongoClientOptions equals and hashCode methods

  • Loading branch information...
1 parent a65a4de commit 0d3b964020e9d2bddda70b6ce5f928c5bf19900a @jyemin jyemin committed Feb 27, 2013
Showing with 57 additions and 0 deletions.
  1. +48 −0 src/main/com/mongodb/MongoClientOptions.java
  2. +9 −0 src/test/com/mongodb/MongoClientOptionsTest.java
View
48 src/main/com/mongodb/MongoClientOptions.java
@@ -511,7 +511,55 @@ public boolean isAlwaysUseMBeans() {
return alwaysUseMBeans;
}
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ final MongoClientOptions that = (MongoClientOptions) o;
+
+ if (alwaysUseMBeans != that.alwaysUseMBeans) return false;
+ if (autoConnectRetry != that.autoConnectRetry) return false;
+ if (connectTimeout != that.connectTimeout) return false;
+ if (connectionsPerHost != that.connectionsPerHost) return false;
+ if (cursorFinalizerEnabled != that.cursorFinalizerEnabled) return false;
+ if (maxAutoConnectRetryTime != that.maxAutoConnectRetryTime) return false;
+ if (maxWaitTime != that.maxWaitTime) return false;
+ if (socketKeepAlive != that.socketKeepAlive) return false;
+ if (socketTimeout != that.socketTimeout) return false;
+ if (threadsAllowedToBlockForConnectionMultiplier != that.threadsAllowedToBlockForConnectionMultiplier)
+ return false;
+ if (!dbDecoderFactory.equals(that.dbDecoderFactory)) return false;
+ if (!dbEncoderFactory.equals(that.dbEncoderFactory)) return false;
+ if (description != null ? !description.equals(that.description) : that.description != null) return false;
+ if (!readPreference.equals(that.readPreference)) return false;
+ // Compare SocketFactory Class, since some equivalent SocketFactory instances are not equal to each other
+ if (!socketFactory.getClass().equals(that.socketFactory.getClass())) return false;
+ if (!writeConcern.equals(that.writeConcern)) return false;
+
+ return true;
+ }
+ @Override
+ public int hashCode() {
+ int result = description != null ? description.hashCode() : 0;
+ result = 31 * result + connectionsPerHost;
+ result = 31 * result + threadsAllowedToBlockForConnectionMultiplier;
+ result = 31 * result + maxWaitTime;
+ result = 31 * result + connectTimeout;
+ result = 31 * result + socketTimeout;
+ result = 31 * result + (socketKeepAlive ? 1 : 0);
+ result = 31 * result + (autoConnectRetry ? 1 : 0);
+ result = 31 * result + (int) (maxAutoConnectRetryTime ^ (maxAutoConnectRetryTime >>> 32));
+ result = 31 * result + readPreference.hashCode();
+ result = 31 * result + dbDecoderFactory.hashCode();
+ result = 31 * result + dbEncoderFactory.hashCode();
+ result = 31 * result + writeConcern.hashCode();
+ result = 31 * result + socketFactory.hashCode();
+ result = 31 * result + (cursorFinalizerEnabled ? 1 : 0);
+ result = 31 * result + (alwaysUseMBeans ? 1 : 0);
+ return result;
+ }
private MongoClientOptions(final Builder builder) {
description = builder.description;
View
9 src/test/com/mongodb/MongoClientOptionsTest.java
@@ -160,4 +160,13 @@ public DBDecoder create() {
public void testStaticBuilderCreate() {
Assert.assertNotNull(MongoClientOptions.builder());
}
+
+ @Test
+ public void testEqualsAndHashCode() {
+ Assert.assertEquals(MongoClientOptions.builder().build(), MongoClientOptions.builder().build());
+ Assert.assertEquals(MongoClientOptions.builder().build().hashCode(), MongoClientOptions.builder().build().hashCode());
+
+ Assert.assertEquals(MongoClientOptions.builder().socketFactory(SSLSocketFactory.getDefault()).build(),
+ MongoClientOptions.builder().socketFactory(SSLSocketFactory.getDefault()).build());
+ }
}

0 comments on commit 0d3b964

Please sign in to comment.
Something went wrong with that request. Please try again.