[folks] Change PostalAddressDetails.postal_addresses to be a Set<PostalAddress>



commit f912d31414251e3a87616cdedb46d1d3015ccd53
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Tue Apr 19 21:41:20 2011 +0100

    Change PostalAddressDetails.postal_addresses to be a Set<PostalAddress>
    
    Helps: bgo#640092

 NEWS                                        |    1 +
 backends/tracker/lib/trf-persona-store.vala |   66 +++++++++++++--------------
 backends/tracker/lib/trf-persona.vala       |   27 +++++-------
 folks/individual.vala                       |   17 +++----
 folks/postal-address-details.vala           |   13 +++--
 tests/tracker/add-persona.vala              |    9 ++--
 tests/tracker/set-postal-addresses.vala     |    7 +--
 tools/inspect/utils.vala                    |    4 +-
 8 files changed, 68 insertions(+), 76 deletions(-)
---
diff --git a/NEWS b/NEWS
index 7a06e05..1dce30b 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ API changes:
 * FieldDetails.parameters is now of type MultiMap<string, string>
 * FieldDetails.get_parameter_values() now returns type Collection<string>
 * FieldDetails.extend_parameters() now takes type MultiMap<string, string>
+* PostalAddressDetails.postal_addresses is now of type Set<PostalAddress>
 
 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 9a4fb8f..ed024e6 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -583,8 +583,8 @@ public class Trf.PersonaStore : Folks.PersonaStore
           else if (k == Folks.PersonaStore.detail_key (
                 PersonaDetail.POSTAL_ADDRESSES))
             {
-              unowned GLib.List<PostalAddress> postal_addresses =
-                (GLib.List<PostalAddress>) v.get_pointer ();
+              Set<PostalAddress> postal_addresses =
+                (Set<PostalAddress>) v.get_object ();
 
               int postal_cnt = 0;
               foreach (var pa in postal_addresses)
@@ -2011,9 +2011,9 @@ public class Trf.PersonaStore : Folks.PersonaStore
     }
 
   internal async void _set_postal_addresses (Folks.Persona persona,
-      owned GLib.List<PostalAddress> postal_addresses)
+      Set<PostalAddress> postal_addresses)
     {
-       yield this._set_attrib (persona, (owned) postal_addresses,
+       yield this._set_attrib_set (persona, postal_addresses,
           Trf.Attrib.POSTAL_ADDRESSES);
     }
 
@@ -2288,11 +2288,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
           case Trf.Attrib.IM_ADDRESSES:
             assert_not_reached ();
           case Trf.Attrib.POSTAL_ADDRESSES:
-            related_attrib = Trf.OntologyDefs.NCO_POSTAL_ADDRESS;
-            related_connection = Trf.OntologyDefs.NCO_HAS_POSTAL_ADDRESS;
-            yield this._remove_attributes_from_persona (persona,
-                _REMOVE_POSTALS);
-            break;
+            assert_not_reached ();
         }
 
       var builder = new Tracker.Sparql.Builder.update ();
