james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [02/18] james-project git commit: JAMES-2107 Run IntelliJ inspection: "Move from imperative to Stream API"
Date Wed, 16 Aug 2017 09:45:35 GMT
JAMES-2107 Run IntelliJ inspection: "Move from imperative to Stream API"


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/cb0f621f
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/cb0f621f
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/cb0f621f

Branch: refs/heads/master
Commit: cb0f621f74e84d1597c37e929ba4ee61dbdde70c
Parents: 855a3c8
Author: benwa <btellier@linagora.com>
Authored: Tue Aug 1 18:01:11 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Aug 16 16:44:07 2017 +0700

----------------------------------------------------------------------
 .../james/mailbox/model/FetchGroupImpl.java     | 21 +++++-----
 .../mailbox/hbase/mail/HBaseMailboxMessage.java |  6 +--
 .../jcr/mail/model/JCRMailboxMessage.java       |  9 +++--
 .../openjpa/AbstractJPAMailboxMessage.java      |  8 ++--
 .../james/mailbox/maildir/UidConstraint.java    |  6 +--
 .../maildir/user/MaildirSubscriptionMapper.java | 40 ++++++++++----------
 .../inmemory/mail/InMemoryMailboxMapper.java    | 22 +++++------
 .../inmemory/mail/InMemoryMessageMapper.java    | 39 +++++++++----------
 .../user/InMemorySubscriptionMapper.java        | 13 +++----
 mailbox/store/pom.xml                           |  4 ++
 .../mailbox/store/StoreMailboxManager.java      | 13 +++----
 .../mailbox/store/StoreSubscriptionManager.java | 14 +++----
 .../store/json/event/EventConverter.java        | 17 ++++-----
 .../store/mail/model/impl/PropertyBuilder.java  | 27 ++++++-------
 .../mailbox/store/search/MessageSearches.java   | 19 +++-------
 .../org/apache/james/ai/classic/Tokenizer.java  |  9 ++---
 .../base/AutomaticallySentMailDetectorImpl.java |  8 ++--
 .../james/transport/matchers/HasHeader.java     | 26 ++++++-------
 .../apache/james/mpt/helper/ScriptBuilder.java  | 10 ++---
 protocols/api/pom.xml                           |  4 ++
 .../handler/AbstractProtocolHandlerChain.java   | 12 +++---
 .../api/handler/ProtocolHandlerChainImpl.java   |  5 +--
 .../api/AbstractProtocolTransportTest.java      | 29 +++++++-------
 .../apache/james/imap/api/message/UidRange.java |  9 ++---
 .../james/imap/processor/SearchProcessor.java   | 10 +----
 .../processor/fetch/MessageResultUtils.java     | 28 ++++----------
 .../protocols/lmtp/AbstractLMTPSServerTest.java | 11 ++----
 .../protocols/lmtp/AbstractLMTPServerTest.java  | 11 ++----
 protocols/pom.xml                               |  5 +++
 .../pop3/core/MessageMetaDataUtils.java         | 10 ++---
 .../protocols/pop3/mailbox/ImapMailbox.java     |  8 ++--
 .../pop3/AbstractStartTlsPOP3ServerTest.java    | 10 ++---
 .../james/protocols/pop3/utils/MockMailbox.java | 12 +++---
 .../smtp/SMTPProtocolHandlerChain.java          | 14 +------
 .../smtp/netty/NettyStartTlsSMTPServerTest.java | 10 ++---
 .../java/org/apache/james/cli/type/CmdType.java | 11 +++---
 .../james/core/MimeMessageWrapperTest.java      | 20 ++--------
 .../mailbox/MailboxManagerManagement.java       | 10 ++---
 .../james/util/bayesian/BayesianAnalyzer.java   |  9 ++---
 .../file/SieveFileRepository.java               | 10 ++---
 server/data/data-ldap/pom.xml                   |  4 ++
 .../user/ldap/ReadOnlyUsersLDAPRepository.java  | 13 +++----
 server/data/data-library/pom.xml                |  4 ++
 .../domainlist/lib/AbstractDomainList.java      | 33 +++++-----------
 .../repository/file/AbstractFileRepository.java | 13 ++-----
 .../repository/file/ExtensionFileFilter.java    |  8 +---
 server/mailet/mailetcontainer-camel/pom.xml     |  4 ++
 .../lib/AbstractStateMailetProcessor.java       | 18 ++++-----
 .../mailets/jsieve/SieveMailAdapter.java        | 14 +++----
 .../mailets/redirect/AddressExtractor.java      |  8 +---
 .../mailets/redirect/SpecialAddressKind.java    | 12 +++---
 .../remoteDelivery/DelaysAndMaxRetry.java       |  8 ++--
 .../RemoteDeliveryConfiguration.java            | 13 ++++---
 .../protocols/lib/ProtocolHandlerChainImpl.java | 20 ++++------
 .../pop3server/mailbox/MailboxAdapter.java      | 11 +++---
 .../james/smtpserver/fastfail/URIScanner.java   | 18 ++++-----
 .../james/smtpserver/fastfail/ValidRcptMX.java  | 11 +++---
 .../james/smtpserver/mock/MockMimeMessage.java  | 36 +++++++++++++-----
 58 files changed, 350 insertions(+), 457 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
