You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2015/10/07 23:24:05 UTC
[1/2] activemq-artemis git commit: ARTEMIS-151 Considering name as
part of equals and hashCode
Repository: activemq-artemis
Updated Branches:
refs/heads/master c21bee63c -> 9d3866471
ARTEMIS-151 Considering name as part of equals and hashCode
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/33188bb4
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/33188bb4
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/33188bb4
Branch: refs/heads/master
Commit: 33188bb4d9ea72ab6c0e17ce20d8d30ed1286a94
Parents: c21bee6
Author: Clebert Suconic <cl...@apache.org>
Authored: Wed Oct 7 12:38:31 2015 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Wed Oct 7 15:30:50 2015 -0400
----------------------------------------------------------------------
.../api/core/TransportConfiguration.java | 49 ++++++---------
.../api/core/TransportConfigurationTest.java | 64 ++++++++++++++++++++
2 files changed, 81 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/33188bb4/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java
index a1e2531..5dd7eda 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java
@@ -152,47 +152,32 @@ public class TransportConfiguration implements Serializable {
return params;
}
+
@Override
public int hashCode() {
- return factoryClassName.hashCode();
+ int result = name != null ? name.hashCode() : 0;
+ result = 31 * result + factoryClassName.hashCode();
+ result = 31 * result + (params != null ? params.hashCode() : 0);
+ return result;
}
@Override
- public boolean equals(final Object other) {
- if (other instanceof TransportConfiguration == false) {
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
return false;
- }
- TransportConfiguration kother = (TransportConfiguration) other;
+ TransportConfiguration that = (TransportConfiguration) o;
- if (factoryClassName.equals(kother.factoryClassName)) {
- if (params == null || params.isEmpty()) {
- return kother.params == null || kother.params.isEmpty();
- }
- else {
- if (kother.params == null || kother.params.isEmpty()) {
- return false;
- }
- else if (params.size() == kother.params.size()) {
- for (Map.Entry<String, Object> entry : params.entrySet()) {
- Object thisVal = entry.getValue();
-
- Object otherVal = kother.params.get(entry.getKey());
-
- if (otherVal == null || !otherVal.equals(thisVal)) {
- return false;
- }
- }
- return true;
- }
- else {
- return false;
- }
- }
- }
- else {
+ if (!factoryClassName.equals(that.factoryClassName))
return false;
- }
+ if (name != null ? !name.equals(that.name) : that.name != null)
+ return false;
+ if (params != null ? !params.equals(that.params) : that.params != null)
+ return false;
+
+ return true;
}
/**
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/33188bb4/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/TransportConfigurationTest.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/TransportConfigurationTest.java b/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/TransportConfigurationTest.java
new file mode 100644
index 0000000..965036c
--- /dev/null
+++ b/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/TransportConfigurationTest.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.artemis.api.core;
+
+import java.util.HashMap;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TransportConfigurationTest {
+
+ @Test
+ public void testEquals() {
+ TransportConfiguration configuration = new TransportConfiguration("SomeClass", new HashMap<String, Object>(), null);
+ TransportConfiguration configuration2 = new TransportConfiguration("SomeClass", new HashMap<String, Object>(), null);
+
+ Assert.assertEquals(configuration, configuration2);
+ Assert.assertEquals(configuration.hashCode(), configuration2.hashCode());
+
+
+ HashMap<String, Object> configMap1 = new HashMap<>();
+ configMap1.put("host", "localhost");
+ HashMap<String, Object> configMap2 = new HashMap<>();
+ configMap2.put("host", "localhost");
+
+ System.out.println("Equals::" + configMap1.equals(configMap2));
+ configuration = new TransportConfiguration("SomeClass", configMap1, null);
+ configuration2 = new TransportConfiguration("SomeClass", configMap2, null);
+ Assert.assertEquals(configuration, configuration2);
+ Assert.assertEquals(configuration.hashCode(), configuration2.hashCode());
+
+ System.out.println("Equals::" + configMap1.equals(configMap2));
+ configuration = new TransportConfiguration("SomeClass", configMap1, "name1");
+ configuration2 = new TransportConfiguration("SomeClass", configMap2, "name2");
+ Assert.assertNotEquals(configuration, configuration2);
+ Assert.assertNotEquals(configuration.hashCode(), configuration2.hashCode());
+ Assert.assertTrue(configuration.isEquivalent(configuration2));
+
+ configMap1 = new HashMap<>();
+ configMap1.put("host", "localhost");
+ configMap2 = new HashMap<>();
+ configMap2.put("host", "localhost3");
+ configuration = new TransportConfiguration("SomeClass", configMap1, null);
+ configuration2 = new TransportConfiguration("SomeClass", configMap2, null);
+ Assert.assertNotEquals(configuration, configuration2);
+ Assert.assertNotEquals(configuration.hashCode(), configuration2.hashCode());
+
+ }
+}
[2/2] activemq-artemis git commit: This closes #189
Posted by cl...@apache.org.
This closes #189
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/9d386647
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/9d386647
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/9d386647
Branch: refs/heads/master
Commit: 9d3866471bb8d9617a4860de36a80810334f7e23
Parents: c21bee6 33188bb
Author: Clebert Suconic <cl...@apache.org>
Authored: Wed Oct 7 17:23:44 2015 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Wed Oct 7 17:23:44 2015 -0400
----------------------------------------------------------------------
.../api/core/TransportConfiguration.java | 49 ++++++---------
.../api/core/TransportConfigurationTest.java | 64 ++++++++++++++++++++
2 files changed, 81 insertions(+), 32 deletions(-)
----------------------------------------------------------------------