[geary/wip/713891-traversable: 8/12] Add/use to_linked_list



commit 33cde3d894236057d94653885c1761091ddebce8
Author: Charles Lindsay <chaz yorba org>
Date:   Wed Dec 11 17:46:44 2013 -0800

    Add/use to_linked_list

 src/client/application/geary-controller.vala |    8 +++-----
 src/engine/util/util-traversable.vala        |    6 ++++++
 2 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index af171d6..1a8068e 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -1967,11 +1967,9 @@ public class GearyController : Geary.BaseObject {
     
     // Returns a list of composer windows for an account, or null if none.
     public Gee.List<ComposerWindow>? get_composer_windows_for_account(Geary.AccountInformation account) {
-        Gee.List<ComposerWindow> ret = new Gee.LinkedList<ComposerWindow>();
-        foreach (ComposerWindow cw in composer_windows) {
-            if (cw.account.information == account)
-                ret.add(cw);
-        }
+        Gee.LinkedList<ComposerWindow> ret = Geary.traverse<ComposerWindow>(composer_windows)
+            .filter(w => w.account.information == account)
+            .to_linked_list();
         
         return ret.size >= 1 ? ret : null;
     }
diff --git a/src/engine/util/util-traversable.vala b/src/engine/util/util-traversable.vala
index 9d80cbc..ff5fb34 100644
--- a/src/engine/util/util-traversable.vala
+++ b/src/engine/util/util-traversable.vala
@@ -111,6 +111,12 @@ public class Iterable<G> : BaseObject {
         return c;
     }
     
+    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;
+    }
+    
     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);


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