[folks] Move SetComparator into folks/utils so it can be used by other backends
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Move SetComparator into folks/utils so it can be used by other backends
- Date: Tue, 11 Oct 2011 01:13:43 +0000 (UTC)
commit 47568e3443cfbe5bdf14cfdb24ac7c4d009c0bae
Author: Raul Gutierrez Segales <rgs collabora co uk>
Date: Mon Sep 19 18:11:56 2011 +0100
Move SetComparator into folks/utils so it can be used by other backends
Helps: https://bugzilla.gnome.org/show_bug.cgi?id=657602
backends/eds/lib/Makefile.am | 1 -
backends/eds/lib/edsf-persona-store.vala | 3 +-
backends/eds/lib/edsf-persona.vala | 22 ++++++++---------
backends/eds/lib/edsf-util.vala | 38 ------------------------------
folks/persona-store.vala | 14 +++++++++++
5 files changed, 25 insertions(+), 53 deletions(-)
---
diff --git a/backends/eds/lib/Makefile.am b/backends/eds/lib/Makefile.am
index 5aa784a..2e52c43 100644
--- a/backends/eds/lib/Makefile.am
+++ b/backends/eds/lib/Makefile.am
@@ -29,7 +29,6 @@ libfolks_eds_la_vala.stamp:
folks_eds_valasources = \
edsf-persona.vala \
edsf-persona-store.vala \
- edsf-util.vala \
memory-icon.vala \
$(NULL)
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 355116c..cf0b363 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -1481,8 +1481,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
_("Roles are not writeable on this contact."));
}
- var comp = new Edsf.SetComparator<RoleFieldDetails> ();
- if (comp.equal (roles, persona.roles))
+ if (Folks.PersonaStore.equal_sets<RoleFieldDetails> (roles, persona.roles))
return;
yield this._set_contact_roles (persona.contact, roles);
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 3101b2f..22cfc28 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -938,8 +938,7 @@ public class Edsf.Persona : Folks.Persona,
new_roles.add (role_fd);
}
- var comp = new Edsf.SetComparator<RoleFieldDetails> ();
- if (!comp.equal (new_roles, this._roles))
+ if (!Folks.PersonaStore.equal_sets<RoleFieldDetails> (new_roles, this._roles))
{
this._roles = new_roles;
this._roles_ro = new_roles.read_only_view;
@@ -1035,8 +1034,8 @@ public class Edsf.Persona : Folks.Persona,
new_email_addresses.add (email_fd);
}
- var comp = new Edsf.SetComparator<EmailFieldDetails> ();
- if (!comp.equal (new_email_addresses, this._email_addresses))
+ if (!Folks.PersonaStore.equal_sets<EmailFieldDetails> (new_email_addresses,
+ this._email_addresses))
{
this._email_addresses = new_email_addresses;
this._email_addresses_ro = new_email_addresses.read_only_view;
@@ -1057,8 +1056,7 @@ public class Edsf.Persona : Folks.Persona,
new_notes.add (note);
}
- var comp = new Edsf.SetComparator<NoteFieldDetails> ();
- if (!comp.equal (new_notes, this._notes))
+ if (!Folks.PersonaStore.equal_sets<NoteFieldDetails> (new_notes, this._notes))
{
this._notes = new_notes;
this._notes_ro = this._notes.read_only_view;
@@ -1414,8 +1412,8 @@ public class Edsf.Persona : Folks.Persona,
new_phone_numbers.add (phone_fd);
}
- var comp = new Edsf.SetComparator<PhoneFieldDetails> ();
- if (!comp.equal (new_phone_numbers, this._phone_numbers))
+ if (!Folks.PersonaStore.equal_sets<PhoneFieldDetails> (new_phone_numbers,
+ this._phone_numbers))
{
this._phone_numbers = new_phone_numbers;
this._phone_numbers_ro = new_phone_numbers.read_only_view;
@@ -1498,8 +1496,9 @@ public class Edsf.Persona : Folks.Persona,
new_postal_addresses.add (pa_fd);
}
- var comp = new Edsf.SetComparator<PostalAddressFieldDetails> ();
- if (!comp.equal (new_postal_addresses, this._postal_addresses))
+ if (!Folks.PersonaStore.equal_sets<PostalAddressFieldDetails> (
+ new_postal_addresses,
+ this._postal_addresses))
{
this._postal_addresses = new_postal_addresses;
this._postal_addresses_ro = new_postal_addresses.read_only_view;
@@ -1527,8 +1526,7 @@ public class Edsf.Persona : Folks.Persona,
/* Make sure it includes our local id */
new_local_ids.add (this.iid);
- var comp = new Edsf.SetComparator<string> ();
- if (!comp.equal (new_local_ids, this.local_ids))
+ if (!Folks.PersonaStore.equal_sets<string> (new_local_ids, this.local_ids))
{
this._local_ids = new_local_ids;
this._local_ids_ro = this._local_ids.read_only_view;
diff --git a/folks/persona-store.vala b/folks/persona-store.vala
index aa533c1..9b464a0 100644
--- a/folks/persona-store.vala
+++ b/folks/persona-store.vala
@@ -658,4 +658,18 @@ public abstract class Folks.PersonaStore : Object
* @since 0.6.3
*/
public bool is_user_set_default { get; internal set; default = false; }
+
+ public static bool equal_sets<G> (Set<G> a, Set<G> b)
+ {
+ if (a.size != b.size)
+ return false;
+
+ foreach (var a_elem in a)
+ {
+ if (!b.contains (a_elem))
+ return false;
+ }
+
+ return true;
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]