[geary/wip/713891-traversable] CR changes



commit 374b8a3aec1266d6b7a93627f1ac037187226512
Author: Charles Lindsay <chaz yorba org>
Date:   Thu Dec 12 12:36:06 2013 -0800

    CR changes

 src/engine/api/geary-search-folder.vala |    2 +-
 src/engine/util/util-iterable.vala      |   32 ++++++++++++------------------
 2 files changed, 14 insertions(+), 20 deletions(-)
---
diff --git a/src/engine/api/geary-search-folder.vala b/src/engine/api/geary-search-folder.vala
index cdd7a47..499d0a4 100644
--- a/src/engine/api/geary-search-folder.vala
+++ b/src/engine/api/geary-search-folder.vala
@@ -103,7 +103,7 @@ public class Geary.SearchFolder : Geary.AbstractLocalFolder, Geary.FolderSupport
         
         // This shouldn't require a result_mutex lock since there's no yield.
         Gee.TreeSet<ImapDB.SearchEmailIdentifier> in_folder = Geary.traverse<Geary.EmailIdentifier>(ids)
-            .cast<ImapDB.SearchEmailIdentifier>()
+            .cast_object<ImapDB.SearchEmailIdentifier>()
             .filter(id => id in search_results)
             .to_tree_set();
         
diff --git a/src/engine/util/util-iterable.vala b/src/engine/util/util-iterable.vala
index 52343e7..4c5ad05 100644
--- a/src/engine/util/util-iterable.vala
+++ b/src/engine/util/util-iterable.vala
@@ -19,6 +19,7 @@ namespace Geary {
  * requires that map/filter/etc. return Iterators, not Iterables.  It still
  * works in foreach.
  */
+
 public class Geary.Iterable<G> : BaseObject {
     private Gee.Iterator<G> i;
     
@@ -50,7 +51,11 @@ public class Geary.Iterable<G> : BaseObject {
         return new Iterable<A>(i.map<A>(f).filter(g => g != null));
     }
     
-    public Iterable<A> cast<A>() {
+    /**
+     * Return only objects of the destination type, as the destination type.
+     * Only works on types derived from Object.
+     */
+    public Iterable<A> cast_object<A>() {
         return new Iterable<G>(
             // This would be a lot simpler if valac didn't barf on the shorter,
             // more obvious syntax for each of these delegates here.
@@ -59,9 +64,7 @@ public class Geary.Iterable<G> : BaseObject {
     }
     
     public G? first() {
-        if (!i.next())
-            return null;
-        return i.get();
+        return (i.next() ? i  get() : null);
     }
     
     public G? first_matching(owned Gee.Predicate<G> f) {
@@ -104,28 +107,20 @@ public class Geary.Iterable<G> : BaseObject {
     }
     
     public Gee.ArrayList<G> to_array_list(owned Gee.EqualDataFunc<G>? equal_func = null) {
-        Gee.ArrayList<G> c = new Gee.ArrayList<G>(equal_func);
-        add_all_to(c);
-        return c;
+        return (Gee.ArrayList<G>) add_all_to(new Gee.ArrayList<G>(equal_func));
     }
     
     public Gee.LinkedList<G> to_linked_list(owned Gee.EqualDataFunc<G>? equal_func = null) {
-        Gee.LinkedList<G> c = new Gee.LinkedList<G>(equal_func);
-        add_all_to(c);
-        return c;
+        return (Gee.LinkedList<G>) add_all_to(new Gee.LinkedList<G>(equal_func));
     }
     
     public Gee.HashSet<G> to_hash_set(owned Gee.HashDataFunc<G>? hash_func = null,
         owned Gee.EqualDataFunc<G>? equal_func = null) {
-        Gee.HashSet<G> c = new Gee.HashSet<G>(hash_func, equal_func);
-        add_all_to(c);
-        return c;
+        return (Gee.HashSet<G>) add_all_to(new Gee.HashSet<G>(hash_func, equal_func));
     }
     
     public Gee.TreeSet<G> to_tree_set(owned CompareDataFunc<G>? compare_func = null) {
-        Gee.TreeSet<G> c = new Gee.TreeSet<G>(compare_func);
-        add_all_to(c);
-        return c;
+        return (Gee.TreeSet<G>) add_all_to(new Gee.TreeSet<G>(compare_func));
     }
     
     public Gee.Map<K, G> add_all_to_map<K>(Gee.Map<K, G> c, Gee.MapFunc<K, G> key_func) {
@@ -140,8 +135,7 @@ public class Geary.Iterable<G> : BaseObject {
         owned Gee.HashDataFunc<K>? key_hash_func = null,
         owned Gee.EqualDataFunc<K>? key_equal_func = null,
         owned Gee.EqualDataFunc<G>? value_equal_func = null) {
-        Gee.HashMap<K, G> c = new Gee.HashMap<K, G>(key_hash_func, key_equal_func, value_equal_func);
-        add_all_to_map<K>(c, key_func);
-        return c;
+        return (Gee.HashMap<K, G>) add_all_to_map<K>(new Gee.HashMap<K, G>(
+            key_hash_func, key_equal_func, value_equal_func), key_func);
     }
 }


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