rygel r496 - in trunk/src/plugins: dvb test tracker



Author: zeeshanak
Date: Wed Jan 28 12:33:20 2009
New Revision: 496
URL: http://svn.gnome.org/viewvc/rygel?rev=496&view=rev

Log:
Drop slice_object_list() in favor of Gee.List.slice().

Modified:
   trunk/src/plugins/dvb/rygel-dvb-content-dir.vala
   trunk/src/plugins/test/rygel-test-content-dir.vala
   trunk/src/plugins/tracker/rygel-media-tracker.vala

Modified: trunk/src/plugins/dvb/rygel-dvb-content-dir.vala
==============================================================================
--- trunk/src/plugins/dvb/rygel-dvb-content-dir.vala	(original)
+++ trunk/src/plugins/dvb/rygel-dvb-content-dir.vala	Wed Jan 28 12:33:20 2009
@@ -126,16 +126,25 @@
             throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
         }
 
+        Gee.List<MediaObject> children = null;
+
         var channels = group.get_channels (offset,
                                            max_count,
                                            out child_count);
         if (max_count == 0 && offset == 0) {
-            return channels;
+            children = channels;
         } else {
-            return slice_object_list (channels,
-                                      offset,
-                                      max_count);
+            uint stop = offset + max_count;
+
+            stop = stop.clamp (0, child_count);
+            children = channels.slice ((int) offset, (int) stop);
+        }
+
+        if (children == null) {
+            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
         }
+
+        return (ArrayList<MediaObject>) children;
     }
 
     public override ArrayList<MediaObject> get_root_children (
@@ -145,19 +154,22 @@
                                                  throws GLib.Error {
         child_count = this.groups.size;
 
-        ArrayList<MediaObject> children;
+        Gee.List<MediaObject> children = null;
 
         if (max_count == 0 && offset == 0) {
             children = this.groups;
-        } else if (offset >= child_count) {
-            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
         } else {
-            children = slice_object_list (this.groups,
-                                          offset,
-                                          max_count);
+            uint stop = offset + max_count;
+
+            stop = stop.clamp (0, child_count);
+            children = this.groups.slice ((int) offset, (int) stop);
         }
 
-        return children;
+        if (children == null) {
+            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
+        }
+
+        return (ArrayList<MediaObject>) children;
     }
 
     // Private methods
@@ -187,25 +199,5 @@
 
         return channel;
     }
-
-    private ArrayList<MediaObject> slice_object_list (
-                                        ArrayList<MediaObject> list,
-                                        uint                   offset,
-                                        uint                   max_count) {
-        uint total = list.size;
-
-        var slice = new ArrayList<MediaObject> ();
-
-        if (max_count == 0 || max_count > (total - offset)) {
-            max_count = total - offset;
-        }
-
-        slice = new ArrayList<MediaObject> ();
-        for (uint i = offset; i < total; i++) {
-            slice.add (list[(int) i]);
-        }
-
-        return slice;
-    }
 }
 

Modified: trunk/src/plugins/test/rygel-test-content-dir.vala
==============================================================================
--- trunk/src/plugins/test/rygel-test-content-dir.vala	(original)
+++ trunk/src/plugins/test/rygel-test-content-dir.vala	Wed Jan 28 12:33:20 2009
@@ -61,19 +61,22 @@
                                                  throws GLib.Error {
         child_count = this.items.size;
 
-        ArrayList<MediaObject> children;
+        Gee.List<MediaObject> children = null;
 
         if (max_count == 0 && offset == 0) {
             children = this.items;
-        } else if (offset >= child_count) {
-            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
         } else {
-            children = slice_object_list (this.items,
-                                          offset,
-                                          max_count);
+            uint stop = offset + max_count;
+
+            stop = stop.clamp (0, child_count);
+            children = this.items.slice ((int) offset, (int) stop);
         }
 
-        return children;
+        if (children == null) {
+            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
+        }
+
+        return (ArrayList<MediaObject>) children;
     }
 
     public override MediaObject find_object_by_id (string object_id)
@@ -109,25 +112,5 @@
             return;
         }
     }
-
-    private ArrayList<MediaObject> slice_object_list (
-                                        ArrayList<MediaObject> list,
-                                        uint                   offset,
-                                        uint                   max_count) {
-        uint total = list.size;
-
-        var slice = new ArrayList<MediaObject> ();
-
-        if (max_count == 0 || max_count > (total - offset)) {
-            max_count = total - offset;
-        }
-
-        slice = new ArrayList<MediaObject> ();
-        for (uint i = offset; i < total; i++) {
-            slice.add (list[(int) i]);
-        }
-
-        return slice;
-    }
 }
 

Modified: trunk/src/plugins/tracker/rygel-media-tracker.vala
==============================================================================
--- trunk/src/plugins/tracker/rygel-media-tracker.vala	(original)
+++ trunk/src/plugins/tracker/rygel-media-tracker.vala	Wed Jan 28 12:33:20 2009
@@ -112,19 +112,22 @@
                                                  throws GLib.Error {
         child_count = this.containers.size;
 
-        ArrayList<MediaObject> children;
+        Gee.List<MediaObject> children = null;
 
         if (max_count == 0 && offset == 0) {
             children = this.containers;
-        } else if (offset >= child_count) {
-            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
         } else {
-            children = slice_object_list (this.containers,
-                                          offset,
-                                          max_count);
+            uint stop = offset + max_count;
+
+            stop = stop.clamp (0, child_count);
+            children = this.containers.slice ((int) offset, (int) stop);
         }
 
-        return children;
+        if (children == null) {
+            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
+        }
+
+        return (ArrayList<MediaObject>) children;
     }
 
     /* Private methods */
@@ -167,25 +170,5 @@
 
         return container;
     }
-
-    private ArrayList<MediaObject> slice_object_list (
-                                        ArrayList<MediaObject> list,
-                                        uint                   offset,
-                                        uint                   max_count) {
-        uint total = list.size;
-
-        var slice = new ArrayList<MediaObject> ();
-
-        if (max_count == 0 || max_count > (total - offset)) {
-            max_count = total - offset;
-        }
-
-        slice = new ArrayList<MediaObject> ();
-        for (uint i = offset; i < total; i++) {
-            slice.add (list[(int) i]);
-        }
-
-        return slice;
-    }
 }
 



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