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 2020/04/03 10:27:42 UTC

[james-project] 06/08: [Refactoring] simplify Collections operator where possible

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 55b4e8caab47e72c857c655850c4e4038201ce4d
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Wed Mar 25 12:08:32 2020 +0100

    [Refactoring] simplify Collections operator where possible
---
 .../james/mailbox/elasticsearch/search/ElasticSearchSearcher.java | 2 +-
 .../java/org/apache/james/mailbox/store/LazyMimeDescriptor.java   | 2 +-
 .../main/java/org/apache/james/blob/mail/MimeMessagePartsId.java  | 4 ++--
 .../java/org/apache/james/smtpserver/fastfail/URIScanner.java     | 8 ++------
 4 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
index dc84cf9..85cceb1 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
@@ -140,7 +140,7 @@ public class ElasticSearchSearcher {
     }
 
     private Optional<DocumentField> retrieveMessageIdField(SearchHit hit) {
-        if (hit.getFields().keySet().contains(JsonMessageConstants.MESSAGE_ID)) {
+        if (hit.getFields().containsKey(JsonMessageConstants.MESSAGE_ID)) {
             return Optional.ofNullable(hit.field(JsonMessageConstants.MESSAGE_ID));
         }
         return Optional.empty();
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/LazyMimeDescriptor.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/LazyMimeDescriptor.java
index aad4f90..f4fc8c4 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/LazyMimeDescriptor.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/LazyMimeDescriptor.java
@@ -136,7 +136,7 @@ public class LazyMimeDescriptor implements MimeDescriptor {
 
     @Override
     public Iterator<MimeDescriptor> parts() {
-        return Collections.<MimeDescriptor>emptyList().iterator();
+        return Collections.emptyIterator();
     }
 
     @Override
diff --git a/server/blob/mail-store/src/main/java/org/apache/james/blob/mail/MimeMessagePartsId.java b/server/blob/mail-store/src/main/java/org/apache/james/blob/mail/MimeMessagePartsId.java
index 5981be8..936efe5 100644
--- a/server/blob/mail-store/src/main/java/org/apache/james/blob/mail/MimeMessagePartsId.java
+++ b/server/blob/mail-store/src/main/java/org/apache/james/blob/mail/MimeMessagePartsId.java
@@ -64,8 +64,8 @@ public class MimeMessagePartsId implements BlobPartsId {
     public static class Factory implements BlobPartsId.Factory<MimeMessagePartsId> {
         @Override
         public MimeMessagePartsId generate(Map<BlobType, BlobId> map) {
-            Preconditions.checkArgument(map.keySet().contains(HEADER_BLOB_TYPE), "Expecting 'mailHeader' blobId to be specified");
-            Preconditions.checkArgument(map.keySet().contains(BODY_BLOB_TYPE), "Expecting 'mailBody' blobId to be specified");
+            Preconditions.checkArgument(map.containsKey(HEADER_BLOB_TYPE), "Expecting 'mailHeader' blobId to be specified");
+            Preconditions.checkArgument(map.containsKey(BODY_BLOB_TYPE), "Expecting 'mailBody' blobId to be specified");
             Preconditions.checkArgument(map.size() == 2, "blobId other than 'mailHeader' or 'mailBody' are not supported");
 
             return builder()
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIScanner.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIScanner.java
index e0464b5..e4b9c5e 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIScanner.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIScanner.java
@@ -241,9 +241,7 @@ public class URIScanner {
             String host = hostFromUriStr(found);
             if (null != host) {
                 host = host.toLowerCase(Locale.US);
-                if (!set.contains(host)) {
-                    set.add(host);
-                }
+                set.add(host);
             }
         }
 
@@ -259,9 +257,7 @@ public class URIScanner {
             if (null != host) {
 
                 host = host.toLowerCase(Locale.US);
-                if (!set.contains(host)) {
-                    set.add(host);
-                }
+                set.add(host);
             }
         }
         return set;


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org