[libgee/0.10] Fix Collection.contains_all_array for primitives



commit aaa59d155248a3b5a92a8448df6b144168a77e5b
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Sat Aug 3 10:59:22 2013 +0200

    Fix Collection.contains_all_array for primitives

 gee/collection.vala |  132 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 128 insertions(+), 4 deletions(-)
---
diff --git a/gee/collection.vala b/gee/collection.vala
index d6a2db8..1c1ec9b 100644
--- a/gee/collection.vala
+++ b/gee/collection.vala
@@ -230,12 +230,37 @@ public interface Gee.Collection<G> : Iterable<G> {
         */
        public bool contains_all_array (G[] array) {
                // FIXME: Change to virtual after bug #693455 is fixed
-               foreach (unowned G item in array) {
-                       if (!contains (item)) {
-                               return false;
+               var t = typeof (G);
+               if (t == typeof (bool)) {
+                       return contains_all_bool_array ((Collection<bool>) this, (bool [])array);
+               } else if (t == typeof (char)) {
+                       return contains_all_char_array ((Collection<char>) this, (char [])array);
+               } else if (t == typeof (uchar)) {
+                       return contains_all_uchar_array ((Collection<uchar>) this, (uchar [])array);
+               } else if (t == typeof (int)) {
+                       return contains_all_int_array ((Collection<int>) this, (int [])array);
+               } else if (t == typeof (uint)) {
+                       return contains_all_uint_array ((Collection<uint>) this, (uint [])array);
+               } else if (t == typeof (int64)) {
+                       return contains_all_int64_array ((Collection<int64?>) this, (int64? [])array);
+               } else if (t == typeof (uint64)) {
+                       return contains_all_uint64_array ((Collection<uint64?>) this, (uint64? [])array);
+               } else if (t == typeof (long)) {
+                       return contains_all_long_array ((Collection<long>) this, (long [])array);
+               } else if (t == typeof (ulong)) {
+                       return contains_all_ulong_array ((Collection<ulong>) this, (ulong [])array);
+               } else if (t == typeof (float)) {
+                       return contains_all_float_array ((Collection<float>) this, (float? [])array);
+               } else if (t == typeof (double)) {
+                       return contains_all_double_array ((Collection<double>) this, (double? [])array);
+               } else {
+                       foreach (unowned G item in array) {
+                               if (!contains (item)) {
+                                       return false;
+                               }
                        }
+                       return true;
                }
-               return true;
        }
 
        /**
@@ -458,5 +483,104 @@ public interface Gee.Collection<G> : Iterable<G> {
                }
                return changed;
        }
+
+       private static bool contains_all_bool_array (Collection<bool> coll, bool[] arr) {
+               foreach (bool el in arr) {
+                       if (!coll.contains (el)) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       private static bool contains_all_char_array (Collection<char> coll, char[] arr) {
+               foreach (char el in arr) {
+                       if (!coll.contains (el)) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       private static bool contains_all_uchar_array (Collection<uchar> coll, uchar[] arr) {
+               foreach (uchar el in arr) {
+                       if (!coll.contains (el)) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       private static bool contains_all_int_array (Collection<int> coll, int[] arr) {
+               foreach (int el in arr) {
+                       if (!coll.contains (el)) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       private static bool contains_all_uint_array (Collection<uint> coll, uint[] arr) {
+               foreach (uint el in arr) {
+                       if (!coll.contains (el)) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       private static bool contains_all_int64_array (Collection<int64?> coll, int64?[] arr) {
+               foreach (unowned int64? el in arr) {
+                       if (!coll.contains (el)) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       private static bool contains_all_uint64_array (Collection<uint64?> coll, uint64?[] arr) {
+               foreach (unowned uint64? el in arr) {
+                       if (!coll.contains (el)) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       private static bool contains_all_long_array (Collection<long> coll, long[] arr) {
+               foreach (long el in arr) {
+                       if (!coll.contains (el)) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       private static bool contains_all_ulong_array (Collection<ulong> coll, ulong[] arr) {
+               foreach (ulong el in arr) {
+                       if (!coll.contains (el)) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       private static bool contains_all_float_array (Collection<float?> coll, float?[] arr) {
+               foreach (unowned float? el in arr) {
+                       if (!coll.contains (el)) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       private static bool contains_all_double_array (Collection<double?> coll, double?[] arr) {
+               foreach (unowned double? el in arr) {
+                       if (!coll.contains (el)) {
+                               return false;
+                       }
+               }
+               return true;
+       }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]