]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Update internal gee from libgee 0.20.0
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 28 Feb 2017 14:22:17 +0000 (15:22 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 3 May 2017 08:14:50 +0000 (10:14 +0200)
gee/arraylist.vala
gee/collection.vala
gee/traversable.vala

index 51a0a1d470f2d6ded76de471e0fdf72de4090f8d..3a7193bfbc4695fb5b7b25f7f9bb1632a86f08de 100644 (file)
@@ -525,6 +525,8 @@ public class Vala.ArrayList<G> : AbstractBidirList<G> {
                        return wrap_float<G> ((float?[])data);
                } else if (t == typeof (double)) {
                        return wrap_double<G> ((double?[])data);
+               } else if (t.is_enum () || t.is_flags ()) {
+                       return wrap_int<G> ((int[])data);
                } else {
                        return (owned)data;
                }
index cd9c6eafac011254d1ad745aa8b93254d396199d..91699d8554cb87b72156001a1bc9358ce44ba5cb 100644 (file)
@@ -179,6 +179,8 @@ public interface Vala.Collection<G> : Iterable<G> {
                        return (G[]) to_float_array ((Collection<float>) this);
                } else if (t == typeof (double)) {
                        return (G[]) to_double_array ((Collection<double>) this);
+               } else if (t.is_enum () || t.is_flags ()) {
+                       return (G[]) to_int_array ((Collection<int>) this);
                } else {
                        G[] array = new G[size];
                        int index = 0;
@@ -222,6 +224,8 @@ public interface Vala.Collection<G> : Iterable<G> {
                        return add_all_float_array ((Collection<float>) this, (float? [])array);
                } else if (t == typeof (double)) {
                        return add_all_double_array ((Collection<double>) this, (double? [])array);
+               } else if (t.is_enum () || t.is_flags ()) {
+                       return add_all_int_array ((Collection<int>) this, (int [])array);
                } else {
                        bool changed = false;
                        foreach (unowned G item in array) {
@@ -265,6 +269,8 @@ public interface Vala.Collection<G> : Iterable<G> {
                        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 if (t.is_enum () || t.is_flags ()) {
+                       return contains_all_int_array ((Collection<int>) this, (int [])array);
                } else {
                        foreach (unowned G item in array) {
                                if (!contains (item)) {
@@ -311,6 +317,8 @@ public interface Vala.Collection<G> : Iterable<G> {
                        return remove_all_float_array ((Collection<float>) this, (float? [])array);
                } else if (t == typeof (double)) {
                        return remove_all_double_array ((Collection<double>) this, (double? [])array);
+               } else if (t.is_enum () || t.is_flags ()) {
+                       return remove_all_int_array ((Collection<int>) this, (int [])array);
                } else {
                        bool changed = false;
                        foreach (unowned G item in array) {
index f046d68e122480bc763f7c0f93ac3004df3c8e0d..81aee29394b8c9d2369596c26cd627a61a85ce6a 100644 (file)
@@ -443,6 +443,112 @@ public interface Vala.Traversable<G> : Object {
                }
        }
 
+       /**
+        * Returns the first element that matches a given condition
+        *
+        * @param pred Predicate to be called to check for matches
+        * @return The first element that matches or null
+        */
+       [CCode (ordering = 10)]
+       public virtual G? first_match (owned Predicate<G> pred) {
+               G? result = null;
+               this.foreach ((item) => {
+                       if (pred (item)) {
+                               result = item;
+                               return false;
+                       }
+                       return true;
+               });
+               return (owned) result;
+       }
+
+       /**
+        * Returns whether any element matches the given predicate.
+        *
+        * This is similar to @first_match, with the difference that it
+        * just returns whether there is a match or not, not the value
+        * of the match.
+        *
+        * @param pred Predicate to be called to check for matches
+        * @return Whether there was a match or not
+        */
+       [CCode (ordering = 11)]
+       public virtual bool any_match (owned Predicate<G> pred) {
+               return this.first_match (pred) != null;
+       }
+
+       /**
+        * Checks whether all elements match the given predicate.
+        *
+        * @param pred Predicate to be called to check for matches
+        * @return Whether all elements match or not
+        */
+       [CCode (ordering = 12)]
+       public virtual bool all_match (owned Predicate<G> pred) {
+               bool result = true;
+               this.foreach ((item) => {
+                       if (!pred (item)) {
+                               result = false;
+                               return false;
+                       }
+                       return true;
+               });
+               return result;
+       }
+
+       /**
+        * Returns the item in the sequence that contains the max value
+        * based on the given compare function.
+        *
+        * @param compare Function to be called for comparisons
+        * @return The item containing the max value.
+        */
+       [CCode (ordering = 13)]
+       public virtual G max (owned CompareDataFunc<G> compare) {
+               G max_value = null;
+               this.foreach ((item) => {
+                       if (max_value == null || compare (max_value, item) > 0) {
+                               max_value = item;
+                       }
+                       return true;
+               });
+               return max_value;
+       }
+
+       /**
+        * Returns the item in the sequence that contains the min value
+        * based on the given compare function.
+        *
+        * @param compare Function to be called for comparisons
+        * @return The item containing the min value.
+        */
+       [CCode (ordering = 14)]
+       public virtual G min (owned CompareDataFunc<G> compare) {
+               G min_value = null;
+               this.foreach ((item) => {
+                       if (min_value == null || compare (min_value, item) < 0) {
+                               min_value = item;
+                       }
+                       return true;
+               });
+               return min_value;
+       }
+
+       /**
+        * Returns a new iterator containing the elements in the source
+        * ordered as specified by the comparison function.
+        *
+        * @param compare Comparison function
+        * @return A new iterator with the source elements sorted.
+        */
+       [CCode (ordering = 15)]
+       public virtual Iterator<G> order_by (owned CompareDataFunc<G>? compare = null) {
+               ArrayList<G> result = new ArrayList<G> ();
+               this.foreach ((item) => result.add (item));
+               result.sort (compare);
+               return result.iterator ();
+       }
+
        public enum Stream {
                YIELD,
                CONTINUE,