From b4a34efc2f6a7fa734b103b67e7aff96b200da1d Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Tue, 28 Feb 2017 15:22:17 +0100 Subject: [PATCH] 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(+) diff --git a/gee/arraylist.vala b/gee/arraylist.vala index 51a0a1d47..3a7193bfb 100644 --- a/gee/arraylist.vala +++ b/gee/arraylist.vala @@ -525,6 +525,8 @@ public class Vala.ArrayList : AbstractBidirList { return wrap_float ((float?[])data); } else if (t == typeof (double)) { return wrap_double ((double?[])data); + } else if (t.is_enum () || t.is_flags ()) { + return wrap_int ((int[])data); } else { return (owned)data; } diff --git a/gee/collection.vala b/gee/collection.vala index cd9c6eafa..91699d855 100644 --- a/gee/collection.vala +++ b/gee/collection.vala @@ -179,6 +179,8 @@ public interface Vala.Collection : Iterable { return (G[]) to_float_array ((Collection) this); } else if (t == typeof (double)) { return (G[]) to_double_array ((Collection) this); + } else if (t.is_enum () || t.is_flags ()) { + return (G[]) to_int_array ((Collection) this); } else { G[] array = new G[size]; int index = 0; @@ -222,6 +224,8 @@ public interface Vala.Collection : Iterable { return add_all_float_array ((Collection) this, (float? [])array); } else if (t == typeof (double)) { return add_all_double_array ((Collection) this, (double? [])array); + } else if (t.is_enum () || t.is_flags ()) { + return add_all_int_array ((Collection) this, (int [])array); } else { bool changed = false; foreach (unowned G item in array) { @@ -265,6 +269,8 @@ public interface Vala.Collection : Iterable { return contains_all_float_array ((Collection) this, (float? [])array); } else if (t == typeof (double)) { return contains_all_double_array ((Collection) this, (double? [])array); + } else if (t.is_enum () || t.is_flags ()) { + return contains_all_int_array ((Collection) this, (int [])array); } else { foreach (unowned G item in array) { if (!contains (item)) { @@ -311,6 +317,8 @@ public interface Vala.Collection : Iterable { return remove_all_float_array ((Collection) this, (float? [])array); } else if (t == typeof (double)) { return remove_all_double_array ((Collection) this, (double? [])array); + } else if (t.is_enum () || t.is_flags ()) { + return remove_all_int_array ((Collection) this, (int [])array); } else { bool changed = false; foreach (unowned G item in array) { diff --git a/gee/traversable.vala b/gee/traversable.vala index f046d68e1..81aee2939 100644 --- a/gee/traversable.vala +++ b/gee/traversable.vala @@ -443,6 +443,112 @@ public interface Vala.Traversable : 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 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 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 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 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 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 order_by (owned CompareDataFunc? compare = null) { + ArrayList result = new ArrayList (); + this.foreach ((item) => result.add (item)); + result.sort (compare); + return result.iterator (); + } + public enum Stream { YIELD, CONTINUE, -- 2.47.2