index 38d4bd1..81a3560 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
@@ -86,19 +86,16 @@ public class FetchGroupImpl implements MessageResult.FetchGroup {
      */
     public void addPartContent(MimePath path, int content) {
         if (partContentDescriptors == null) {
-            partContentDescriptors = new HashSet<PartContentDescriptor>();
-        }
-        PartContentDescriptorImpl currentDescriptor = null;
-        for (PartContentDescriptor descriptor : partContentDescriptors) {
-            if (path.equals(descriptor.path())) {
-                currentDescriptor = (PartContentDescriptorImpl) descriptor;
-                break;
-            }
-        }
-        if (currentDescriptor == null) {
-            currentDescriptor = new PartContentDescriptorImpl(path);
-            partContentDescriptors.add(currentDescriptor);
+            partContentDescriptors = new HashSet<>();
         }
+        PartContentDescriptorImpl currentDescriptor = (PartContentDescriptorImpl) partContentDescriptors.stream()
+            .filter(descriptor -> path.equals(descriptor.path()))
+            .findFirst()
+            .orElseGet(() -> {
+                PartContentDescriptorImpl result = new PartContentDescriptorImpl(path);
+                partContentDescriptors.add(result);
+                return result;
+            });
 
         currentDescriptor.or(content);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
index e4b57e9a..d401e36 100644
--- a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
+++ b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
@@ -318,11 +318,7 @@ public class HBaseMailboxMessage implements MailboxMessage {
      * This implementation supports user flags
      */
     public String[] createUserFlags() {
-        String[] flags = new String[userFlags.size()];
-        for (int i = 0; i < userFlags.size(); i++) {
-            flags[i] = userFlags.get(i);
-        }
-        return flags;
+        return userFlags.toArray(new String[userFlags.size()]);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
index 3637e41..7ffabb6 100644
--- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
+++ b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
@@ -53,6 +53,8 @@ import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.search.comparator.UidComparator;
 import org.slf4j.Logger;
 
+import com.github.steveash.guavate.Guavate;
+
 public class JCRMailboxMessage implements MailboxMessage, JCRImapConstants, Persistent {
 
     private static final Comparator<MailboxMessage> MESSAGE_UID_COMPARATOR = new UidComparator();
@@ -304,10 +306,9 @@ public class JCRMailboxMessage implements MailboxMessage, JCRImapConstants, Pers
 
 
             List<Property> currentProperties = getProperties();
-            List<Property> newProperties = new ArrayList<Property>();
-            for (Property prop : currentProperties) {
-                newProperties.add(new JCRProperty(prop, logger));
-            }
+            List<Property> newProperties = currentProperties.stream()
+                .map(prop -> new JCRProperty(prop, logger))
+                .collect(Guavate.toImmutableList());
             // remove old properties, we will add a bunch of new ones
             NodeIterator iterator = node.getNodes("messageProperty");
             while (iterator.hasNext()) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
index c9ae2e4..2b27598 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
@@ -463,11 +463,9 @@ public abstract class AbstractJPAMailboxMessage implements MailboxMessage {
     }
 
     protected String[] createUserFlags() {
-        String[] flags = new String[userFlags.size()];
-        for (int i = 0; i < userFlags.size(); i++) {
-            flags[i] = userFlags.get(i).getName();
-        }
-        return flags;
+        return userFlags.stream()
+            .map(JPAUserFlag::getName)
+            .toArray(String[]::new);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/UidConstraint.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/UidConstraint.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/UidConstraint.java
index 1608213..52656f9 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/UidConstraint.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/UidConstraint.java
@@ -50,10 +50,8 @@ public class UidConstraint {
     }
     
     public boolean isAllowed(long uid) {
-        for (Constraint constraint : constraints)
-            if (!constraint.isAllowed(uid))
-                return false;
-        return true;
+        return constraints.stream()
+            .allMatch(constraint -> constraint.isAllowed(uid));
     }
 
     public abstract static class Constraint {

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/user/MaildirSubscriptionMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/user/MaildirSubscriptionMapper.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/user/MaildirSubscriptionMapper.java
index 43ea311..552c949 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/user/MaildirSubscriptionMapper.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/user/MaildirSubscriptionMapper.java
@@ -26,7 +26,6 @@ import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -37,6 +36,10 @@ import org.apache.james.mailbox.store.user.SubscriptionMapper;
 import org.apache.james.mailbox.store.user.model.Subscription;
 import org.apache.james.mailbox.store.user.model.impl.SimpleSubscription;
 
+import com.github.steveash.guavate.Guavate;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+
 public class MaildirSubscriptionMapper extends NonTransactionalMapper implements SubscriptionMapper {
 
     private static final String FILE_SUBSCRIPTION = "subscriptions";
@@ -53,10 +56,11 @@ public class MaildirSubscriptionMapper extends NonTransactionalMapper implements
     public void delete(Subscription subscription) throws SubscriptionException {
      // TODO: we need some kind of file locking here
         Set<String> subscriptionNames = readSubscriptionsForUser(subscription.getUser());
-        boolean changed = subscriptionNames.remove(subscription.getMailbox());
+        Set<String> newSubscriptions = Sets.difference(subscriptionNames, ImmutableSet.of(subscription.getMailbox()));
+        boolean changed = subscriptionNames.size() != newSubscriptions.size();
         if (changed) {
             try {
-                writeSubscriptions(new File(store.userRoot(subscription.getUser())), subscriptionNames);
+                writeSubscriptions(new File(store.userRoot(subscription.getUser())), newSubscriptions);
             } catch (IOException e) {
                 throw new SubscriptionException(e);
             }
@@ -69,11 +73,9 @@ public class MaildirSubscriptionMapper extends NonTransactionalMapper implements
     @Override
     public List<Subscription> findSubscriptionsForUser(String user) throws SubscriptionException {
         Set<String> subscriptionNames = readSubscriptionsForUser(user);
-        ArrayList<Subscription> subscriptions = new ArrayList<Subscription>();
-        for (String subscription : subscriptionNames) {
-            subscriptions.add(new SimpleSubscription(user, subscription));
-        }
-        return subscriptions;
+        return subscriptionNames.stream()
+            .map(subscription -> new SimpleSubscription(user, subscription))
+            .collect(Guavate.toImmutableList());
     }
 
     /**
@@ -100,10 +102,14 @@ public class MaildirSubscriptionMapper extends NonTransactionalMapper implements
     public void save(Subscription subscription) throws SubscriptionException {
         // TODO: we need some kind of file locking here
         Set<String> subscriptionNames = readSubscriptionsForUser(subscription.getUser());
-        boolean changed = subscriptionNames.add(subscription.getMailbox());
+        Set<String> newSubscriptions = ImmutableSet.<String>builder()
+            .addAll(subscriptionNames)
+            .add(subscription.getMailbox())
+            .build();
+        boolean changed = subscriptionNames.size() != newSubscriptions.size();
         if (changed) {
             try {
-                writeSubscriptions(new File(store.userRoot(subscription.getUser())), subscriptionNames);
+                writeSubscriptions(new File(store.userRoot(subscription.getUser())), newSubscriptions);
             } catch (IOException e) {
                 throw new SubscriptionException(e);
             }
@@ -127,13 +133,11 @@ public class MaildirSubscriptionMapper extends NonTransactionalMapper implements
      */
     private Set<String> readSubscriptionsForUser(String user) throws SubscriptionException { 
         File userRoot = new File(store.userRoot(user));
-        Set<String> subscriptionNames;
         try {
-            subscriptionNames = readSubscriptions(userRoot);
+            return readSubscriptions(userRoot);
         } catch (IOException e) {
             throw new SubscriptionException(e);
         }
-        return subscriptionNames;
     }
 
     /**
@@ -144,16 +148,14 @@ public class MaildirSubscriptionMapper extends NonTransactionalMapper implements
      */
     private Set<String> readSubscriptions(File mailboxFolder) throws IOException {
         File subscriptionFile = new File(mailboxFolder, FILE_SUBSCRIPTION);
-        HashSet<String> subscriptions = new HashSet<String>();
         if (!subscriptionFile.exists()) {
-            return subscriptions;
+            return ImmutableSet.of();
         }
         FileReader fileReader = new FileReader(subscriptionFile);
         BufferedReader reader = new BufferedReader(fileReader);
-        String subscription;
-        while ((subscription = reader.readLine()) != null)
-            if (!subscription.equals(""))
-                subscriptions.add(subscription);
+        Set<String> subscriptions = reader.lines()
+            .filter(subscription -> !subscription.equals(""))
+            .collect(Guavate.toImmutableSet());
         reader.close();
         fileReader.close();
         return subscriptions;

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
index 7e7eb8e..4ef6936 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
@@ -34,6 +34,7 @@ import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Objects;
 
 public class InMemoryMailboxMapper implements MailboxMapper {
@@ -84,13 +85,11 @@ public class InMemoryMailboxMapper implements MailboxMapper {
      */
     public List<Mailbox> findMailboxWithPathLike(MailboxPath path) throws MailboxException {
         final String regex = path.getName().replace("%", ".*");
-        List<Mailbox> results = new ArrayList<Mailbox>();
-        for (Mailbox mailbox: mailboxesByPath.values()) {
-            if (mailboxMatchesRegex(mailbox, path, regex)) {
-                results.add(new SimpleMailbox(mailbox));
-            }
-        }
-        return results;
+        return mailboxesByPath.values()
+            .stream()
+            .filter(mailbox -> mailboxMatchesRegex(mailbox, path, regex))
+            .map(SimpleMailbox::new)
+            .collect(Guavate.toImmutableList());
     }
 
     private boolean mailboxMatchesRegex(Mailbox mailbox, MailboxPath path, String regex) {
@@ -134,12 +133,9 @@ public class InMemoryMailboxMapper implements MailboxMapper {
      */
     public boolean hasChildren(Mailbox mailbox, char delimiter) throws MailboxException {
         String mailboxName = mailbox.getName() + delimiter;
-        for (Mailbox box: mailboxesByPath.values()) {
-            if (belongsToSameUser(mailbox, box) && box.getName().startsWith(mailboxName)) {
-                return true;
-            }
-        }
-        return false;
+        return mailboxesByPath.values()
+            .stream()
+            .anyMatch(box -> belongsToSameUser(mailbox, box) && box.getName().startsWith(mailboxName));
     }
 
     private boolean belongsToSameUser(Mailbox mailbox, Mailbox otherMailbox) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
index aacc35b..9c6bfc0 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
@@ -45,6 +45,8 @@ import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 import org.apache.james.mailbox.store.mail.utils.ApplicableFlagCalculator;
 
+import com.github.steveash.guavate.Guavate;
+
 public class InMemoryMessageMapper extends AbstractMessageMapper {
     private final Map<InMemoryId, Map<MessageUid, MailboxMessage>> mailboxByUid;
     private static final int INITIAL_SIZE = 256;
@@ -75,13 +77,10 @@ public class InMemoryMessageMapper extends AbstractMessageMapper {
 
     @Override
     public long countUnseenMessagesInMailbox(Mailbox mailbox) throws MailboxException {
-        long count = 0;
-        for (MailboxMessage member : getMembershipByUidForMailbox(mailbox).values()) {
-            if (!member.isSeen()) {
-                count++;
-            }
-        }
-        return count;
+        return getMembershipByUidForMailbox(mailbox).values()
+            .stream()
+            .filter(member -> !member.isSeen())
+            .count();
     }
 
     @Override
@@ -118,27 +117,23 @@ public class InMemoryMessageMapper extends AbstractMessageMapper {
 
     @Override
     public List<MessageUid> findRecentMessageUidsInMailbox(Mailbox mailbox) throws MailboxException {
-        final List<MessageUid> results = new ArrayList<MessageUid>();
-        for (MailboxMessage member : getMembershipByUidForMailbox(mailbox).values()) {
-            if (member.isRecent()) {
-                results.add(member.getUid());
-            }
-        }
-        Collections.sort(results);
-
-        return results;
+        return getMembershipByUidForMailbox(mailbox).values()
+            .stream()
+            .filter(MailboxMessage::isRecent)
+            .map(MailboxMessage::getUid)
+            .sorted()
+            .collect(Guavate.toImmutableList());
     }
 
     @Override
     public MessageUid findFirstUnseenMessageUid(Mailbox mailbox) throws MailboxException {
         List<MailboxMessage> memberships = new ArrayList<MailboxMessage>(getMembershipByUidForMailbox(mailbox).values());
         Collections.sort(memberships);
-        for (MailboxMessage m : memberships) {
-            if (m.isSeen() == false) {
-                return m.getUid();
-            }
-        }
-        return null;
+        return memberships.stream()
+            .filter(m -> !m.isSeen())
+            .findFirst()
+            .map(MailboxMessage::getUid)
+            .orElse(null);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/user/InMemorySubscriptionMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/user/InMemorySubscriptionMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/user/InMemorySubscriptionMapper.java
index 7ec79d9..7bad0e6 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/user/InMemorySubscriptionMapper.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/user/InMemorySubscriptionMapper.java
@@ -48,16 +48,13 @@ public class InMemorySubscriptionMapper extends NonTransactionalMapper implement
 
     public Subscription findMailboxSubscriptionForUser(String user, String mailbox) {
         final List<Subscription> subscriptions = subscriptionsByUser.get(user);
-        Subscription result = null;
         if (subscriptions != null) {
-            for(Subscription subscription:subscriptions) {
-                if (subscription.getMailbox().equals(mailbox)) {
-                    result = subscription;
-                    break;
-                }
-            }
+            return subscriptions.stream()
+                .filter(subscription -> subscription.getMailbox().equals(mailbox))
+                .findFirst()
+                .orElse(null);
         }
-        return result;
+        return null;
     }
 
     public List<Subscription> findSubscriptionsForUser(String user) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/store/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/store/pom.xml b/mailbox/store/pom.xml
index 7459362..a12e0ff 100644
--- a/mailbox/store/pom.xml
+++ b/mailbox/store/pom.xml
@@ -73,6 +73,10 @@
             <artifactId>commons-lang</artifactId>
         </dependency>
         <dependency>
+            <groupId>com.github.steveash.guavate</groupId>
+            <artifactId>guavate</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index cc7083c..09d3a64 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -84,6 +84,7 @@ import org.apache.james.mailbox.store.transaction.Mapper;
 import org.apache.james.mailbox.store.transaction.TransactionalMapper;
 import org.slf4j.Logger;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
 import com.google.common.collect.FluentIterable;
@@ -775,13 +776,11 @@ public class StoreMailboxManager implements MailboxManager {
 
     @Override
     public List<MailboxPath> list(MailboxSession session) throws MailboxException {
-        List<MailboxPath> mList = new ArrayList<MailboxPath>();
-        List<Mailbox> mailboxes = mailboxSessionMapperFactory.getMailboxMapper(session).list();
-        for (Mailbox m : mailboxes) {
-            mList.add(m.generateAssociatedPath());
-        }
-        return Collections.unmodifiableList(mList);
-
+        return mailboxSessionMapperFactory.getMailboxMapper(session)
+            .list()
+            .stream()
+            .map(Mailbox::generateAssociatedPath)
+            .collect(Guavate.toImmutableList());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreSubscriptionManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreSubscriptionManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreSubscriptionManager.java
index e611536..fb0c38c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreSubscriptionManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreSubscriptionManager.java
@@ -20,7 +20,7 @@ package org.apache.james.mailbox.store;
 
 import java.util.Collection;
 import java.util.HashSet;
-import java.util.List;
+import java.util.stream.Collectors;
 
 import javax.inject.Inject;
 
@@ -88,13 +88,11 @@ public class StoreSubscriptionManager implements SubscriptionManager {
      * @see org.apache.james.mailbox.SubscriptionManager#subscriptions(org.apache.james.mailbox.MailboxSession)
      */
     public Collection<String> subscriptions(MailboxSession session) throws SubscriptionException {
-        final SubscriptionMapper mapper = mapperFactory.getSubscriptionMapper(session);
-        final List<Subscription> subscriptions = mapper.findSubscriptionsForUser(session.getUser().getUserName());
-        final Collection<String> results = new HashSet<String>(INITIAL_SIZE);
-        for (Subscription subscription:subscriptions) {
-            results.add(subscription.getMailbox());
-        }        
-        return results;
+        return mapperFactory.getSubscriptionMapper(session)
+            .findSubscriptionsForUser(session.getUser().getUserName())
+            .stream()
+            .map(Subscription::getMailbox)
+            .collect(Collectors.toCollection(() -> new HashSet<>(INITIAL_SIZE)));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
index 0621d55..6e47062 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
@@ -19,7 +19,6 @@
 
 package org.apache.james.mailbox.store.json.event;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -46,6 +45,7 @@ import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.collect.ImmutableMap;
 
 public class EventConverter {
@@ -150,10 +150,9 @@ public class EventConverter {
                                                                MailboxDataTransferObject mailboxIntermediate,
                                                                List<MessageUid> uids,
                                                                List<UpdatedFlags> updatedFlagsList) {
-        ArrayList<UpdatedFlagsDataTransferObject> updatedFlagsDataTransferObjects = new ArrayList<UpdatedFlagsDataTransferObject>();
-        for(UpdatedFlags updatedFlags : updatedFlagsList) {
-            updatedFlagsDataTransferObjects.add(new UpdatedFlagsDataTransferObject(updatedFlags));
-        }
+        List<UpdatedFlagsDataTransferObject> updatedFlagsDataTransferObjects = updatedFlagsList.stream()
+            .map(UpdatedFlagsDataTransferObject::new)
+            .collect(Guavate.toImmutableList());
         return EventDataTransferObject.builder()
             .type(EventType.FLAGS)
             .session(new MailboxSessionDataTransferObject(session))
@@ -198,11 +197,9 @@ public class EventConverter {
     }
 
     private List<UpdatedFlags> retrieveUpdatedFlags(List<UpdatedFlagsDataTransferObject> updatedFlagsDataTransferObject) {
-        List<UpdatedFlags> result = new ArrayList<UpdatedFlags>();
-        for(UpdatedFlagsDataTransferObject proxy : updatedFlagsDataTransferObject) {
-            result.add(proxy.retrieveUpdatedFlags());
-        }
-        return result;
+        return updatedFlagsDataTransferObject.stream()
+            .map(UpdatedFlagsDataTransferObject::retrieveUpdatedFlags)
+            .collect(Guavate.toImmutableList());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/PropertyBuilder.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/PropertyBuilder.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/PropertyBuilder.java
index 2c88849..7d004c7 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/PropertyBuilder.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/PropertyBuilder.java
@@ -50,6 +50,7 @@ import java.util.TreeMap;
 
 import org.apache.james.mailbox.store.mail.model.Property;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Predicate;
 
 /**
@@ -110,14 +111,11 @@ public class PropertyBuilder {
      * or null when no property has the given name and namespace
      */
     public String getFirstValue(String namespace, String localName) {
-        String result = null;
-        for (SimpleProperty property: properties) {
-            if (property.isNamed(namespace, localName)) {
-                result = property.getValue();
-                break;
-            }
-        }
-        return result;
+        return properties.stream()
+            .filter(property -> property.isNamed(namespace, localName))
+            .findFirst()
+            .map(SimpleProperty::getValue)
+            .orElse(null);
     }
     
     /**
@@ -127,13 +125,10 @@ public class PropertyBuilder {
      * @return not null
      */
     public List<String> getValues(String namespace, String localName) {
-        List<String> results = new ArrayList<String>();
-        for (SimpleProperty property: properties) {
-            if (property.isNamed(namespace, localName)) {
-                results.add(property.getValue());
-            }
-        }
-        return results;
+        return properties.stream()
+            .filter(property -> property.isNamed(namespace, localName))
+            .map(SimpleProperty::getValue)
+            .collect(Guavate.toImmutableList());
     }
     
     /**
@@ -183,7 +178,7 @@ public class PropertyBuilder {
      * @return values indexed by local name
      */
     public SortedMap<String,String> getProperties(String namespace) {
-        final SortedMap<String, String> parameters = new TreeMap<String, String>();
+        final SortedMap<String, String> parameters = new TreeMap<>();
         for (SimpleProperty property : properties) {
             if (property.isInSpace(namespace)) {
                 parameters.put(property.getLocalName(), property.getValue());

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
index 78fa9af..966814a 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
@@ -26,6 +26,7 @@ import java.io.InputStream;
 import java.io.SequenceInputStream;
 import java.io.StringReader;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
@@ -358,12 +359,8 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
         SearchQuery.UidInOperator operator = criterion.getOperator();
         UidRange[] ranges = operator.getRange();
         MessageUid uid = message.getUid();
-        for (UidRange numericRange : ranges) {
-            if (numericRange.isIn(uid)) {
-                return true;
-            }
-        }
-        return false;
+        return Arrays.stream(ranges)
+            .anyMatch(numericRange -> numericRange.isIn(uid));
     }
 
     private boolean matches(SearchQuery.HeaderCriterion criterion, MailboxMessage message)
@@ -429,13 +426,9 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
     private boolean exists(String headerName, MailboxMessage message) throws MailboxException, IOException {
         List<Header> headers = ResultUtils.createHeaders(message);
 
-        for (Header header : headers) {
-            String name = header.getName();
-            if (headerName.equalsIgnoreCase(name)) {
-                return true;
-            }
-        }
-        return false;
+        return headers.stream()
+            .map(Header::getName)
+            .anyMatch(headerName::equalsIgnoreCase);
     }
 
     private boolean matches(SearchQuery.ContainsOperator operator, String headerName,

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailet/ai/src/main/java/org/apache/james/ai/classic/Tokenizer.java
----------------------------------------------------------------------
diff --git a/mailet/ai/src/main/java/org/apache/james/ai/classic/Tokenizer.java b/mailet/ai/src/main/java/org/apache/james/ai/classic/Tokenizer.java
index af268ad..d61957a 100644
--- a/mailet/ai/src/main/java/org/apache/james/ai/classic/Tokenizer.java
+++ b/mailet/ai/src/main/java/org/apache/james/ai/classic/Tokenizer.java
@@ -21,6 +21,7 @@ package org.apache.james.ai.classic;
 
 import java.io.IOException;
 import java.io.Reader;
+import java.util.stream.IntStream;
 
 /**
  * Tokenizes streaming mail input.
@@ -70,12 +71,8 @@ public abstract class Tokenizer {
     protected abstract void next(String token);
 
     private boolean allDigits(String s) {
-        for (int i = 0; i < s.length(); i++) {
-            if (!Character.isDigit(s.charAt(i))) {
-                return false;
-            }
-        }
-        return true;
+        return IntStream.range(0, s.length())
+            .allMatch(i -> Character.isDigit(s.charAt(i)));
     }
     
     private String nextToken(Reader reader) throws java.io.IOException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java b/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
index cdf9e50..d95a061 100644
--- a/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
+++ b/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
@@ -23,6 +23,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.Arrays;
 
 import javax.mail.MessagingException;
 
@@ -87,11 +88,8 @@ public class AutomaticallySentMailDetectorImpl implements AutomaticallySentMailD
     public boolean isAutoSubmitted(Mail mail) throws MessagingException {
         String[] headers = mail.getMessage().getHeader(AUTO_SUBMITTED_HEADER);
         if (headers != null) {
-            for (String header : headers) {
-                if (header.equalsIgnoreCase(AUTO_REPLIED_VALUE)) {
-                    return true;
-                }
-            }
+            return Arrays.stream(headers)
+                .anyMatch(header -> header.equalsIgnoreCase(AUTO_REPLIED_VALUE));
         }
         return false;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java b/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
index d982a61..1fe2108 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
@@ -20,6 +20,15 @@
 
 package org.apache.james.transport.matchers;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.codec.DecoderUtil;
 import org.apache.james.mime4j.util.MimeUtil;
@@ -27,14 +36,6 @@ import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.GenericMatcher;
 
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.StringTokenizer;
-
 /**
  * use: <pre><code>&lt;mailet match="HasHeader={&lt;header&gt;[=value]}+" class="..." /&gt;</code></pre>
  * <p/>
@@ -83,11 +84,8 @@ public class HasHeader extends GenericMatcher {
         public boolean isMatching(MimeMessage mimeMessage) throws MessagingException {
             String[] headerArray = mimeMessage.getHeader(headerName);
             if (headerArray != null && headerArray.length > 0) {
-                for (String value : headerArray) {
-                    if (headerValue.equals(sanitizeHeaderField(value))) {
-                        return true;
-                    }
-                }
+                return Arrays.stream(headerArray)
+                    .anyMatch(value -> headerValue.equals(sanitizeHeaderField(value)));
             }
             return false;
         }
@@ -96,7 +94,7 @@ public class HasHeader extends GenericMatcher {
     private List<HeaderCondition> headerConditions;
 
     public void init() throws MessagingException {
-        headerConditions = new ArrayList<HeaderCondition>();
+        headerConditions = new ArrayList<>();
         StringTokenizer conditionTokenizer = new StringTokenizer(getCondition(), CONDITION_SEPARATOR);
         while (conditionTokenizer.hasMoreTokens()) {
             headerConditions.add(parseHeaderCondition(conditionTokenizer.nextToken().trim()));

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/mpt/core/src/main/java/org/apache/james/mpt/helper/ScriptBuilder.java
----------------------------------------------------------------------
diff --git a/mpt/core/src/main/java/org/apache/james/mpt/helper/ScriptBuilder.java b/mpt/core/src/main/java/org/apache/james/mpt/helper/ScriptBuilder.java
index 589fac2..f431a29 100644
--- a/mpt/core/src/main/java/org/apache/james/mpt/helper/ScriptBuilder.java
+++ b/mpt/core/src/main/java/org/apache/james/mpt/helper/ScriptBuilder.java
@@ -28,6 +28,7 @@ import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.SocketChannel;
 import java.nio.channels.WritableByteChannel;
 import java.nio.charset.Charset;
+import java.util.Arrays;
 import java.util.Locale;
 
 import org.apache.commons.lang.StringUtils;
@@ -1459,13 +1460,8 @@ public class ScriptBuilder {
         }
 
         private boolean ignoreLine(String line) {
-            boolean result = false;
-            for (String entry : IGNORE_LINES_CONTAINING) {
-                if (line.indexOf(entry) > 0) {
-                    result = true;
-                    break;
-                }
-            }
+            boolean result = Arrays.stream(IGNORE_LINES_CONTAINING)
+                .anyMatch(entry -> line.indexOf(entry) > 0);
             for (int i = 0; i < IGNORE_LINES_STARTING_WITH.length && !result; i++) {
                 if (line.startsWith(IGNORE_LINES_STARTING_WITH[i])) {
                     result = true;

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/api/pom.xml
----------------------------------------------------------------------
diff --git a/protocols/api/pom.xml b/protocols/api/pom.xml
index 3d44414..8d0f0fd 100644
--- a/protocols/api/pom.xml
+++ b/protocols/api/pom.xml
@@ -39,6 +39,10 @@
             <artifactId>guava</artifactId>
         </dependency>
         <dependency>
+            <groupId>com.github.steveash.guavate</groupId>
+            <artifactId>guavate</artifactId>
+        </dependency>
+        <dependency>
             <groupId>commons-configuration</groupId>
             <artifactId>commons-configuration</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/api/src/main/java/org/apache/james/protocols/api/handler/AbstractProtocolHandlerChain.java
----------------------------------------------------------------------
diff --git a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/AbstractProtocolHandlerChain.java b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/AbstractProtocolHandlerChain.java
index 146c3f6..23c1f08 100644
--- a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/AbstractProtocolHandlerChain.java
+++ b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/AbstractProtocolHandlerChain.java
@@ -20,6 +20,7 @@ package org.apache.james.protocols.api.handler;
 
 import java.util.LinkedList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 
 /**
@@ -41,14 +42,11 @@ public abstract class AbstractProtocolHandlerChain implements ProtocolHandlerCha
      */
     @SuppressWarnings("unchecked")
     public <T> LinkedList<T> getHandlers(Class<T> type) {
-        LinkedList<T> result = new LinkedList<T>();
         List<ProtocolHandler> handlers = getHandlers();
-        for (ProtocolHandler handler : handlers) {
-            if (type.isInstance(handler)) {
-                result.add((T) handler);
-            }
-        }
-        return result;
+        return handlers.stream()
+            .filter(type::isInstance)
+            .map(handler -> (T) handler)
+            .collect(Collectors.toCollection(LinkedList::new));
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/api/src/main/java/org/apache/james/protocols/api/handler/ProtocolHandlerChainImpl.java
----------------------------------------------------------------------
diff --git a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/ProtocolHandlerChainImpl.java b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/ProtocolHandlerChainImpl.java
index 3ca9437..4eb4f8f 100644
--- a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/ProtocolHandlerChainImpl.java
+++ b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/ProtocolHandlerChainImpl.java
@@ -259,10 +259,7 @@ public class ProtocolHandlerChainImpl extends AbstractProtocolHandlerChain imple
      * @see java.util.List#subList(int, int)
      */
     public List<ProtocolHandler> subList(int fromIndex, int toIndex) {
-        List<ProtocolHandler> sList = new ArrayList<ProtocolHandler>();
-        for (Object handler : handlers.subList(fromIndex, toIndex)) {
-            sList.add((ProtocolHandler) handler);
-        }
+        List<ProtocolHandler> sList = new ArrayList<>(handlers.subList(fromIndex, toIndex));
         if (readyOnly) {
             return Collections.unmodifiableList(sList);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/api/src/test/java/org/apache/james/protocols/api/AbstractProtocolTransportTest.java
----------------------------------------------------------------------
diff --git a/protocols/api/src/test/java/org/apache/james/protocols/api/AbstractProtocolTransportTest.java b/protocols/api/src/test/java/org/apache/james/protocols/api/AbstractProtocolTransportTest.java
index 039a01d..e19db8b 100644
--- a/protocols/api/src/test/java/org/apache/james/protocols/api/AbstractProtocolTransportTest.java
+++ b/protocols/api/src/test/java/org/apache/james/protocols/api/AbstractProtocolTransportTest.java
@@ -30,11 +30,14 @@ import java.util.Collections;
 import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.CountDownLatch;
+import java.util.stream.IntStream;
 
 import org.apache.james.protocols.api.future.FutureResponseImpl;
 import org.apache.james.protocols.api.handler.LineHandler;
 import org.junit.Test;
 
+import com.github.steveash.guavate.Guavate;
+
 /**
  * Test-case for PROTOCOLS-62
  *
@@ -45,11 +48,10 @@ public class AbstractProtocolTransportTest {
     
     @Test
     public void testWriteOrder() throws InterruptedException, UnsupportedEncodingException {
-        final List<Response> messages = new ArrayList<Response>();
-        for (int i = 0; i < 2000; i++) {
-            messages.add(new TestResponse());
-        }
-        
+        final List<Response> messages = IntStream.range(0, 2000)
+            .mapToObj(i -> new TestResponse())
+            .collect(Guavate.toImmutableList());
+
         checkWrittenResponses(messages);
     }
     
@@ -67,22 +69,21 @@ public class AbstractProtocolTransportTest {
        
     @Test
     public void testWriteOrderFutureResponse() throws InterruptedException, UnsupportedEncodingException {
-        final List<Response> messages = new ArrayList<Response>();
-        for (int i = 0; i < 2000; i++) {
-            messages.add(new FutureResponseImpl());
-        }
-        notifyFutureResponses(messages, false);
+        final List<Response> messages = IntStream.range(0, 2000)
+            .mapToObj(i -> new FutureResponseImpl())
+            .collect(Guavate.toImmutableList());
 
+        notifyFutureResponses(messages, false);
         
         checkWrittenResponses(messages);
     }
 
     @Test
     public void testWriteOrderFutureResponseReverseNotify() throws InterruptedException, UnsupportedEncodingException {
-        final List<Response> messages = new ArrayList<Response>();
-        for (int i = 0; i < 2000; i++) {
-            messages.add(new FutureResponseImpl());
-        }
+        final List<Response> messages = IntStream.range(0, 2000)
+            .mapToObj(i -> new FutureResponseImpl())
+            .collect(Guavate.toImmutableList());
+
         notifyFutureResponses(messages, true);
 
         checkWrittenResponses(messages);

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/imap/src/main/java/org/apache/james/imap/api/message/UidRange.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/UidRange.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/UidRange.java
index cf1455e..d972442 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/message/UidRange.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/UidRange.java
@@ -22,6 +22,7 @@ package org.apache.james.imap.api.message;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MessageRange;
@@ -80,11 +81,9 @@ public final class UidRange implements Iterable<MessageUid> {
 
 
     private static LinkedList<UidRange> toUidRanges(List<Range<MessageUid>> mergedRanges) {
-        LinkedList<UidRange> result = new LinkedList<UidRange>();
-        for (Range<MessageUid> range: mergedRanges) {
-            result.add(new UidRange(range.lowerEndpoint(), range.upperEndpoint()));
-        }
-        return result;
+        return mergedRanges.stream()
+            .map(range -> new UidRange(range.lowerEndpoint(), range.upperEndpoint()))
+            .collect(Collectors.toCollection(LinkedList::new));
     }
     
     private final MessageRange range;

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
index 2713d73..3d59941 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
@@ -134,7 +134,7 @@ public class SearchProcessor extends AbstractMailboxProcessor<SearchRequest> imp
                 for (long id : ids) {
                     idList.add(id);
                 }
-                
+
                 List<IdRange> idsAsRanges = new ArrayList<IdRange>();
                 for (Long id: idList) {
                     idsAsRanges.add(new IdRange(id));
@@ -219,13 +219,7 @@ public class SearchProcessor extends AbstractMailboxProcessor<SearchRequest> imp
     }
     
     private long[] toArray(Collection<Long> results) {
-        final Iterator<Long> it = results.iterator();
-        final int length = results.size();
-        long[] ids = new long[length];
-        for (int i = 0; i < length; i++) {
-            ids[i] = ((Long) it.next()).longValue();
-        }
-        return ids;
+        return results.stream().mapToLong(x -> x).toArray();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/MessageResultUtils.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/MessageResultUtils.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/MessageResultUtils.java
index 411f6dc..6c83560 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/MessageResultUtils.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/MessageResultUtils.java
@@ -20,6 +20,7 @@
 package org.apache.james.imap.processor.fetch;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -70,11 +71,9 @@ public class MessageResultUtils {
                 MessageResult.Header header = iterator.next();
                 final String headerName = header.getName();
                 if (headerName != null) {
-                    for (String name : names) {
-                        if (headerName.equalsIgnoreCase(name)) {
-                            results.add(header);
-                            break;
-                        }
+                    if (Arrays.stream(names)
+                        .anyMatch(headerName::equalsIgnoreCase)) {
+                        results.add(header);
                     }
                 }
             }
@@ -114,17 +113,11 @@ public class MessageResultUtils {
     }
 
     private static boolean contains(Collection<String> names, MessageResult.Header header) throws MailboxException {
-        boolean match = false;
         final String headerName = header.getName();
         if (headerName != null) {
-            for (String name : names) {
-                if (name.equalsIgnoreCase(headerName)) {
-                    match = true;
-                    break;
-                }
-            }
+            return names.stream().anyMatch(name -> name.equalsIgnoreCase(headerName));
         }
-        return match;
+        return false;
     }
 
     /**
@@ -189,13 +182,8 @@ public class MessageResultUtils {
                 MessageResult.Header header = iterator.next();
                 final String headerName = header.getName();
                 if (headerName != null) {
-                    boolean match = false;
-                    for (String name : names) {
-                        if (headerName.equalsIgnoreCase(name)) {
-                            match = true;
-                            break;
-                        }
-                    }
+                    boolean match = Arrays.stream(names)
+                        .anyMatch(headerName::equalsIgnoreCase);
                     if (!match) {
                         results.add(header);
                     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPSServerTest.java
----------------------------------------------------------------------
diff --git a/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPSServerTest.java b/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPSServerTest.java
index 7363969..96d7c34 100644
--- a/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPSServerTest.java
+++ b/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPSServerTest.java
@@ -93,13 +93,10 @@ public abstract class AbstractLMTPSServerTest extends AbstractLMTPServerTest{
             for (int i = 0; i < rcptCount; i++) {
                 replies.add(getReply());
             }
-            
-            for (int code: replies) {
-                if (SMTPReply.isPositiveCompletion(code)) {
-                    return true;
-                }
-            }
-            return false;
+
+            return replies.stream()
+                .mapToInt(code -> code)
+                .anyMatch(SMTPReply::isPositiveCompletion);
         }
 
         

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPServerTest.java
----------------------------------------------------------------------
diff --git a/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPServerTest.java b/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPServerTest.java
index 333a961..6f7ceb3 100644
--- a/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPServerTest.java
+++ b/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPServerTest.java
@@ -301,13 +301,10 @@ public abstract class AbstractLMTPServerTest extends AbstractSMTPServerTest{
             for (int i = 0; i < rcptCount; i++) {
                 replies.add(getReply());
             }
-            
-            for (int code: replies) {
-                if (SMTPReply.isPositiveCompletion(code)) {
-                    return true;
-                }
-            }
-            return false;
+
+            return replies.stream()
+                .mapToInt(code -> code)
+                .anyMatch(SMTPReply::isPositiveCompletion);
         }
 
         

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/pom.xml
----------------------------------------------------------------------
diff --git a/protocols/pom.xml b/protocols/pom.xml
index 20ab218..02bb164 100644
--- a/protocols/pom.xml
+++ b/protocols/pom.xml
@@ -157,6 +157,11 @@
                 <version>${apache-commons-io.version}</version>
             </dependency>
             <dependency>
+                <groupId>com.github.steveash.guavate</groupId>
+                <artifactId>guavate</artifactId>
+                <version>1.0.0</version>
+            </dependency>
+            <dependency>
                 <groupId>com.google.guava</groupId>
                 <artifactId>guava</artifactId>
                 <version>18.0</version>

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaDataUtils.java
----------------------------------------------------------------------
diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaDataUtils.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaDataUtils.java
index 2b6add0..6f69806 100644
--- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaDataUtils.java
+++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/MessageMetaDataUtils.java
@@ -20,6 +20,7 @@
 package org.apache.james.protocols.pop3.core;
 
 import java.util.List;
+import java.util.stream.IntStream;
 
 import org.apache.james.protocols.api.ProtocolSession.State;
 import org.apache.james.protocols.pop3.POP3Session;
@@ -56,12 +57,7 @@ public class MessageMetaDataUtils {
             return false;
         }
 
-        for (int i = 0; i < uid.length(); i++) {
-            if ((uid.charAt(i) >= 0x21 && uid.charAt(i) <= 0x7E) == false) {
-                return false;
-            }
-        }
-
-        return true;
+        return IntStream.range(0, uid.length())
+            .allMatch(i -> uid.charAt(i) >= 0x21 && uid.charAt(i) <= 0x7E);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java
----------------------------------------------------------------------
diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java
index 00c2195..5998e64 100644
--- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java
+++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/mailbox/ImapMailbox.java
@@ -20,6 +20,7 @@ package org.apache.james.protocols.pop3.mailbox;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Arrays;
 
 /**
  * An IMAP Mailbox adapter which is used in POP3 to retrieve messages
@@ -80,10 +81,9 @@ public abstract class ImapMailbox implements Mailbox {
     public abstract void remove(long... uids) throws IOException;
 
 	public void remove(String... uids) throws NumberFormatException, IOException {
-        long imapUids[] = new long[uids.length];
-        for (int i = 0; i < uids.length; i++) {
-            imapUids[i] = Long.parseLong(uids[i]);
-        }
+        long imapUids[] = Arrays.stream(uids)
+            .mapToLong(Long::parseLong)
+            .toArray();
         this.remove(imapUids);
 	}
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractStartTlsPOP3ServerTest.java
----------------------------------------------------------------------
diff --git a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractStartTlsPOP3ServerTest.java b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractStartTlsPOP3ServerTest.java
index e3fe5d3..128e388 100644
--- a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractStartTlsPOP3ServerTest.java
+++ b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/AbstractStartTlsPOP3ServerTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import java.net.InetSocketAddress;
+import java.util.Arrays;
 
 import org.apache.commons.net.pop3.POP3Reply;
 import org.apache.commons.net.pop3.POP3SClient;
@@ -78,13 +79,8 @@ public abstract class AbstractStartTlsPOP3ServerTest {
             assertEquals(POP3Reply.OK, client.sendCommand("CAPA"));
             client.getAdditionalReply();
 
-            boolean startTlsCapa = false;
-            for (String cap: client.getReplyStrings()) {
-                if (cap.equalsIgnoreCase("STLS")) {
-                    startTlsCapa = true;
-                    break;
-                }
-            }
+            boolean startTlsCapa = Arrays.stream(client.getReplyStrings())
+                .anyMatch(cap -> cap.equalsIgnoreCase("STLS"));
             assertTrue(startTlsCapa);
             
             assertTrue(client.execTLS());

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java
----------------------------------------------------------------------
diff --git a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java
index c2dbe27..308dac8 100644
--- a/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java
+++ b/protocols/pop3/src/test/java/org/apache/james/protocols/pop3/utils/MockMailbox.java
@@ -22,7 +22,6 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.SequenceInputStream;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -32,6 +31,8 @@ import org.apache.james.protocols.pop3.mailbox.ImapMailbox;
 import org.apache.james.protocols.pop3.mailbox.ImapMessageMetaData;
 import org.apache.james.protocols.pop3.mailbox.MessageMetaData;
 
+import com.github.steveash.guavate.Guavate;
+
 @SuppressWarnings("deprecation")
 public class MockMailbox extends ImapMailbox {
 
@@ -75,11 +76,10 @@ public class MockMailbox extends ImapMailbox {
     }
 
     public List<MessageMetaData> getMessages() throws IOException {
-        List<MessageMetaData> meta = new ArrayList<MessageMetaData>();
-        for (Message m: messages.values()) {
-            meta.add(m.meta);
-        }
-        return meta;
+        return messages.values()
+            .stream()
+            .map(m -> m.meta)
+            .collect(Guavate.toImmutableList());
     }
 
     public void remove(long... uids) throws IOException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPProtocolHandlerChain.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPProtocolHandlerChain.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPProtocolHandlerChain.java
index 1f3faff..1fd0d8f 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPProtocolHandlerChain.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPProtocolHandlerChain.java
@@ -138,22 +138,12 @@ public class SMTPProtocolHandlerChain extends ProtocolHandlerChainImpl {
 
     @Override
     public boolean addAll(Collection<? extends ProtocolHandler> c) {
-        for (ProtocolHandler handler: c) {
-            if (!checkForAuth(handler)) {
-                return false;
-            }
-        }
-        return super.addAll(c);
+        return c.stream().allMatch(this::checkForAuth) && super.addAll(c);
     }
 
     @Override
     public boolean addAll(int index, Collection<? extends ProtocolHandler> c) {
-        for (ProtocolHandler handler: c) {
-            if (!checkForAuth(handler)) {
-                return false;
-            }
-        }
-        return super.addAll(index, c);
+        return c.stream().allMatch(this::checkForAuth) && super.addAll(index, c);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
index a979e81..25e627e 100644
--- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
+++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
@@ -22,6 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.net.InetSocketAddress;
 import java.net.Socket;
+import java.util.Arrays;
 import java.util.Locale;
 import java.util.Properties;
 
@@ -148,12 +149,9 @@ public class NettyStartTlsSMTPServerTest {
         }
 
         public boolean isStartTLSAnnounced() {
-            for (String reply: client.getReplyStrings()) {
-                if (reply.toUpperCase(Locale.US).endsWith("STARTTLS")) {
-                    return true;
-                }
-            }
-            return false;
+            return Arrays.stream(client.getReplyStrings())
+                .anyMatch(reply -> reply.toUpperCase(Locale.US)
+                    .endsWith("STARTTLS"));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java
----------------------------------------------------------------------
diff --git a/server/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java b/server/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java
index b94e0da..d3d0f74 100644
--- a/server/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java
+++ b/server/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.cli.type;
 
+import java.util.Arrays;
+
 /**
  * Enumeration of valid command types.
  */
@@ -92,11 +94,10 @@ public enum CmdType {
      */
     public static CmdType lookup(String command) {
         if (command != null) {
-            for (CmdType cmd : values()) {
-                if (cmd.getCommand().equalsIgnoreCase(command)) {
-                    return cmd;
-                }
-            }
+            return Arrays.stream(values())
+                .filter(cmd -> cmd.getCommand().equalsIgnoreCase(command))
+                .findFirst()
+                .orElse(null);
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/container/core/src/test/java/org/apache/james/core/MimeMessageWrapperTest.java
----------------------------------------------------------------------
diff --git a/server/container/core/src/test/java/org/apache/james/core/MimeMessageWrapperTest.java b/server/container/core/src/test/java/org/apache/james/core/MimeMessageWrapperTest.java
index 449eedc..2f06915 100644
--- a/server/container/core/src/test/java/org/apache/james/core/MimeMessageWrapperTest.java
+++ b/server/container/core/src/test/java/org/apache/james/core/MimeMessageWrapperTest.java
@@ -225,15 +225,9 @@ public class MimeMessageWrapperTest extends MimeMessageFromStreamTest {
         mw.saveChanges();
 
         BufferedReader reader = new BufferedReader(new InputStreamReader(mw.getMessageInputStream()));
-        String line;
 
-        boolean headerUpdated = false;
-        while ((line = reader.readLine()) != null) {
-            if (line.equals("X-Test: X-Value")) {
-                headerUpdated = true;
-                break;
-            }
-        }
+        boolean headerUpdated = reader.lines()
+            .anyMatch(line -> line.equals("X-Test: X-Value"));
         reader.close();
         assertTrue(headerUpdated);
     }
@@ -250,15 +244,9 @@ public class MimeMessageWrapperTest extends MimeMessageFromStreamTest {
         mw.saveChanges();
 
         BufferedReader reader = new BufferedReader(new InputStreamReader(mw.getMessageInputStream()));
-        String line;
 
-        boolean contentUpdated = false;
-        while ((line = reader.readLine()) != null) {
-            if (line.equals(newContent)) {
-                contentUpdated = true;
-                break;
-            }
-        }
+        boolean contentUpdated = reader.lines()
+            .anyMatch(line -> line.equals(newContent));
         reader.close();
         assertTrue(contentUpdated);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
index 5f794a8..8afca6a 100644
--- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
+++ b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
@@ -21,7 +21,6 @@ package org.apache.james.adapter.mailbox;
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 
@@ -42,6 +41,7 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MailboxQuery;
 import org.slf4j.Logger;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Preconditions;
 
 /**
@@ -107,10 +107,10 @@ public class MailboxManagerManagement extends StandardMBean implements MailboxMa
             session = mailboxManager.createSystemSession(username, log);
             mailboxManager.startProcessingRequest(session);
             List<MailboxMetaData> mList = retrieveAllUserMailboxes(username, session);
-            for (MailboxMetaData aMList : mList) {
-                boxes.add(aMList.getPath().getName());
-            }
-            Collections.sort(boxes);
+            boxes = mList.stream()
+                .map(aMList -> aMList.getPath().getName())
+                .sorted()
+                .collect(Guavate.toImmutableList());
         } catch (MailboxException e) {
             log.error("Error list mailboxes for user " + username, e);
         } finally {

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/container/util/src/main/java/org/apache/james/util/bayesian/BayesianAnalyzer.java
----------------------------------------------------------------------
diff --git a/server/container/util/src/main/java/org/apache/james/util/bayesian/BayesianAnalyzer.java b/server/container/util/src/main/java/org/apache/james/util/bayesian/BayesianAnalyzer.java
index fe2ebca..d775a75 100644
--- a/server/container/util/src/main/java/org/apache/james/util/bayesian/BayesianAnalyzer.java
+++ b/server/container/util/src/main/java/org/apache/james/util/bayesian/BayesianAnalyzer.java
@@ -31,6 +31,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
+import java.util.stream.IntStream;
 
 /**
  * <p>
@@ -707,11 +708,7 @@ public class BayesianAnalyzer {
     }
 
     private boolean allDigits(String s) {
-        for (int i = 0; i < s.length(); i++) {
-            if (!Character.isDigit(s.charAt(i))) {
-                return false;
-            }
-        }
-        return true;
+        return IntStream.range(0, s.length())
+            .allMatch(i -> Character.isDigit(s.charAt(i)));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java b/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
index 60f5351..c6d315e 100644
--- a/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
+++ b/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
@@ -178,12 +178,10 @@ public class SieveFileRepository implements SieveRepository {
      */
     @Override
     public void haveSpace(String user, String name, long size) throws QuotaExceededException, StorageException {
-        long usedSpace = 0;
-        for (File file : getUserDirectory(user).listFiles()) {
-            if (!(file.getName().equals(name) || SYSTEM_FILES.contains(file.getName()))) {
-                usedSpace = usedSpace + file.length();
-            }
-        }
+        long usedSpace = Arrays.stream(getUserDirectory(user).listFiles())
+            .filter(file -> !(file.getName().equals(name) || SYSTEM_FILES.contains(file.getName())))
+            .mapToLong(File::length)
+            .sum();
 
         long quota = Long.MAX_VALUE;
         File file = getQuotaFile(user);

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/data/data-ldap/pom.xml
----------------------------------------------------------------------
diff --git a/server/data/data-ldap/pom.xml b/server/data/data-ldap/pom.xml
index da79b91..761680f 100644
--- a/server/data/data-ldap/pom.xml
+++ b/server/data/data-ldap/pom.xml
@@ -50,6 +50,10 @@
             <artifactId>commons-configuration</artifactId>
         </dependency>
         <dependency>
+            <groupId>com.github.steveash.guavate</groupId>
+            <artifactId>guavate</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java b/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java
index e2007cb..f7f48ef 100644
--- a/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java
+++ b/server/data/data-ldap/src/main/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepository.java
@@ -54,6 +54,7 @@ import org.apache.james.util.retry.naming.ldap.RetryingLdapContext;
 import org.apache.mailet.MailAddress;
 import org.slf4j.Logger;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Optional;
 
 /**
@@ -715,19 +716,17 @@ public class ReadOnlyUsersLDAPRepository implements UsersRepository, Configurabl
      * @see UsersRepository#list()
      */
     public Iterator<String> list() throws UsersRepositoryException {
-        List<String> result = new ArrayList<String>();
         try {
-
-            for (ReadOnlyLDAPUser readOnlyLDAPUser : buildUserCollection(getValidUsers())) {
-                result.add(readOnlyLDAPUser.getUserName());
-            }
+            return buildUserCollection(getValidUsers())
+                .stream()
+                .map(ReadOnlyLDAPUser::getUserName)
+                .collect(Guavate.toImmutableList())
+                .iterator();
         } catch (NamingException namingException) {
             throw new UsersRepositoryException(
                     "Unable to retrieve users list from LDAP due to unknown naming error.",
                     namingException);
         }
-
-        return result.iterator();
     }
 
     private Collection<String> getValidUsers() throws NamingException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/data/data-library/pom.xml
----------------------------------------------------------------------
diff --git a/server/data/data-library/pom.xml b/server/data/data-library/pom.xml
index 1d33e2e..00c8c27 100644
--- a/server/data/data-library/pom.xml
+++ b/server/data/data-library/pom.xml
@@ -54,6 +54,10 @@
             <artifactId>apache-mailet-api</artifactId>
         </dependency>
         <dependency>
+            <groupId>com.github.steveash.guavate</groupId>
+            <artifactId>guavate</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
index e238d4b..8c0a6e1 100644
--- a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
+++ b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
@@ -23,7 +23,6 @@ import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.List;
 import java.util.Locale;
 
@@ -37,6 +36,7 @@ import org.apache.james.lifecycle.api.LogEnabled;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
 import com.google.common.base.Throwables;
@@ -211,38 +211,25 @@ public abstract class AbstractDomainList implements DomainList, LogEnabled, Conf
      * @return domainIP List of ipaddress for domains
      */
     private static List<String> getDomainsIP(List<String> domains, DNSService dns, Logger log) {
-        List<String> domainIP = new ArrayList<String>();
-        if (domains.size() > 0) {
-            for (String domain : domains) {
-                List<String> domList = getDomainIP(domain, dns, log);
-
-                for (String aDomList : domList) {
-                    if (!domainIP.contains(aDomList)) {
-                        domainIP.add(aDomList);
-                    }
-                }
-            }
-        }
-        return domainIP;
+        return domains.stream()
+            .flatMap(domain -> getDomainIP(domain, dns, log).stream())
+            .distinct()
+            .collect(Guavate.toImmutableList());
     }
 
     /**
      * @see #getDomainsIP(List, DNSService, Logger)
      */
     private static List<String> getDomainIP(String domain, DNSService dns, Logger log) {
-        List<String> domainIP = new ArrayList<String>();
         try {
-            Collection<InetAddress> addrs = dns.getAllByName(domain);
-            for (InetAddress addr : addrs) {
-                String ip = addr.getHostAddress();
-                if (!domainIP.contains(ip)) {
-                    domainIP.add(ip);
-                }
-            }
+            return dns.getAllByName(domain).stream()
+                .map(InetAddress::getHostAddress)
+                .distinct()
+                .collect(Guavate.toImmutableList());
         } catch (UnknownHostException e) {
             log.error("Cannot get IP address(es) for " + domain);
+            return ImmutableList.of();
         }
-        return domainIP;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/data/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java b/server/data/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java
index 3f6409e..2472fed 100644
--- a/server/data/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java
+++ b/server/data/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java
@@ -27,9 +27,8 @@ import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Iterator;
-import java.util.List;
 
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
@@ -294,14 +293,10 @@ public abstract class AbstractFileRepository implements Repository, Configurable
     public Iterator<String> list() {
         final File storeDir = new File(m_baseDirectory.getAbsolutePath());
         final String[] names = storeDir.list(m_filter);
-        final List<String> list = new ArrayList<String>();
 
-        for (String name : names) {
-            String decoded = decode(name);
-            list.add(decoded);
-        }
-
-        return list.iterator();
+        return Arrays.stream(names)
+            .map(this::decode)
+            .iterator();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/data/data-library/src/main/java/org/apache/james/repository/file/ExtensionFileFilter.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/repository/file/ExtensionFileFilter.java b/server/data/data-library/src/main/java/org/apache/james/repository/file/ExtensionFileFilter.java
index a5ab933..2820a4a 100644
--- a/server/data/data-library/src/main/java/org/apache/james/repository/file/ExtensionFileFilter.java
+++ b/server/data/data-library/src/main/java/org/apache/james/repository/file/ExtensionFileFilter.java
@@ -21,6 +21,7 @@ package org.apache.james.repository.file;
 
 import java.io.File;
 import java.io.FilenameFilter;
+import java.util.Arrays;
 
 /**
  * This filters files based on the extension (what the filename ends with). This
@@ -51,11 +52,6 @@ public class ExtensionFileFilter implements FilenameFilter {
     }
 
     public boolean accept(File file, String name) {
-        for (String m_extension : m_extensions) {
-            if (name.endsWith(m_extension)) {
-                return true;
-            }
-        }
-        return false;
+        return Arrays.stream(m_extensions).anyMatch(name::endsWith);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/mailet/mailetcontainer-camel/pom.xml
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/pom.xml b/server/mailet/mailetcontainer-camel/pom.xml
index 0ec7778..0d4c959 100644
--- a/server/mailet/mailetcontainer-camel/pom.xml
+++ b/server/mailet/mailetcontainer-camel/pom.xml
@@ -88,6 +88,10 @@
             <artifactId>commons-configuration</artifactId>
         </dependency>
         <dependency>
+            <groupId>com.github.steveash.guavate</groupId>
+            <artifactId>guavate</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.sun.mail</groupId>
             <artifactId>javax.mail</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb0f621f/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
index 2086e40..7912568 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
@@ -54,6 +54,8 @@ import org.apache.mailet.base.GenericMailet;
 import org.apache.mailet.base.MatcherInverter;
 import org.slf4j.Logger;
 
+import com.github.steveash.guavate.Guavate;
+
 /**
  * Abstract base class for {@link MailProcessor} implementations which want to
  * process {@link Mail} via {@link Matcher} and {@link Mailet}
@@ -179,11 +181,9 @@ public abstract class AbstractStateMailetProcessor implements MailProcessor, Con
      * @return mailets
      */
     public List<Mailet> getMailets() {
-        List<Mailet> mailets = new ArrayList<Mailet>();
-        for (MatcherMailetPair pair : pairs) {
-            mailets.add(pair.getMailet());
-        }
-        return Collections.unmodifiableList(mailets);
+        return pairs.stream()
+            .map(MatcherMailetPair::getMailet)
+            .collect(Guavate.toImmutableList());
     }
 
     /**
@@ -192,11 +192,9 @@ public abstract class AbstractStateMailetProcessor implements MailProcessor, Con
      * @return matchers
      */
     public List<Matcher> getMatchers() {
-        List<Matcher> matchers = new ArrayList<Matcher>();
-        for (MatcherMailetPair pair : pairs) {
-            matchers.add(pair.getMatcher());
-        }
-        return Collections.unmodifiableList(matchers);
+        return pairs.stream()
+            .map(MatcherMailetPair::getMatcher)
+            .collect(Guavate.toImmutableList());
     }
 
     public void addListener(MailetProcessorListener listener) {


---------------------------------------------------------------------
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