@@ -2301,34 +2297,11 @@ public class Trf.PersonaStore : Folks.PersonaStore
       foreach (var p in attribs)
         {
           FieldDetails fd = null;
-          PostalAddress pa = null;
 
           string affl = "_:a%d".printf (i);
           string attr;
 
-          if (what == Trf.Attrib.POSTAL_ADDRESSES)
-            {
-              pa = (PostalAddress) p;
-              attr = "_:p%d".printf (i);
-              builder.subject (attr);
-              builder.predicate ("a");
-              builder.object (related_attrib);
-              builder.predicate (Trf.OntologyDefs.NCO_POBOX);
-              builder.object_string (pa.po_box);
-              builder.predicate (Trf.OntologyDefs.NCO_LOCALITY);
-              builder.object_string (pa.locality);
-              builder.predicate (Trf.OntologyDefs.NCO_POSTALCODE);
-              builder.object_string (pa.postal_code);
-              builder.predicate (Trf.OntologyDefs.NCO_STREET_ADDRESS);
-              builder.object_string (pa.street);
-              builder.predicate (Trf.OntologyDefs.NCO_EXTENDED_ADDRESS);
-              builder.object_string (pa.extension);
-              builder.predicate (Trf.OntologyDefs.NCO_COUNTRY);
-              builder.object_string (pa.country);
-              builder.predicate (Trf.OntologyDefs.NCO_REGION);
-              builder.object_string (pa.region);
-            }
-          else if (what == Trf.Attrib.URLS)
+          if (what == Trf.Attrib.URLS)
             {
               fd = (FieldDetails) p;
               var type_p = fd.get_parameter_values ("type");
@@ -2408,6 +2381,11 @@ public class Trf.PersonaStore : Folks.PersonaStore
                 _REMOVE_IM_ADDRS);
             break;
           case Trf.Attrib.POSTAL_ADDRESSES:
+            related_attrib = Trf.OntologyDefs.NCO_POSTAL_ADDRESS;
+            related_connection = Trf.OntologyDefs.NCO_HAS_POSTAL_ADDRESS;
+            yield this._remove_attributes_from_persona (persona,
+                _REMOVE_POSTALS);
+            break;
           case Trf.Attrib.URLS:
             assert_not_reached ();
         }
@@ -2421,11 +2399,31 @@ public class Trf.PersonaStore : Folks.PersonaStore
           PostalAddress pa = null;
 
           string affl = "_:a%d".printf (i);
-          string attr;
+          string attr = null;
 
           switch (what)
             {
               case Trf.Attrib.POSTAL_ADDRESSES:
+                pa = (PostalAddress) p;
+                attr = "_:p%d".printf (i);
+                builder.subject (attr);
+                builder.predicate ("a");
+                builder.object (related_attrib);
+                builder.predicate (Trf.OntologyDefs.NCO_POBOX);
+                builder.object_string (pa.po_box);
+                builder.predicate (Trf.OntologyDefs.NCO_LOCALITY);
+                builder.object_string (pa.locality);
+                builder.predicate (Trf.OntologyDefs.NCO_POSTALCODE);
+                builder.object_string (pa.postal_code);
+                builder.predicate (Trf.OntologyDefs.NCO_STREET_ADDRESS);
+                builder.object_string (pa.street);
+                builder.predicate (Trf.OntologyDefs.NCO_EXTENDED_ADDRESS);
+                builder.object_string (pa.extension);
+                builder.predicate (Trf.OntologyDefs.NCO_COUNTRY);
+                builder.object_string (pa.country);
+                builder.predicate (Trf.OntologyDefs.NCO_REGION);
+                builder.object_string (pa.region);
+                break;
               case Trf.Attrib.URLS:
                 assert_not_reached ();
               case Trf.Attrib.IM_ADDRESSES:
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 91e8919..eb738f3 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -249,21 +249,18 @@ public class Trf.Persona : Folks.Persona,
         }
     }
 
-  private GLib.List<PostalAddress> _postal_addresses =
-      new GLib.List<PostalAddress> ();
+  private HashSet<PostalAddress> _postal_addresses =
+      new HashSet<PostalAddress> ();
+
   /**
    * { inheritDoc}
    */
-  public GLib.List<PostalAddress> postal_addresses
+  public Set<PostalAddress> postal_addresses
     {
       get { return this._postal_addresses; }
       private set
         {
-          var _temp = new GLib.List<PostalAddress> ();
-          foreach (unowned PostalAddress e in value)
-              _temp.prepend (e);
-          ((Trf.PersonaStore) this.store)._set_postal_addresses (this,
-              (owned) _temp);
+          ((Trf.PersonaStore) this.store)._set_postal_addresses (this, value);
         }
     }
 
@@ -553,8 +550,7 @@ public class Trf.Persona : Folks.Persona,
           return;
         }
 
-      GLib.List<PostalAddress> postal_addresses =
-          new GLib.List<PostalAddress> ();
+      var postal_addresses = new HashSet<PostalAddress> ();
 
       string[] addresses_a = postal_field.split ("\n");
 
