MAILET-130 SetMailAttribute upgrade to new style

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

Branch: refs/heads/master
Commit: 12eb738dea700de6c838a37fc149afaa8e53f0bf
Parents: 9b1dd0b
Author: Matthieu Baechler <matthieu.baech...@linagora.com>
Authored: Mon Aug 29 17:26:21 2016 +0200
Committer: Matthieu Baechler <matthieu.baech...@linagora.com>
Committed: Tue Sep 20 09:12:10 2016 +0200

----------------------------------------------------------------------
 .../transport/mailets/SetMailAttribute.java     | 45 ++++++--------------
 1 file changed, 13 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/12eb738d/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMailAttribute.java
----------------------------------------------------------------------
diff --git 
a/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMailAttribute.java
 
b/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMailAttribute.java
index fd5192d..ea91948 100644
--- 
a/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMailAttribute.java
+++ 
b/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMailAttribute.java
@@ -21,10 +21,8 @@
 
 package org.apache.james.transport.mailets;
 
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Set;
 
 import javax.mail.MessagingException;
 
@@ -32,6 +30,8 @@ import org.apache.mailet.Mail;
 import org.apache.mailet.MailetException;
 import org.apache.mailet.base.GenericMailet;
 
+import com.google.common.collect.ImmutableMap;
+
 /**
  * <p>This mailet sets attributes on the Mail.</p>
  * 
@@ -43,52 +43,33 @@ import org.apache.mailet.base.GenericMailet;
  * &lt;/mailet&gt;
  * </code></pre>
  *
- * @version CVS $Revision$ $Date$
  * @since 2.2.0
  */
 public class SetMailAttribute extends GenericMailet {
 
-    private final HashMap<String, String> attributesToSet = new 
HashMap<String, String>(2);
-    
-    private Set<Map.Entry<String, String>> entries;
+    private ImmutableMap<String, String> entries;
     
-    /**
-     * Return a string describing this mailet.
-     *
-     * @return a string describing this mailet
-     */
+    @Override
     public String getMailetInfo() {
         return "Set Mail Attribute Mailet";
     }
 
-    /**
-     * Initialize the mailet
-     *
-     * @throws MailetException if the processor parameter is missing
-     */
-    public void init() throws MailetException
-    {
+    @Override
+    public void init() throws MailetException {
+        ImmutableMap.Builder<String, String> attributes = 
ImmutableMap.builder();
         Iterator<String> iter = getInitParameterNames();
         while (iter.hasNext()) {
             String name = iter.next();
-            String value = getInitParameter (name);
-            attributesToSet.put (name,value);
+            String value = getInitParameter(name);
+            attributes.put(name, value);
         }
-        entries = attributesToSet.entrySet();
+        entries = attributes.build();
     }
 
-    /**
-     * Sets the configured attributes
-     *
-     * @param mail the mail to process
-     *
-     * @throws MessagingException in all cases
-     */
+    @Override
     public void service(Mail mail) throws MessagingException {
-        if (entries != null) {
-            for (Map.Entry<String, String> entry : entries) {
-                mail.setAttribute(entry.getKey(), entry.getValue());
-            }
+        for (Map.Entry<String, String> entry : entries.entrySet()) {
+            mail.setAttribute(entry.getKey(), entry.getValue());
         }
     }
     


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

Reply via email to