You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2017/12/18 06:17:12 UTC
[3/3] james-project git commit: JAMES-2259 SearchKey should match
bean contract
JAMES-2259 SearchKey should match bean contract
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/1695b0a2
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1695b0a2
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1695b0a2
Branch: refs/heads/master
Commit: 1695b0a2a75161fa043f8158c7bc71d22a4d3c6f
Parents: a795945
Author: benwa <bt...@linagora.com>
Authored: Fri Dec 15 10:46:08 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Dec 18 13:16:21 2017 +0700
----------------------------------------------------------------------
.../imap/api/message/request/SearchKey.java | 75 ++++++--------------
.../imap/api/message/request/SearchKeyTest.java | 32 +++++++++
2 files changed, 54 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/1695b0a2/protocols/imap/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java
index 374efba..810817a 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/request/SearchKey.java
@@ -22,6 +22,7 @@ package org.apache.james.imap.api.message.request;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Objects;
import java.util.Optional;
import org.apache.james.imap.api.message.IdRange;
@@ -455,62 +456,30 @@ public final class SearchKey {
public long getModSeq() {
return modSeq;
}
- /**
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + ((date == null) ? 0 : date.hashCode());
- result = PRIME * result + ((name == null) ? 0 : name.hashCode());
- if (sequence != null) {
- result = PRIME * result + sequence.length;
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof SearchKey) {
+ SearchKey searchKey = (SearchKey) o;
+
+ return Objects.equals(this.type, searchKey.type)
+ && Objects.equals(this.size, searchKey.size)
+ && Objects.equals(this.seconds, searchKey.seconds)
+ && Objects.equals(this.modSeq, searchKey.modSeq)
+ && Objects.equals(this.date, searchKey.date)
+ && Objects.equals(this.keys, searchKey.keys)
+ && Objects.equals(this.name, searchKey.name)
+ && Objects.equals(this.value, searchKey.value)
+ && Arrays.equals(this.sequence, searchKey.sequence)
+ && Arrays.equals(this.uids, searchKey.uids);
}
- result = PRIME * result + (int) (size ^ (size >>> 32));
- result = PRIME * result + ((keys == null) ? 0 : keys.hashCode());
- result = PRIME * result + type;
- result = PRIME * result + ((value == null) ? 0 : value.hashCode());
- return result;
+ return false;
}
- /**
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- final SearchKey other = (SearchKey) obj;
- if (date == null) {
- if (other.date != null)
- return false;
- } else if (!date.equals(other.date))
- return false;
- if (name == null) {
- if (other.name != null)
- return false;
- } else if (!name.equals(other.name))
- return false;
- if (!Arrays.equals(sequence, other.sequence))
- return false;
- if (size != other.size)
- return false;
- if (keys == null) {
- if (other.keys != null)
- return false;
- } else if (!keys.equals(other.keys))
- return false;
- if (type != other.type)
- return false;
- if (value == null) {
- if (other.value != null)
- return false;
- } else if (!value.equals(other.value))
- return false;
- return true;
+ @Override
+ public final int hashCode() {
+ return Objects.hash(type, date, keys, size, name, value,
+ Arrays.hashCode(sequence), Arrays.hashCode(uids), seconds, modSeq);
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/1695b0a2/protocols/imap/src/test/java/org/apache/james/imap/api/message/request/SearchKeyTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/api/message/request/SearchKeyTest.java b/protocols/imap/src/test/java/org/apache/james/imap/api/message/request/SearchKeyTest.java
new file mode 100644
index 0000000..6ea9da7
--- /dev/null
+++ b/protocols/imap/src/test/java/org/apache/james/imap/api/message/request/SearchKeyTest.java
@@ -0,0 +1,32 @@
+/****************************************************************
+ * 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.james.imap.api.message.request;
+
+import org.junit.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class SearchKeyTest {
+ @Test
+ public void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(SearchKey.class)
+ .verify();
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org