james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject svn commit: r1711983 - in /james/project/trunk/server/data: data-api/src/main/java/org/apache/james/rrt/lib/ data-library/src/main/java/org/apache/james/rrt/lib/ data-library/src/test/java/org/apache/james/rrt/lib/
Date Mon, 02 Nov 2015 13:46:31 GMT
Author: matthieu
Date: Mon Nov  2 13:46:31 2015
New Revision: 1711983

URL: http://svn.apache.org/viewvc?rev=1711983&view=rev
Log:
JAMES-1595 Mappings is now a list of Mapping obj, start using it

Added:
    james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java
      - copied, changed from r1711982, james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
    james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
      - copied, changed from r1711982, james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
Modified:
    james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
    james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
    james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java

Copied: james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java
(from r1711982, james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java)
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java?p2=james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java&p1=james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java&r1=1711982&r2=1711983&rev=1711983&view=diff
==============================================================================
--- james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
(original)
+++ james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mapping.java
Mon Nov  2 13:46:31 2015
@@ -21,16 +21,8 @@
 package org.apache.james.rrt.lib;
 
 
-public interface Mappings {
+public interface Mapping {
 
-    boolean contains(String mapping);
+    String asString();
 
-    int size();
-
-    Mappings remove(String mapping);
-
-    boolean isEmpty();
-
-    Iterable<String> asStrings();
-    
 }
\ No newline at end of file

Modified: james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java?rev=1711983&r1=1711982&r2=1711983&view=diff
==============================================================================
--- james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
(original)
+++ james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
Mon Nov  2 13:46:31 2015
@@ -21,7 +21,7 @@
 package org.apache.james.rrt.lib;
 
 
-public interface Mappings {
+public interface Mappings extends Iterable<Mapping> {
 
     boolean contains(String mapping);
 

Copied: james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
(from r1711982, james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java)
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java?p2=james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java&p1=james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java&r1=1711982&r2=1711983&rev=1711983&view=diff
==============================================================================
--- james/project/trunk/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
(original)
+++ james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
Mon Nov  2 13:46:31 2015
@@ -20,17 +20,38 @@
 
 package org.apache.james.rrt.lib;
 
+import com.google.common.base.Objects;
 
-public interface Mappings {
 
-    boolean contains(String mapping);
+public class MappingImpl implements Mapping {
 
-    int size();
+    public static MappingImpl of(String mapping) {
+        return new MappingImpl(mapping);
+    }
 
-    Mappings remove(String mapping);
+    private final String mapping;
 
-    boolean isEmpty();
-
-    Iterable<String> asStrings();
+    public MappingImpl(String mapping) {
+        this.mapping = mapping;
+    }
+    
+    @Override
+    public String asString() {
+        return mapping;
+    }
+    
+    @Override
+    public boolean equals(Object other) {
+        if (other instanceof MappingImpl) {
+            MappingImpl otherMapping = (MappingImpl) other;
+            return Objects.equal(mapping, otherMapping.mapping);
+        }
+        return false;
+    }
+    
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(mapping);
+    }
     
 }
\ No newline at end of file

Modified: james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java?rev=1711983&r1=1711982&r2=1711983&view=diff
==============================================================================
--- james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
(original)
+++ james/project/trunk/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
Mon Nov  2 13:46:31 2015
@@ -25,17 +25,19 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.StringTokenizer;
 
+import com.google.common.base.Function;
+import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 
 public class MappingsImpl implements Mappings {
 
     public static MappingsImpl empty() {
-        return new MappingsImpl(new ArrayList<String>());
+        return builder().build();
     }
     
     public static MappingsImpl fromRawString(String raw) {
-        return new MappingsImpl(mappingToCollection(raw));
+        return fromCollection(mappingToCollection(raw));
     }
     
     private static ArrayList<String> mappingToCollection(String rawMapping) {
@@ -48,8 +50,12 @@ public class MappingsImpl implements Map
         return map;
     }
     
-    public static Mappings fromCollection(Collection<String> mappings) {
-        return new MappingsImpl(mappings);
+    public static MappingsImpl fromCollection(Collection<String> mappings) {
+        Builder builder = builder();
+        for (String mapping: mappings) {
+            builder.add(mapping);
+        }
+        return builder.build();
     }
     
     public static Builder from(Mappings from) {
@@ -64,37 +70,42 @@ public class MappingsImpl implements Map
     
     public static class Builder {
         
-        private final ImmutableList.Builder<String> mappings;
+        private final ImmutableList.Builder<Mapping> mappings;
         
         private Builder() {
             mappings = ImmutableList.builder();
         }
 
         public Builder add(String mapping) {
-            mappings.add(mapping);
+            mappings.add(MappingImpl.of(mapping));
             return this;
         }
 
         public Builder addAll(Mappings mappings) {
-            this.mappings.addAll(mappings.asStrings());
+            this.mappings.addAll(mappings);
             return this;
         }
         
-        public Mappings build() {
+        public MappingsImpl build() {
             return new MappingsImpl(mappings.build());
         }
         
     }
     
-    private final ImmutableList<String> mappings;
+    private final ImmutableList<Mapping> mappings;
 
-    private MappingsImpl(Collection<String> mappings) {
+    private MappingsImpl(Collection<Mapping> mappings) {
         this.mappings = ImmutableList.copyOf(mappings);
     }
     
     @Override
     public Iterable<String> asStrings() {
-        return mappings;
+        return FluentIterable.from(mappings).transform(new Function<Mapping, String>()
{
+            @Override
+            public String apply(Mapping input) {
+                return input.asString();
+            }
+        });
     }
 
     @Override
@@ -108,11 +119,12 @@ public class MappingsImpl implements Map
     }
 
     @Override
-    public Mappings remove(String mapping) {
+    public Mappings remove(String mappingAsString) {
+        MappingImpl mapping = MappingImpl.of(mappingAsString);
         if (mappings.contains(mapping)) {
-            ArrayList<String> updatedMappings = Lists.newArrayList(mappings);
+            ArrayList<Mapping> updatedMappings = Lists.newArrayList(mappings);
             updatedMappings.remove(mapping);
-            return MappingsImpl.fromCollection(updatedMappings);
+            return new MappingsImpl(updatedMappings);
         }
         return this;
     }
@@ -121,5 +133,10 @@ public class MappingsImpl implements Map
     public boolean isEmpty() {
         return mappings.isEmpty();
     }
+    
+    @Override
+    public Iterator<Mapping> iterator() {
+        return mappings.iterator();
+    }
 
 }
\ No newline at end of file

Modified: james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java?rev=1711983&r1=1711982&r2=1711983&view=diff
==============================================================================
--- james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
(original)
+++ james/project/trunk/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
Mon Nov  2 13:46:31 2015
@@ -112,7 +112,7 @@ public class RewriteTablesStepdefs {
 
     @Then("mappings for user \"([^\"]*)\" at domain \"([^\"]*)\" should be empty")
     public void assertMappingsIsEmpty(String user, String domain) throws Throwable {
-        assertThat(rewriteTable.getMappings(user, domain).asStrings()).isNullOrEmpty();
+        assertThat(rewriteTable.getMappings(user, domain)).isNullOrEmpty();
     }
 
     @Then("mappings for user \"([^\"]*)\" at domain \"([^\"]*)\" should contains only \"([^\"]*)\"")



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