@@ -586,11 +582,10 @@ public class Trf.Persona : Folks.Persona,
               null, (owned) types,
               a_info[Trf.PostalAddressFields.TRACKER_ID]);
 
-          postal_addresses.prepend ((owned) pa);
+          postal_addresses.add (pa);
         }
 
-      postal_addresses.reverse ();
-      this._postal_addresses = (owned) postal_addresses;
+      this._postal_addresses = postal_addresses;
     }
 
  private void _update_local_ids ()
@@ -608,7 +603,7 @@ public class Trf.Persona : Folks.Persona,
 
   internal bool _add_postal_address (PostalAddress postal_address)
     {
-      foreach (unowned PostalAddress pa in this._postal_addresses)
+      foreach (var pa in this._postal_addresses)
         {
           if (postal_address.equal (pa))
             {
@@ -616,14 +611,14 @@ public class Trf.Persona : Folks.Persona,
             }
         }
 
-      this._postal_addresses.append (postal_address);
+      this._postal_addresses.add (postal_address);
       this.notify_property ("postal-addresses");
       return true;
     }
 
   internal bool _remove_postal_address (string tracker_id)
     {
-      foreach (unowned PostalAddress pa in this._postal_addresses)
+      foreach (var pa in this._postal_addresses)
         {
           if (pa.uid == tracker_id)
             {
diff --git a/folks/individual.vala b/folks/individual.vala
index 5e67770..08d9c47 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -350,19 +350,18 @@ public class Folks.Individual : Object,
         }
     }
 
-  private GLib.List<PostalAddress> _postal_addresses;
+  private HashSet<PostalAddress> _postal_addresses;
   /**
    * { inheritDoc}
    */
-  public GLib.List<PostalAddress> postal_addresses
+  public Set<PostalAddress> postal_addresses
     {
       get { return this._postal_addresses; }
       private set
         {
-          this._postal_addresses = new GLib.List<PostalAddress> ();
+          this._postal_addresses = new HashSet<PostalAddress> ();
           foreach (PostalAddress pa in value)
-            this._postal_addresses.prepend (pa);
-          this._postal_addresses.reverse ();
+            this._postal_addresses.add (pa);
         }
     }
 
@@ -1297,19 +1296,17 @@ public class Folks.Individual : Object,
 
   private void _update_postal_addresses ()
     {
-      this._postal_addresses = new GLib.List<PostalAddress> ();
+      this._postal_addresses = new HashSet<PostalAddress> ();
       /* FIXME: Detect duplicates somehow? */
       foreach (var persona in this._persona_list)
         {
           var address_details = persona as PostalAddressDetails;
           if (address_details != null)
             {
-              foreach (unowned PostalAddress pa in
-                  address_details.postal_addresses)
-                this._postal_addresses.append (pa);
+              foreach (var pa in address_details.postal_addresses)
+                this._postal_addresses.add (pa);
             }
         }
-      this._postal_addresses.reverse ();
 
       this.notify_property ("postal-addresses");
     }
diff --git a/folks/postal-address-details.vala b/folks/postal-address-details.vala
index dbe9f1f..86a35d6 100644
--- a/folks/postal-address-details.vala
+++ b/folks/postal-address-details.vala
@@ -20,6 +20,7 @@
  */
 
 using GLib;
+using Gee;
 
 /**
  * Object representing a postal mail address.
@@ -127,19 +128,19 @@ public class Folks.PostalAddress : Object
       construct set { _address_format = (value != null ? value : ""); }
     }
 
-  private List<string> _types;
+  private GLib.List<string> _types;
   /**
    * The types of the address.
    *
    * The types of address, for instance an address can be a home or work
    * address.
    */
-  public List<string> types
+  public GLib.List<string> types
     {
       get { return this._types; }
       construct set
         {
-          this._types = new List<string> ();
+          this._types = new GLib.List<string> ();
           foreach (unowned string type in value)
             this._types.prepend (type);
           this._types.reverse ();
@@ -171,7 +172,7 @@ public class Folks.PostalAddress : Object
    */
   public PostalAddress (string? po_box, string? extension, string? street,
       string? locality, string? region, string? postal_code, string? country,
-      string? address_format, List<string> types, string? uid)
+      string? address_format, GLib.List<string> types, string? uid)
     {
       Object (po_box:         po_box,
               extension:      extension,
@@ -231,6 +232,8 @@ public interface Folks.PostalAddressDetails : Object
    * The postal addresses of the contact.
    *
    * A list of postal addresses associated to the contact.
+   *
+   * @since UNRELEASED
    */
-  public abstract List<PostalAddress> postal_addresses { get; set; }
+  public abstract Set<PostalAddress> postal_addresses { get; set; }
 }
diff --git a/tests/tracker/add-persona.vala b/tests/tracker/add-persona.vala
index 5d8f4a3..aedd1a2 100644
--- a/tests/tracker/add-persona.vala
+++ b/tests/tracker/add-persona.vala
@@ -269,16 +269,15 @@ public class AddPersonaTests : Folks.TestCase
       details.insert (Folks.PersonaStore.detail_key (PersonaDetail.ROLES),
           (owned) v12);
 
-      Value? v13 = Value (typeof (GLib.List<PostalAddress>));
-      GLib.List<PostalAddress> postal_addresses =
-        new GLib.List<PostalAddress> ();
+      Value? v13 = Value (typeof (Set<PostalAddress>));
+      var postal_addresses = new HashSet<PostalAddress> ();
 
       GLib.List<string> types =  new GLib.List<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);
-      postal_addresses.prepend ((owned) postal_a);
-      v13.set_pointer (postal_addresses);
+      postal_addresses.add (postal_a);
+      v13.set_object (postal_addresses);
       details.insert (
           Folks.PersonaStore.detail_key (PersonaDetail.POSTAL_ADDRESSES),
           (owned) v13);
diff --git a/tests/tracker/set-postal-addresses.vala b/tests/tracker/set-postal-addresses.vala
index f887b1a..deb74b4 100644
--- a/tests/tracker/set-postal-addresses.vala
+++ b/tests/tracker/set-postal-addresses.vala
@@ -120,8 +120,7 @@ public class SetPostalAddressesTests : Folks.TestCase
               i.notify["postal-addresses"].connect (this._notify_postal_cb);
 
               GLib.List<string> types =  new GLib.List<string> ();
-              GLib.List<PostalAddress> addresses =
-                new GLib.List<PostalAddress> ();
+              var addresses = new HashSet<PostalAddress> ();
               var pa = new Folks.PostalAddress (null, null, null, null, null,
                 null, null, null, types, null);
               pa.po_box = this._address.po_box;
@@ -132,7 +131,7 @@ public class SetPostalAddressesTests : Folks.TestCase
               pa.country = this._address.country;
               pa.region  = this._address.region;
 
-              addresses.prepend ((owned) pa);
+              addresses.add (pa);
 
               Trf.Persona p = (Trf.Persona)i.personas.nth_data (0);
               p.postal_addresses = (owned) addresses;
@@ -147,7 +146,7 @@ public class SetPostalAddressesTests : Folks.TestCase
       Folks.Individual i = (Folks.Individual) individual_obj;
       if (i.full_name == this._persona_fullname)
         {
-          foreach (unowned PostalAddress p in i.postal_addresses)
+          foreach (var p in i.postal_addresses)
             {
               /* we don't care if UIDs differ for this test */
               this._address.uid = p.uid;
diff --git a/tools/inspect/utils.vala b/tools/inspect/utils.vala
index 37351e4..a1ea495 100644
--- a/tools/inspect/utils.vala
+++ b/tools/inspect/utils.vala
@@ -354,8 +354,8 @@ private class Folks.Inspect.Utils
         {
           output_string = "{ ";
           bool first = true;
-          unowned GLib.List<PostalAddress> prop_list =
-              (GLib.List<PostalAddress>) prop_value.get_pointer ();
+          Set<PostalAddress> prop_list =
+              (Set<PostalAddress>) prop_value.get_object ();
 
           foreach (var p in prop_list)
             {



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