diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2017-02-28 15:22:17 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2017-05-03 10:14:50 +0200 |
commit | b4a34efc2f6a7fa734b103b67e7aff96b200da1d (patch) | |
tree | de67e7d312fca4b469a4db0712885bd22f25c214 | |
parent | b7148f8c267a7eddc3a2ab9e8c894c9160c375af (diff) | |
download | vala-b4a34efc2f6a7fa734b103b67e7aff96b200da1d.tar.gz |
Update internal gee from libgee 0.20.0
-rw-r--r-- | gee/arraylist.vala | 2 | ||||
-rw-r--r-- | gee/collection.vala | 8 | ||||
-rw-r--r-- | gee/traversable.vala | 106 |
3 files changed, 116 insertions, 0 deletions
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<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 cd9c6eafa..91699d855 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 f046d68e1..81aee2939 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, |