[folks] Change PostalAddress.types to be a Set<string>



commit 42992e45d4441de8378f2c15ae6de157ff9b0ab2
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Wed Apr 20 11:22:18 2011 +0100

    Change PostalAddress.types to be a Set<string>
    
    Helps: bgo#640092

 NEWS                                               |    1 +
 backends/tracker/lib/trf-persona-store.vala        |    4 +-
 backends/tracker/lib/trf-persona.vala              |    4 +-
 folks/postal-address-details.vala                  |   25 +++++++++++--------
 tests/tracker/add-persona.vala                     |    4 +-
 .../tracker/postal-address-details-interface.vala  |    2 +-
 tests/tracker/set-postal-addresses.vala            |    4 +-
 7 files changed, 24 insertions(+), 20 deletions(-)
---
diff --git a/NEWS b/NEWS
index 6ac78c2..6cdcb34 100644
--- a/NEWS
+++ b/NEWS
@@ -45,6 +45,7 @@ API changes:
 * NoteDetails.notes now has type Set<Note>
 * RoleDetails.roles now has type Set<Role>
 * PotentialMatch.known_email_aliases now has type Set<string>
+* PostalAddress.types now has type Set<string>
 
 Overview of changes from libfolks 0.4.0 to libfolks 0.5.0
 =========================================================
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index 86e43b7..0ce7695 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -1700,11 +1700,11 @@ public class Trf.PersonaStore : Folks.PersonaStore
               var country = cursor.get_string
                   (Trf.AfflInfoFields.AFFL_COUNTRY).dup ();
 
-              GLib.List<string> types = new GLib.List<string> ();
+              var types = new HashSet<string> ();
 
               affl_info.postal_address = new Folks.PostalAddress (
                   po_box, extension, street, locality, region, postal_code,
-                  country, null, (owned) types, affl_info.affl_tracker_id);
+                  country, null, types, affl_info.affl_tracker_id);
 
               affl_info.email = cursor.get_string
                   (Trf.AfflInfoFields.AFFL_EMAIL).dup ();
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 0251195..da5c01f 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -550,7 +550,7 @@ public class Trf.Persona : Folks.Persona,
           if (address_empty)
             continue;
 
-          GLib.List<string> types = new GLib.List<string> ();
+          var types = new HashSet<string> ();
 
           var pa = new PostalAddress (a_info[Trf.PostalAddressFields.POBOX],
               a_info[Trf.PostalAddressFields.EXTENDED_ADDRESS],
@@ -559,7 +559,7 @@ public class Trf.Persona : Folks.Persona,
               a_info[Trf.PostalAddressFields.REGION],
               a_info[Trf.PostalAddressFields.POSTALCODE],
               a_info[Trf.PostalAddressFields.COUNTRY],
-              null, (owned) types,
+              null, types,
               a_info[Trf.PostalAddressFields.TRACKER_ID]);
 
           postal_addresses.add (pa);
diff --git a/folks/postal-address-details.vala b/folks/postal-address-details.vala
index 86a35d6..8ac7de4 100644
--- a/folks/postal-address-details.vala
+++ b/folks/postal-address-details.vala
@@ -128,22 +128,22 @@ public class Folks.PostalAddress : Object
       construct set { _address_format = (value != null ? value : ""); }
     }
 
-  private GLib.List<string> _types;
+  private HashSet<string> _types;
+
   /**
    * The types of the address.
    *
    * The types of address, for instance an address can be a home or work
    * address.
    */
-  public GLib.List<string> types
+  public Set<string> types
     {
       get { return this._types; }
       construct set
         {
-          this._types = new GLib.List<string> ();
-          foreach (unowned string type in value)
-            this._types.prepend (type);
-          this._types.reverse ();
+          this._types = new HashSet<string> ();
+          foreach (var type in value)
+            this._types.add (type);
         }
     }
 
@@ -169,10 +169,11 @@ public class Folks.PostalAddress : Object
    * @param region the region (state or province) name
    * @param postal_code the postal code
    * @param address_format the address format
