brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [4/7] git commit: Adds MutableList.builder.addAll(V[])
Date Wed, 29 Oct 2014 16:19:45 GMT
Adds MutableList.builder.addAll(V[])


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/b59cbd4e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/b59cbd4e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/b59cbd4e

Branch: refs/heads/master
Commit: b59cbd4e53e7aa625294a1bf2fd00bf29ac4cd7a
Parents: e9b22a4
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Oct 28 23:33:01 2014 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Oct 29 16:01:37 2014 +0000

----------------------------------------------------------------------
 .../brooklyn/util/collections/MutableList.java  |  7 ++++
 .../util/collections/MutableListTest.java       | 40 ++++++++++++++++++++
 2 files changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b59cbd4e/utils/common/src/main/java/brooklyn/util/collections/MutableList.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/collections/MutableList.java b/utils/common/src/main/java/brooklyn/util/collections/MutableList.java
index 1c1b2d2..c467f0e 100644
--- a/utils/common/src/main/java/brooklyn/util/collections/MutableList.java
+++ b/utils/common/src/main/java/brooklyn/util/collections/MutableList.java
@@ -154,6 +154,13 @@ public class MutableList<V> extends ArrayList<V> {
             return this;
         }
 
+        public Builder<V> addAll(V[] vals) {
+            for (V v : vals) {
+                result.add(v);
+            }
+            return this;
+        }
+
         public Builder<V> removeAll(Iterable<? extends V> iterable) {
             if (iterable instanceof Collection) {
                 result.removeAll((Collection<? extends V>) iterable);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b59cbd4e/utils/common/src/test/java/brooklyn/util/collections/MutableListTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/brooklyn/util/collections/MutableListTest.java b/utils/common/src/test/java/brooklyn/util/collections/MutableListTest.java
index e7dc5bf..c862e7f 100644
--- a/utils/common/src/test/java/brooklyn/util/collections/MutableListTest.java
+++ b/utils/common/src/test/java/brooklyn/util/collections/MutableListTest.java
@@ -24,9 +24,49 @@ import java.util.List;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+import com.google.common.collect.ImmutableList;
+
 @Test
 public class MutableListTest {
 
+    public void testBuilderAddArray() throws Exception {
+        List<Object> vals = MutableList.builder().addAll(new Object[] {1,2,3}).build();
+        Assert.assertEquals(vals, ImmutableList.of(1,2,3));
+    }
+    
+    public void testBuilderAddVarargs() throws Exception {
+        List<Object> vals = MutableList.builder().add(1,2,3).build();
+        Assert.assertEquals(vals, ImmutableList.of(1,2,3));
+    }
+    
+    public void testBuilderAddIterable() throws Exception {
+        List<Object> vals = MutableList.builder().addAll(ImmutableList.of(1,2)).addAll(ImmutableList.of(2,3)).build();
+        Assert.assertEquals(vals, ImmutableList.of(1,2,2,3));
+    }
+    
+    public void testBuilderAddIterator() throws Exception {
+        List<Object> vals = MutableList.builder().addAll(ImmutableList.of(1,2).iterator()).build();
+        Assert.assertEquals(vals, ImmutableList.of(1,2));
+    }
+    
+    public void testBuilderRemoval() throws Exception {
+        List<Object> vals = MutableList.builder()
+                .add(1,2,3)
+                .remove(2)
+                .add(4)
+                .build();
+        Assert.assertEquals(vals, ImmutableList.of(1,3,4));
+    }
+    
+    public void testBuilderRemoveAll() throws Exception {
+        List<Object> vals = MutableList.builder()
+                .add(1,2,3)
+                .removeAll(ImmutableList.of(2,3))
+                .add(4)
+                .build();
+        Assert.assertEquals(vals, ImmutableList.of(1,4));
+    }
+    
     public void testEqualsExact() {
         List<Object> a = MutableList.<Object>of("a", 1, "b", false);
         List<Object> b = MutableList.<Object>of("a", 1, "b", false);


Mime
View raw message