From: Zeeshan Ali (Khattak) Date: Wed, 28 Jan 2009 12:33:20 +0000 (+0000) Subject: Drop slice_object_list() in favor of Gee.List.slice(). X-Git-Tag: RYGEL_0_2_2~147 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=80cacf5d707c8415b0f6af4759b0ae30c51d3727;p=profile%2Fivi%2Frygel.git Drop slice_object_list() in favor of Gee.List.slice(). svn path=/trunk/; revision=496 --- diff --git a/src/plugins/dvb/rygel-dvb-content-dir.vala b/src/plugins/dvb/rygel-dvb-content-dir.vala index 0535be0..4e00c7c 100644 --- a/src/plugins/dvb/rygel-dvb-content-dir.vala +++ b/src/plugins/dvb/rygel-dvb-content-dir.vala @@ -126,16 +126,25 @@ public class Rygel.DVBContentDir : ContentDirectory { throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"); } + Gee.List 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) children; } public override ArrayList get_root_children ( @@ -145,19 +154,22 @@ public class Rygel.DVBContentDir : ContentDirectory { throws GLib.Error { child_count = this.groups.size; - ArrayList children; + Gee.List 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) children; } // Private methods @@ -187,25 +199,5 @@ public class Rygel.DVBContentDir : ContentDirectory { return channel; } - - private ArrayList slice_object_list ( - ArrayList list, - uint offset, - uint max_count) { - uint total = list.size; - - var slice = new ArrayList (); - - if (max_count == 0 || max_count > (total - offset)) { - max_count = total - offset; - } - - slice = new ArrayList (); - for (uint i = offset; i < total; i++) { - slice.add (list[(int) i]); - } - - return slice; - } } diff --git a/src/plugins/test/rygel-test-content-dir.vala b/src/plugins/test/rygel-test-content-dir.vala index 9f739dd..4bd72b6 100644 --- a/src/plugins/test/rygel-test-content-dir.vala +++ b/src/plugins/test/rygel-test-content-dir.vala @@ -61,19 +61,22 @@ public class Rygel.TestContentDir : ContentDirectory { throws GLib.Error { child_count = this.items.size; - ArrayList children; + Gee.List 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) children; } public override MediaObject find_object_by_id (string object_id) @@ -109,25 +112,5 @@ public class Rygel.TestContentDir : ContentDirectory { return; } } - - private ArrayList slice_object_list ( - ArrayList list, - uint offset, - uint max_count) { - uint total = list.size; - - var slice = new ArrayList (); - - if (max_count == 0 || max_count > (total - offset)) { - max_count = total - offset; - } - - slice = new ArrayList (); - for (uint i = offset; i < total; i++) { - slice.add (list[(int) i]); - } - - return slice; - } } diff --git a/src/plugins/tracker/rygel-media-tracker.vala b/src/plugins/tracker/rygel-media-tracker.vala index 1ab533e..6bdf49f 100644 --- a/src/plugins/tracker/rygel-media-tracker.vala +++ b/src/plugins/tracker/rygel-media-tracker.vala @@ -112,19 +112,22 @@ public class Rygel.MediaTracker : ContentDirectory { throws GLib.Error { child_count = this.containers.size; - ArrayList children; + Gee.List 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) children; } /* Private methods */ @@ -167,25 +170,5 @@ public class Rygel.MediaTracker : ContentDirectory { return container; } - - private ArrayList slice_object_list ( - ArrayList list, - uint offset, - uint max_count) { - uint total = list.size; - - var slice = new ArrayList (); - - if (max_count == 0 || max_count > (total - offset)) { - max_count = total - offset; - } - - slice = new ArrayList (); - for (uint i = offset; i < total; i++) { - slice.add (list[(int) i]); - } - - return slice; - } }