[geary/wip/713891-traversable: 5/12] Using Traversable in couple more arbitrary files



commit 3b68f74673aeb882ee1ff4fcf6cb24f45fd3e0c6
Author: Charles Lindsay <chaz yorba org>
Date:   Wed Dec 11 16:59:12 2013 -0800

    Using Traversable in couple more arbitrary files

 src/engine/api/geary-named-flags.vala   |   29 ++++++++---------------------
 src/engine/imap/message/imap-flags.vala |    7 +------
 2 files changed, 9 insertions(+), 27 deletions(-)
---
diff --git a/src/engine/api/geary-named-flags.vala b/src/engine/api/geary-named-flags.vala
index f3c069c..ed4e93e 100644
--- a/src/engine/api/geary-named-flags.vala
+++ b/src/engine/api/geary-named-flags.vala
@@ -34,11 +34,7 @@ public class Geary.NamedFlags : BaseObject, Gee.Hashable<Geary.NamedFlags> {
     }
     
     public bool contains_any(NamedFlags flags) {
-        foreach(NamedFlag nf in list)
-            if (flags.contains(nf))
-                return true;
-        
-        return false;
+        return Geary.traverse<NamedFlag>(list).any(f => flags.contains(f));
     }
     
     public Gee.Set<NamedFlag> get_all() {
@@ -53,11 +49,9 @@ public class Geary.NamedFlags : BaseObject, Gee.Hashable<Geary.NamedFlags> {
     }
     
     public virtual void add_all(NamedFlags flags) {
-        Gee.ArrayList<NamedFlag> added = new Gee.ArrayList<NamedFlag>();
-        foreach (NamedFlag flag in flags.get_all()) {
-            if (!list.contains(flag))
-                added.add(flag);
-        }
+        Gee.ArrayList<NamedFlag> added = Geary.traverse<NamedFlag>(flags.get_all())
+            .filter(f => !list.contains(f))
+            .to_array_list();
         
         list.add_all(added);
         notify_added(added);
@@ -72,11 +66,9 @@ public class Geary.NamedFlags : BaseObject, Gee.Hashable<Geary.NamedFlags> {
     }
     
     public virtual bool remove_all(NamedFlags flags) {
-        Gee.ArrayList<NamedFlag> removed = new Gee.ArrayList<NamedFlag>();
-        foreach (NamedFlag flag in flags.get_all()) {
-            if (list.contains(flag))
-                removed.add(flag);
-        }
+        Gee.ArrayList<NamedFlag> removed = Geary.traverse<NamedFlag>(flags.get_all())
+            .filter(f => list.contains(f))
+            .to_array_list();
         
         list.remove_all(removed);
         notify_removed(removed);
@@ -91,12 +83,7 @@ public class Geary.NamedFlags : BaseObject, Gee.Hashable<Geary.NamedFlags> {
         if (list.size != other.list.size)
             return false;
         
-        foreach (NamedFlag flag in list) {
-            if (!other.contains(flag))
-                return false;
-        }
-        
-        return true;
+        return Geary.traverse<NamedFlag>(list).all(f => other.contains(f));
     }
     
     public uint hash() {
diff --git a/src/engine/imap/message/imap-flags.vala b/src/engine/imap/message/imap-flags.vala
index 42f0997..303419f 100644
--- a/src/engine/imap/message/imap-flags.vala
+++ b/src/engine/imap/message/imap-flags.vala
@@ -55,12 +55,7 @@ public abstract class Geary.Imap.Flags : Geary.MessageData.AbstractMessageData,
         if (other.size != size)
             return false;
         
-        foreach (Flag flag in list) {
-            if (!other.contains(flag))
-                return false;
-        }
-        
-        return true;
+        return Geary.traverse<Flag>(list).all(f => other.contains(f));
     }
     
     public override string to_string() {


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