Reviewers: scottb,

Message:
Review requested.

Description:
This is a convenience method for the permutation reduction work.

Please review this at http://gwt-code-reviews.appspot.com/56806

Affected files:
   M dev/core/src/com/google/gwt/dev/util/collect/Sets.java


Index: dev/core/src/com/google/gwt/dev/util/collect/Sets.java
diff --git a/dev/core/src/com/google/gwt/dev/util/collect/Sets.java  
b/dev/core/src/com/google/gwt/dev/util/collect/Sets.java
index  
b98d3d812a965bf3fbcbb6ae32f7c1d1bf698e43..c2d8501037e5ad2fbc05702b3d06fe2234dfe0b0
  
100644
--- a/dev/core/src/com/google/gwt/dev/util/collect/Sets.java
+++ b/dev/core/src/com/google/gwt/dev/util/collect/Sets.java
@@ -15,6 +15,7 @@
   */
  package com.google.gwt.dev.util.collect;

+import java.util.Collection;
  import java.util.Collections;
  import java.util.Set;

@@ -51,6 +52,38 @@ public class Sets {
      }
    }

+  public static <T> Set<T> addAll(Set<T> set, Collection<T> toAdd) {
+    if (toAdd.isEmpty()) {
+      // No-op
+      return set;
+
+    } else if (set.containsAll(toAdd)) {
+      // No-op
+      return set;
+    }
+
+    switch (set.size()) {
+      case 0:
+        if (toAdd.size() == 1) {
+          // Empty -> Singleton
+          return create(toAdd.iterator().next());
+        } else {
+          // Empty -> HashSet
+          return new HashSet<T>(toAdd);
+        }
+      case 1: {
+        // Singleton -> HashSet
+        Set<T> result = new HashSet<T>(toAdd);
+        result.add(set.iterator().next());
+        return result;
+      }
+      default:
+        // HashSet
+        set.addAll(toAdd);
+        return set;
+    }
+  }
+
    public static <T> Set<T> create() {
      return Collections.emptySet();
    }



--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to