Drop slice_object_list() in favor of Gee.List.slice().
authorZeeshan Ali (Khattak) <zeeshanak@src.gnome.org>
Wed, 28 Jan 2009 12:33:20 +0000 (12:33 +0000)
committerZeeshan Ali (Khattak) <zeeshanak@src.gnome.org>
Wed, 28 Jan 2009 12:33:20 +0000 (12:33 +0000)
svn path=/trunk/; revision=496

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

index 0535be0..4e00c7c 100644 (file)
@@ -126,16 +126,25 @@ public class Rygel.DVBContentDir : ContentDirectory {
             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 @@ public class Rygel.DVBContentDir : ContentDirectory {
                                                  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 @@ public class Rygel.DVBContentDir : ContentDirectory {
 
         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;
-    }
 }
 
index 9f739dd..4bd72b6 100644 (file)
@@ -61,19 +61,22 @@ public class Rygel.TestContentDir : ContentDirectory {
                                                  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 @@ public class Rygel.TestContentDir : ContentDirectory {
             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;
-    }
 }
 
index 1ab533e..6bdf49f 100644 (file)
@@ -112,19 +112,22 @@ public class Rygel.MediaTracker : ContentDirectory {
                                                  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 @@ public class Rygel.MediaTracker : ContentDirectory {
 
         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;
-    }
 }