james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [01/18] james-project git commit: JAMES-2107 Run IntelliJ inspection: "Move from imperative to Stream API"
Date Wed, 16 Aug 2017 09:45:34 GMT
Repository: james-project
Updated Branches:
  refs/heads/master f40ce327c -> 34d63025e


http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/SieveMailAdapter.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/SieveMailAdapter.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/SieveMailAdapter.java
index 749504b..1e8b56f 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/SieveMailAdapter.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/SieveMailAdapter.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 
 import javax.mail.Header;
@@ -332,13 +333,12 @@ public class SieveMailAdapter implements MailAdapter, EnvelopeAccessors,
ActionC
      */
     public String getEnvelopeTo()
     {
-        for (MailAddress mailAddress : getMail().getRecipients()) {
-            String recipient = mailAddress.toInternetAddress().getAddress();
-            if (recipient != null) {
-                return recipient;
-            }
-        }
-        return null;
+        return getMail().getRecipients()
+            .stream()
+            .map(mailAddress -> mailAddress.toInternetAddress().getAddress())
+            .filter(Objects::nonNull)
+            .findFirst()
+            .orElse(null);
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AddressExtractor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AddressExtractor.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AddressExtractor.java
index 9b9a97c..85475ee 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AddressExtractor.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AddressExtractor.java
@@ -175,11 +175,7 @@ public class AddressExtractor {
     }
 
     private boolean isAllowed(String addressString, List<String> allowedSpecials) {
-        for (String allowedSpecial : allowedSpecials) {
-            if (addressString.equals(allowedSpecial.toLowerCase(Locale.US).trim())) {
-                return true;
-            }
-        }
-        return false;
+        return allowedSpecials.stream()
+            .anyMatch(allowedSpecial -> addressString.equals(allowedSpecial.toLowerCase(Locale.US).trim()));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/SpecialAddressKind.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/SpecialAddressKind.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/SpecialAddressKind.java
index 30ed518..5d00dc3 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/SpecialAddressKind.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/SpecialAddressKind.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.transport.mailets.redirect;
 
+import java.util.Arrays;
+
 public enum SpecialAddressKind {
     SENDER("sender"),
     REVERSE_PATH("reverse.path"),
@@ -37,12 +39,10 @@ public enum SpecialAddressKind {
     }
 
     public static SpecialAddressKind forValue(String value) {
-        for (SpecialAddressKind kind : values()) {
-            if (kind.value.equals(value)) {
-                return kind;
-            }
-        }
-        return null;
+        return Arrays.stream(values())
+            .filter(kind -> kind.value.equals(value))
+            .findFirst()
+            .orElse(null);
     }
 
     public String getValue() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/DelaysAndMaxRetry.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/DelaysAndMaxRetry.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/DelaysAndMaxRetry.java
index 16ae192..fd7e043 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/DelaysAndMaxRetry.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/DelaysAndMaxRetry.java
@@ -97,11 +97,9 @@ public class DelaysAndMaxRetry {
     }
 
     private static int computeTotalAttempts(List<Delay> delayList) {
-        int sum = 0;
-        for (Delay delay : delayList) {
-            sum += delay.getAttempts();
-        }
-        return sum;
+        return delayList.stream()
+            .mapToInt(Delay::getAttempts)
+            .sum();
     }
 
     private final int maxRetries;

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfiguration.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfiguration.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfiguration.java
index 221df2a..58173f2 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfiguration.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfiguration.java
@@ -23,12 +23,14 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Properties;
 
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.james.domainlist.api.DomainList;
 import org.apache.mailet.MailetConfig;
 import org.apache.mailet.base.MailetUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Optional;
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
@@ -123,11 +125,12 @@ public class RemoteDeliveryConfiguration {
     private Properties computeJavaxProperties(MailetConfig mailetConfig) {
         Properties result = new Properties();
         // deal with <mail.*> attributes, passing them to javamail
-        for (String propertyName : ImmutableList.copyOf(mailetConfig.getInitParameterNames()))
{
-            if (propertyName.startsWith(JAVAX_PREFIX)) {
-                result.put(propertyName, mailetConfig.getInitParameter(propertyName));
-            }
-        }
+        result.putAll(
+            ImmutableList.copyOf(mailetConfig.getInitParameterNames())
+                .stream()
+                .filter(propertyName -> propertyName.startsWith(JAVAX_PREFIX))
+                .map(propertyName -> Pair.of(propertyName, mailetConfig.getInitParameter(propertyName)))
+                .collect(Guavate.toImmutableMap(Pair::getKey, Pair::getValue)));
         return result;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java
b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java
index 6dfad6c..c491586 100644
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java
@@ -18,6 +18,10 @@
  ****************************************************************/
 package org.apache.james.protocols.lib;
 
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.Collectors;
+
 import org.apache.commons.configuration.CombinedConfiguration;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.ConfigurationUtils;
@@ -30,9 +34,6 @@ import org.apache.james.protocols.api.handler.WiringException;
 import org.apache.james.protocols.lib.handler.HandlersPackage;
 import org.apache.james.protocols.lib.handler.ProtocolHandlerLoader;
 
-import java.util.LinkedList;
-import java.util.List;
-
 public class ProtocolHandlerChainImpl implements ProtocolHandlerChain {
 
     private final ProtocolHandlerLoader loader;
@@ -137,15 +138,10 @@ public class ProtocolHandlerChainImpl implements ProtocolHandlerChain
{
     @SuppressWarnings("unchecked")
     @Override
     public <T> LinkedList<T> getHandlers(Class<T> type) {
-        LinkedList<T> hList = new LinkedList<T>();
-
-        for (Object h : handlers) {
-            if (type.isInstance(h)) {
-                hList.add((T) h);
-
-            }
-        }
-        return hList;
+        return handlers.stream()
+            .filter(type::isInstance)
+            .map(h -> (T) h)
+            .collect(Collectors.toCollection(LinkedList::new));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
index 75ce1c1..321628e 100644
--- a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
+++ b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
@@ -21,6 +21,7 @@ package org.apache.james.pop3server.mailbox;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -40,6 +41,8 @@ import org.apache.james.mailbox.model.MessageResult.FetchGroup;
 import org.apache.james.protocols.pop3.mailbox.Mailbox;
 import org.apache.james.protocols.pop3.mailbox.MessageMetaData;
 
+import com.github.steveash.guavate.Guavate;
+
 public class MailboxAdapter implements Mailbox {
 
     private static abstract class POP3FetchGroup implements FetchGroup {
@@ -167,11 +170,9 @@ public class MailboxAdapter implements Mailbox {
 
     @Override
     public void remove(String... uids) throws IOException {
-        List<MessageUid> uidList = new ArrayList<MessageUid>();
-
-        for (String uid : uids) {
-            uidList.add(MessageUid.of(Long.valueOf(uid)));
-        }
+        List<MessageUid> uidList = Arrays.stream(uids)
+            .map(uid -> MessageUid.of(Long.valueOf(uid)))
+            .collect(Guavate.toImmutableList());
 
         List<MessageRange> ranges = MessageRange.toRanges(uidList);
         try {

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIScanner.java
----------------------------------------------------------------------
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 a71e29f..01e1100 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
@@ -23,8 +23,10 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.HashSet;
 import java.util.Locale;
+import java.util.Objects;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
 import org.apache.james.smtpserver.TLDLookup;
 
@@ -186,18 +188,12 @@ public class URIScanner {
      * @return newDomains the domains which were extracted
      */
     static public HashSet<String> scanContentForDomains(HashSet<String> domains,
CharSequence content) {
-        HashSet<String> newDomains = new HashSet<String>();
         HashSet<String> hosts = scanContentForHosts(content);
-        for (String host : hosts) {
-            final String domain = domainFromHost(host);
-
-            if (null != domain) {
-                if (!domains.contains(domain)) {
-                    newDomains.add(domain);
-                }
-            }
-        }
-        return newDomains;
+        return hosts.stream()
+            .map(URIScanner::domainFromHost)
+            .filter(Objects::nonNull)
+            .filter(domain -> !domains.contains(domain))
+            .collect(Collectors.toCollection(HashSet::new));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java
b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java
index f97c287..62e35b3 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java
@@ -19,7 +19,7 @@
 package org.apache.james.smtpserver.fastfail;
 
 import java.net.UnknownHostException;
-import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 
@@ -41,6 +41,8 @@ import org.apache.james.protocols.smtp.hook.RcptHook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.steveash.guavate.Guavate;
+
 /**
  * This class can be used to reject email with bogus MX which is send from a
  * authorized user or an authorized network.
@@ -149,10 +151,9 @@ public class ValidRcptMX implements RcptHook, ProtocolHandler {
 
         if (networks.length == 0) {
 
-            Collection<String> bannedNetworks = new ArrayList<String>();
-            for (String network : networks) {
-                bannedNetworks.add(network.trim());
-            }
+            Collection<String> bannedNetworks = Arrays.stream(networks)
+                .map(String::trim)
+                .collect(Guavate.toImmutableList());
 
             setBannedNetworks(bannedNetworks, dnsService);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/mock/MockMimeMessage.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/mock/MockMimeMessage.java
b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/mock/MockMimeMessage.java
index 7c3e9cd..2cd567e 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/mock/MockMimeMessage.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/mock/MockMimeMessage.java
@@ -18,17 +18,34 @@
  ****************************************************************/
 package org.apache.james.smtpserver.mock;
 
-import java.io.*;
-import java.util.*;
-import java.util.Map.Entry;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
 
 import javax.activation.DataHandler;
-import javax.mail.*;
+import javax.mail.Address;
+import javax.mail.Flags;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.Session;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.InternetHeaders;
 import javax.mail.internet.MimeMessage;
 import javax.mail.search.SearchTerm;
 
+import com.github.steveash.guavate.Guavate;
+
 public class MockMimeMessage extends MimeMessage {
 
     private final List<Address> fromAddresses = new ArrayList<Address>();
@@ -446,12 +463,11 @@ public class MockMimeMessage extends MimeMessage {
         return Collections.enumeration(getHeadersAsStrings(contentHeaders));
     }
 
-    private ArrayList<String> getHeadersAsStrings(HashMap<String, String> contentHeaders)
{
-        ArrayList<String> headerLines = new ArrayList<String>();
-        for (Entry<String, String> entry : contentHeaders.entrySet()) {
-            headerLines.add(entry.getKey() + ":" + entry.getValue());
-        }
-        return headerLines;
+    private List<String> getHeadersAsStrings(HashMap<String, String> contentHeaders)
{
+        return contentHeaders.entrySet()
+            .stream()
+            .map(entry -> entry.getKey() + ":" + entry.getValue())
+            .collect(Guavate.toImmutableList());
     }
 
     @Override


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


Mime
View raw message