+   * @since UNRELEASED
    */
   public PostalAddress (string? po_box, string? extension, string? street,
       string? locality, string? region, string? postal_code, string? country,
-      string? address_format, GLib.List<string> types, string? uid)
+      string? address_format, Set<string> types, string? uid)
     {
       Object (po_box:         po_box,
               extension:      extension,
@@ -196,14 +197,16 @@ public class Folks.PostalAddress : Object
           this.postal_code != with.postal_code ||
           this.country != with.country ||
           this.address_format != with.address_format ||
-          this.types.length () != with.types.length () ||
+          this.types.size != with.types.size ||
           this.uid != with.uid)
         return false;
 
-      for (int i=0; i<this.types.length (); i++)
+      foreach (var type in this.types)
         {
-          if (this.types.nth_data (i) != with.types.nth_data (i))
-            return false;
+          if (with.types.contains (type) == false)
+            {
+              return false;
+            }
         }
 
       return true;
diff --git a/tests/tracker/add-persona.vala b/tests/tracker/add-persona.vala
index cc6bc39..cd67287 100644
--- a/tests/tracker/add-persona.vala
+++ b/tests/tracker/add-persona.vala
@@ -96,7 +96,7 @@ public class AddPersonaTests : Folks.TestCase
       this._title_1 = "CFO";
       this._organisation_1 = "Example Inc.";
 
-      GLib.List<string> types =  new GLib.List<string> ();
+      var types =  new HashSet<string> ();
       this._address = new PostalAddress (this._po_box,
           this._extension, this._street, this._locality, this._region,
           this._postal_code, this._country, null, types, null);
@@ -270,7 +270,7 @@ public class AddPersonaTests : Folks.TestCase
       Value? v13 = Value (typeof (Set<PostalAddress>));
       var postal_addresses = new HashSet<PostalAddress> ();
 
-      GLib.List<string> types =  new GLib.List<string> ();
+      var types =  new HashSet<string> ();
       PostalAddress postal_a = new PostalAddress (this._po_box,
           this._extension, this._street, this._locality, this._region,
           this._postal_code, this._country, null, types, null);
diff --git a/tests/tracker/postal-address-details-interface.vala b/tests/tracker/postal-address-details-interface.vala
index dd021c2..e35138c 100644
--- a/tests/tracker/postal-address-details-interface.vala
+++ b/tests/tracker/postal-address-details-interface.vala
@@ -67,7 +67,7 @@ public class PostalAddressDetailsInterfaceTests : Folks.TestCase
       this._fullname = "persona #1";
       c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname);
 
-      GLib.List<string> types = new GLib.List<string> ();
+      var types = new HashSet<string> ();
       this._postal_address = new PostalAddress (
            this._pobox,
            this._extended,
diff --git a/tests/tracker/set-postal-addresses.vala b/tests/tracker/set-postal-addresses.vala
index ef00a81..7e36e6c 100644
--- a/tests/tracker/set-postal-addresses.vala
+++ b/tests/tracker/set-postal-addresses.vala
@@ -59,7 +59,7 @@ public class SetPostalAddressesTests : Folks.TestCase
       c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname);
       this._tracker_backend.add_contact (c1);
 
-      GLib.List<string> types =  new GLib.List<string> ();
+      var types =  new HashSet<string> ();
       this._address = new PostalAddress (null, null, null, null, null,
           null, null, null, types, null);
       this._address.po_box = "12345";
@@ -119,7 +119,7 @@ public class SetPostalAddressesTests : Folks.TestCase
             {
               i.notify["postal-addresses"].connect (this._notify_postal_cb);
 
-              GLib.List<string> types =  new GLib.List<string> ();
+              var types =  new HashSet<string> ();
               var addresses = new HashSet<PostalAddress> ();
               var pa = new Folks.PostalAddress (null, null, null, null, null,
                 null, null, null, types, null);



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