[vala/wip/gee: 102/103] Update internal gee from libgee 0.20.0



commit b4a34efc2f6a7fa734b103b67e7aff96b200da1d
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Feb 28 15:22:17 2017 +0100

    Update internal gee from libgee 0.20.0

 gee/arraylist.vala   |    2 +
 gee/collection.vala  |    8 ++++
 gee/traversable.vala |  106 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+), 0 deletions(-)
---
diff --git a/gee/arraylist.vala b/gee/arraylist.vala
index 51a0a1d..3a7193b 100644
--- a/gee/arraylist.vala
+++ b/gee/arraylist.vala
@@ -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;
                }
diff --git a/gee/collection.vala b/gee/collection.vala
index cd9c6ea..91699d8 100644
--- a/gee/collection.vala
+++ b/gee/collection.vala
@@ -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) {
diff --git a/gee/traversable.vala b/gee/traversable.vala
index f046d68..81aee29 100644
--- a/gee/traversable.vala
+++ b/gee/traversable.vala
@@ -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,


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