[folks] Implement FieldDetails.equal()/hash() in terms of the default.
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Implement FieldDetails.equal()/hash() in terms of the default.
- Date: Fri, 12 Aug 2011 15:56:31 +0000 (UTC)
commit 486a993849b4bf6a1bef6937af62e642d4bfbfec
Author: Travis Reitter <travis reitter collabora co uk>
Date: Wed Jul 13 15:35:00 2011 -0700
Implement FieldDetails.equal()/hash() in terms of the default.
This allows explicit references to FieldDetails.equal()/hash() for
structures storing them (in case it changes from the
AbstractFieldDetails implementation in the future).
Helps: bgo#653679 - Change PostalAddressDetails.postal_addresses to
support vCard-like arbitrary parameters
backends/libsocialweb/lib/swf-persona.vala | 7 +++++--
backends/tracker/lib/trf-persona.vala | 21 +++++++++++++++------
folks/field-details.vala | 20 ++++++++++++++++++++
folks/individual.vala | 20 ++++++++++++++------
tests/tracker/add-persona.vala | 9 ++++++---
tests/tracker/duplicated-emails.vala | 8 ++++++--
tests/tracker/duplicated-phones.vala | 8 ++++++--
tests/tracker/match-email-addresses.vala | 8 ++++++--
tests/tracker/match-known-emails.vala | 8 ++++++--
tests/tracker/match-phone-number.vala | 8 ++++++--
tests/tracker/remove-persona.vala | 3 ++-
tests/tracker/set-duplicate-email.vala | 8 ++++++--
tests/tracker/set-emails.vala | 4 +++-
tests/tracker/set-phones.vala | 4 +++-
tests/tracker/set-urls.vala | 4 +++-
15 files changed, 107 insertions(+), 33 deletions(-)
---
diff --git a/backends/libsocialweb/lib/swf-persona.vala b/backends/libsocialweb/lib/swf-persona.vala
index 2a5062a..489dac6 100644
--- a/backends/libsocialweb/lib/swf-persona.vala
+++ b/backends/libsocialweb/lib/swf-persona.vala
@@ -107,7 +107,9 @@ public class Swf.Persona : Folks.Persona,
get { return this._urls_ro; }
private set
{
- this._urls = new HashSet<FieldDetails> ();
+ this._urls = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
this._urls_ro = this._urls.read_only_view;
foreach (var ps in value)
this._urls.add (ps);
@@ -295,7 +297,8 @@ public class Swf.Persona : Folks.Persona,
if (this.full_name != full_name)
this.full_name = full_name;
- var urls = new HashSet<FieldDetails> ();
+ var urls = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var website = contact.get_value ("url");
if (website != null)
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 72c722f..338d63f 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -404,9 +404,13 @@ public class Trf.Persona : Folks.Persona,
this._full_name = fullname;
this._tracker_id = tracker_id;
this._structured_name = new StructuredName (null, null, null, null, null);
- this._phone_numbers = new HashSet<FieldDetails> ();
+ this._phone_numbers = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
this._phone_numbers_ro = this._phone_numbers.read_only_view;
- this._email_addresses = new HashSet<FieldDetails> ();
+ this._email_addresses = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
this._email_addresses_ro = this._email_addresses.read_only_view;
this._roles = new HashSet<Role> ((GLib.HashFunc) Role.hash,
(GLib.EqualFunc) Role.equal);
@@ -414,7 +418,8 @@ public class Trf.Persona : Folks.Persona,
this._notes = new HashSet<Note> ((GLib.HashFunc) Note.hash,
(GLib.EqualFunc) Note.equal);
this._notes_ro = this._notes.read_only_view;
- this._urls = new HashSet<FieldDetails> ();
+ this._urls = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
this._urls_ro = this._urls.read_only_view;
this._postal_addresses = new HashSet<PostalAddress> ();
this._postal_addresses_ro = this._postal_addresses.read_only_view;
@@ -962,7 +967,8 @@ public class Trf.Persona : Folks.Persona,
return;
}
- var phones = new HashSet<FieldDetails> ();
+ var phones = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
string[] phones_a = phones_field.split ("\n");
foreach (var p in phones_a)
@@ -1082,7 +1088,9 @@ public class Trf.Persona : Folks.Persona,
return;
}
- var email_addresses = new HashSet<FieldDetails> ();
+ var email_addresses = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
string[] emails_a = emails_field.split (",");
foreach (var e in emails_a)
@@ -1103,7 +1111,8 @@ public class Trf.Persona : Folks.Persona,
private void _update_urls ()
{
- var urls = new HashSet<FieldDetails> ();
+ var urls = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var _urls_field = this._cursor.get_string (Trf.Fields.URLS).dup ();
if (_urls_field == null)
diff --git a/folks/field-details.vala b/folks/field-details.vala
index 8a62969..3a1dddb 100644
--- a/folks/field-details.vala
+++ b/folks/field-details.vala
@@ -49,4 +49,24 @@ public class Folks.FieldDetails : AbstractFieldDetails<string>
{
this.value = value;
}
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public override bool equal (AbstractFieldDetails<string> that)
+ {
+ return base.equal<string> (that);
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public override uint hash ()
+ {
+ return base.hash ();
+ }
}
diff --git a/folks/individual.vala b/folks/individual.vala
index 53db48d..6b1782d 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -694,11 +694,16 @@ public class Folks.Individual : Object,
this._persona_set_ro = this._persona_set.read_only_view;
this._stores = new HashMap<PersonaStore, uint> (null, null);
this._gender = Gender.UNSPECIFIED;
- this._urls = new HashSet<FieldDetails> ();
+ this._urls = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
this._urls_ro = this._urls.read_only_view;
- this._phone_numbers = new HashSet<FieldDetails> ();
+ this._phone_numbers = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
this._phone_numbers_ro = this._phone_numbers.read_only_view;
- this._email_addresses = new HashSet<FieldDetails> ();
+ this._email_addresses = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
this._email_addresses_ro = this._email_addresses.read_only_view;
this._roles = new HashSet<Role>
((GLib.HashFunc) Role.hash, (GLib.EqualFunc) Role.equal);
@@ -1298,7 +1303,8 @@ public class Folks.Individual : Object,
{
/* Populate the URLs as the union of our Personas' URLs.
* If the same URL exists multiple times we merge the parameters. */
- var urls_set = new HashMap<unowned string, unowned FieldDetails> ();
+ var urls_set = new HashMap<unowned string, unowned FieldDetails> (
+ null, null, (GLib.EqualFunc) FieldDetails.equal);
this._urls.clear ();
@@ -1336,7 +1342,8 @@ public class Folks.Individual : Object,
/* FIXME: We should handle phone numbers better, just string comparison
doesn't work. */
var phone_numbers_set =
- new HashMap<unowned string, unowned FieldDetails> ();
+ new HashMap<unowned string, unowned FieldDetails> (
+ null, null, (GLib.EqualFunc) FieldDetails.equal);
this._phone_numbers.clear ();
@@ -1371,7 +1378,8 @@ public class Folks.Individual : Object,
{
/* Populate the email addresses as the union of our Personas' addresses.
* If the same address exists multiple times we merge the parameters. */
- var emails_set = new HashMap<unowned string, unowned FieldDetails> ();
+ var emails_set = new HashMap<unowned string, unowned FieldDetails> (
+ null, null, (GLib.EqualFunc) FieldDetails.equal);
this._email_addresses.clear ();
diff --git a/tests/tracker/add-persona.vala b/tests/tracker/add-persona.vala
index 0d049c9..7a0df3b 100644
--- a/tests/tracker/add-persona.vala
+++ b/tests/tracker/add-persona.vala
@@ -225,7 +225,8 @@ public class AddPersonaTests : Folks.TestCase
(owned) v7);
Value? v8 = Value (typeof (Set<FieldDetails>));
- var emails = new HashSet<FieldDetails> ();
+ var emails = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var email_1 = new FieldDetails (this._email_1);
emails.add (email_1);
var email_2 = new FieldDetails (this._email_2);
@@ -252,7 +253,8 @@ public class AddPersonaTests : Folks.TestCase
(owned) v10);
Value? v11 = Value (typeof (Set<FieldDetails>));
- var phones = new HashSet<FieldDetails> ();
+ var phones = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var phone_1 = new FieldDetails (this._phone_1);
phones.add (phone_1);
var phone_2 = new FieldDetails (this._phone_2);
@@ -285,7 +287,8 @@ public class AddPersonaTests : Folks.TestCase
(owned) v13);
Value? v14 = Value (typeof (Set<FieldDetails>));
- var urls = new HashSet<FieldDetails> ();
+ var urls = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var url_1 = new FieldDetails (this._url_1);
urls.add (url_1);
var url_2 = new FieldDetails (this._url_2);
diff --git a/tests/tracker/duplicated-emails.vala b/tests/tracker/duplicated-emails.vala
index ee9d9d7..2a4cfa2 100644
--- a/tests/tracker/duplicated-emails.vala
+++ b/tests/tracker/duplicated-emails.vala
@@ -167,7 +167,9 @@ public class DuplicatedEmailsTests : Folks.TestCase
(owned) val);
val = Value (typeof (Set<FieldDetails>));
- var emails1 = new HashSet<FieldDetails> ();
+ var emails1 = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var email_1 = new FieldDetails (this._email_1);
emails1.add (email_1);
val.set_object (emails1);
@@ -181,7 +183,9 @@ public class DuplicatedEmailsTests : Folks.TestCase
(owned) val);
val = Value (typeof (Set<FieldDetails>));
- var emails2 = new HashSet<FieldDetails> ();
+ var emails2 = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var email_2 = new FieldDetails (this._email_1);
emails2.add (email_2);
val.set_object (emails2);
diff --git a/tests/tracker/duplicated-phones.vala b/tests/tracker/duplicated-phones.vala
index 75f5c7e..aa5d04a 100644
--- a/tests/tracker/duplicated-phones.vala
+++ b/tests/tracker/duplicated-phones.vala
@@ -167,7 +167,9 @@ public class DuplicatedPhonesTests : Folks.TestCase
(owned) val);
val = Value (typeof (Set<FieldDetails>));
- var phones1 = new HashSet<FieldDetails> ();
+ var phones1 = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var phone_1 = new FieldDetails (this._phone_1);
phones1.add (phone_1);
val.set_object (phones1);
@@ -181,7 +183,9 @@ public class DuplicatedPhonesTests : Folks.TestCase
(owned) val);
val = Value (typeof (Set<FieldDetails>));
- var phones2 = new HashSet<FieldDetails> ();
+ var phones2 = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var phone_2 = new FieldDetails (this._phone_1);
phones2.add (phone_2);
val.set_object (phones2);
diff --git a/tests/tracker/match-email-addresses.vala b/tests/tracker/match-email-addresses.vala
index 2c0f599..34cf12e 100644
--- a/tests/tracker/match-email-addresses.vala
+++ b/tests/tracker/match-email-addresses.vala
@@ -172,7 +172,9 @@ public class MatchEmailAddressesTests : Folks.TestCase
(owned) val);
val = Value (typeof (Set<FieldDetails>));
- var emails1 = new HashSet<FieldDetails> ();
+ var emails1 = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var email_1 = new FieldDetails (this._email_1);
emails1.add (email_1);
val.set_object (emails1);
@@ -186,7 +188,9 @@ public class MatchEmailAddressesTests : Folks.TestCase
(owned) val);
val = Value (typeof (Set<FieldDetails>));
- var emails2 = new HashSet<FieldDetails> ();
+ var emails2 = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var email_2 = new FieldDetails (this._email_1);
emails2.add (email_2);
val.set_object (emails2);
diff --git a/tests/tracker/match-known-emails.vala b/tests/tracker/match-known-emails.vala
index a6470b0..0383a7a 100644
--- a/tests/tracker/match-known-emails.vala
+++ b/tests/tracker/match-known-emails.vala
@@ -180,7 +180,9 @@ public class MatchKnownEmailsTests : Folks.TestCase
(owned) val);
val = Value (typeof (Set<FieldDetails>));
- var emails1 = new HashSet<FieldDetails> ();
+ var emails1 = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var email_1 = new FieldDetails (this._email_1);
emails1.add (email_1);
val.set_object (emails1);
@@ -194,7 +196,9 @@ public class MatchKnownEmailsTests : Folks.TestCase
(owned) val);
val = Value (typeof (Set<FieldDetails>));
- var emails2 = new HashSet<FieldDetails> ();
+ var emails2 = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var email_2 = new FieldDetails (this._email_1);
emails2.add (email_2);
val.set_object (emails2);
diff --git a/tests/tracker/match-phone-number.vala b/tests/tracker/match-phone-number.vala
index 5c124df..268592e 100644
--- a/tests/tracker/match-phone-number.vala
+++ b/tests/tracker/match-phone-number.vala
@@ -174,7 +174,9 @@ public class MatchPhoneNumberTests : Folks.TestCase
(owned) val);
val = Value (typeof (Set<FieldDetails>));
- var phone_numbers1 = new HashSet<FieldDetails> ();
+ var phone_numbers1 = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var phone_number_1 = new FieldDetails (this._phone_1);
phone_numbers1.add (phone_number_1);
val.set_object (phone_numbers1);
@@ -188,7 +190,9 @@ public class MatchPhoneNumberTests : Folks.TestCase
(owned) val);
val = Value (typeof (Set<FieldDetails>));
- var phone_numbers2 = new HashSet<FieldDetails> ();
+ var phone_numbers2 = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var phone_number_2 = new FieldDetails (this._phone_2);
phone_numbers2.add (phone_number_2);
val.set_object (phone_numbers2);
diff --git a/tests/tracker/remove-persona.vala b/tests/tracker/remove-persona.vala
index b38b1f1..7612d6b 100644
--- a/tests/tracker/remove-persona.vala
+++ b/tests/tracker/remove-persona.vala
@@ -132,7 +132,8 @@ public class RemovePersonaTests : Folks.TestCase
(owned) v1);
Value? v2 = Value (typeof (Set<FieldDetails>));
- var emails = new HashSet<FieldDetails> ();
+ var emails = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var email_1 = new FieldDetails ("test-1 example org");
emails.add (email_1);
var email_2 = new FieldDetails ("test-2 example org");
diff --git a/tests/tracker/set-duplicate-email.vala b/tests/tracker/set-duplicate-email.vala
index b5019fb..11fa3fa 100644
--- a/tests/tracker/set-duplicate-email.vala
+++ b/tests/tracker/set-duplicate-email.vala
@@ -124,7 +124,9 @@ public class SetDuplicateEmailTests : Folks.TestCase
{
if (this._has_email ((Trf.Persona) p, this._email_1))
{
- var emails1 = new HashSet<FieldDetails> ();
+ var emails1 = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var email_1 = new FieldDetails (this._email_1);
emails1.add (email_1);
((EmailDetails) p).email_addresses = emails1;
@@ -194,7 +196,9 @@ public class SetDuplicateEmailTests : Folks.TestCase
(owned) val);
val = Value (typeof (Set<FieldDetails>));
- var emails1 = new HashSet<FieldDetails> ();
+ var emails1 = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var email_1 = new FieldDetails (this._email_1);
emails1.add (email_1);
val.set_object (emails1);
diff --git a/tests/tracker/set-emails.vala b/tests/tracker/set-emails.vala
index 9e9a483..f2fd4f8 100644
--- a/tests/tracker/set-emails.vala
+++ b/tests/tracker/set-emails.vala
@@ -113,7 +113,9 @@ public class SetEmailsTests : Folks.TestCase
{
i.notify["email-addresses"].connect (this._notify_emails_cb);
- var emails = new HashSet<FieldDetails> ();
+ var emails = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var p1 = new FieldDetails (this._email_1);
emails.add (p1);
var p2 = new FieldDetails (this._email_2);
diff --git a/tests/tracker/set-phones.vala b/tests/tracker/set-phones.vala
index 70d1a53..58dceb6 100644
--- a/tests/tracker/set-phones.vala
+++ b/tests/tracker/set-phones.vala
@@ -113,7 +113,9 @@ public class SetPhonesTests : Folks.TestCase
{
i.notify["phone-numbers"].connect (this._notify_phones_cb);
- var phones = new HashSet<FieldDetails> ();
+ var phones = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var p1 = new FieldDetails (this._phone_1);
phones.add (p1);
var p2 = new FieldDetails (this._phone_2);
diff --git a/tests/tracker/set-urls.vala b/tests/tracker/set-urls.vala
index fab096a..239e23c 100644
--- a/tests/tracker/set-urls.vala
+++ b/tests/tracker/set-urls.vala
@@ -108,7 +108,9 @@ public class SetURLsTests : Folks.TestCase
{
i.notify["urls"].connect (this._notify_urls_cb);
- var urls = new HashSet<FieldDetails> ();
+ var urls = new HashSet<FieldDetails> (
+ (GLib.HashFunc) FieldDetails.hash,
+ (GLib.EqualFunc) FieldDetails.equal);
var p1 = new FieldDetails (this._urls.get ("blog"));
p1.set_parameter ("type", "blog");
urls.add (p1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]