In the same spirit (inspired from <a href="http://stackoverflow.com/questions/5412059/how-to-implement-general-pagination">http://stackoverflow.com/questions/5412059/how-to-implement-general-pagination</a>) : <div><br></div>
<div><br><div>public interface PagedResult&lt;T&gt; {<br><br>    PagedResult&lt;T&gt; next();<br><br>    PagedResult&lt;T&gt; prev();</div><div><br></div><div>    PagedResult&lt;T&gt; withOffset(int offset);</div><div><br>
</div><div>    PagedResult&lt;T&gt; withLimit(int limit);<br><br>    List&lt;T&gt; result();<br><br>}</div><div><br><br><div class="gmail_quote">On Tue, Jan 15, 2013 at 1:38 PM, Douglas Campos <span dir="ltr">&lt;<a href="mailto:qmx@qmx.me" target="_blank">qmx@qmx.me</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I&#39;m not a fan of those PageContext objects (remembers me of some wild-ass ThreadLocals leaking all over)<br>
<br>
My proposal for the paging aware APIs would be something like this:<br>
<br>
public interface PagedResult&lt;T&gt; {<br>
<br>
    List&lt;T&gt; next();<br>
<br>
    List&lt;T&gt; prev();<br>
<br>
    List&lt;T&gt; page(int offset, int limit);<br>
<br>
}<br>
<br>
and the Async counterpart<br>
<br>
public interface AsyncPagedResult&lt;T&gt; {<br>
<br>
    void next(Callback&lt;List&lt;T&gt;&gt; callback);<br>
<br>
    void prev(Callback&lt;List&lt;T&gt;&gt; callback);<br>
<br>
    void page(int offset, int limit, Callback&lt;List&lt;T&gt;&gt; callback);<br>
<br>
    public static interface Callback&lt;U&gt; {<br>
        public void onResult(U result);<br>
    }<br>
}<br>
<br>
I don&#39;t like the idea of having a companion object for holding the pagination state.<br>
<br>
Thoughts?<br>
<br>
-- qmx<br>
<div><div class="h5"><br>
On 15/01/2013, at 08:37, Matthias Wessendorf &lt;<a href="mailto:matzew@apache.org">matzew@apache.org</a>&gt; wrote:<br>
<br>
&gt; Hi Summers,<br>
&gt;<br>
&gt;<br>
&gt; <a href="https://gist.github.com/4532661" target="_blank">https://gist.github.com/4532661</a><br>
&gt;<br>
&gt; That is a way to do paging which keeps Pipes immutable, uses readWithFilter, and doesn&#39;t impose any (for convenient definitions of any) bookkeeping on the developer.<br>
&gt;<br>
&gt;<br>
&gt; from your Andorid gist:<br>
&gt;<br>
&gt; A) Once the response has been received, the Pipe implementation will return a List of objects. If this List instance is passed to Pipe.getPageContext the appropriate PageContext will be returned<br>
&gt;<br>
&gt; Note: There is no &#39;return&#39; - the readWithFilter is void, instead a Callback is invoked (onSuccess(list)), see Pipe.java<br>
&gt;<br>
&gt; B) The developer will receive from readWithFilter() a List of object. If she passes this list into Pipe.getPageContext(List result) she will receive the PageContext associated with this result.<br>
&gt;<br>
&gt; Do you mean like:<br>
&gt;<br>
&gt; ...<br>
&gt; myPipe.readWithFilter(filter, new Callback&lt;List&lt;Data&gt;&gt;() {<br>
&gt;<br>
&gt;<br>
&gt; @Override<br>
&gt;<br>
&gt;<br>
&gt; public void onSuccess(List&lt;Data&gt; data) {<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; // get the PageContext:<br>
&gt;<br>
&gt;<br>
&gt; PageContext ctx = myPipe.getPageContext(data);<br>
&gt;<br>
&gt;<br>
&gt; ...<br>
&gt;<br>
&gt;<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; @Override<br>
&gt;<br>
&gt;<br>
&gt; public void onFailure(Exception e) {<br>
&gt;<br>
&gt;<br>
&gt; }<br>
&gt; });<br>
&gt; Not sure about that.....<br>
&gt;<br>
&gt; But for iOS I am thinking about passing in the PageContext into the closure/block of the readWithFilter, like:<br>
&gt;<br>
&gt; -(void) readWithFilter:(void (^)(id&lt;AGFilterConfig&gt; config)) config<br>
&gt;<br>
&gt;<br>
&gt; success:(void (^)(id listOfObjects, id pageContext))success<br>
&gt;<br>
&gt;<br>
&gt; failure:(void (^)(NSError *error))failure;<br>
&gt; A usage would look like:<br>
&gt;<br>
&gt;     [pipe readWithFilter:^(id&lt;AGFilterConfig&gt; config) {<br>
&gt;<br>
&gt;<br>
&gt; // set the filter args and override the given defaults<br>
&gt;<br>
&gt;<br>
&gt; } success:^(id listOfObjects, id pageContext) {<br>
&gt;<br>
&gt;<br>
&gt; // work with the listOfObjects reponse.<br>
&gt;<br>
&gt;<br>
&gt; // for paging/query info, access the given pagecontext,<br>
&gt;<br>
&gt;<br>
&gt; // of the CURRENT request<br>
&gt;<br>
&gt;<br>
&gt; ...<br>
&gt;<br>
&gt;<br>
&gt; } failure:^(NSError *error) {<br>
&gt;<br>
&gt;<br>
&gt; // handle errorz<br>
&gt;<br>
&gt;<br>
&gt; }];<br>
&gt; Any thoughts ?<br>
&gt;<br>
&gt; Not sure I like (or understand) the Pipe.getPageContext(List result) call. Current mindset is that thePageContext just (and only) belongs to the previous (executed) request... Not sure I want to support something like<br>

&gt;<br>
&gt; // first call:<br>
&gt; List&lt;SomeType&gt; first;<br>
&gt; myPipe.readWithFilter(.....) // set first inside of callback<br>
&gt; ...<br>
&gt; // second call:<br>
&gt; List&lt;SomeType&gt; second;<br>
&gt; myPipe.readWithFilter(.....) // set second inside of callback<br>
&gt; ...<br>
&gt; // third call:<br>
&gt; List&lt;SomeType&gt; third;<br>
&gt; myPipe.readWithFilter(.....) // set third inside of callback<br>
&gt; ...<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; /// A BIT LATER ....:<br>
&gt; myPipe.getPageContext(first);<br>
&gt;<br>
&gt;<br>
&gt; I am not sure if that (myPipe.getPageContext(first);) is really desired (or would even easily work, as it would need to store the &quot;metadata&quot;).....<br>
&gt;<br>
&gt;<br>
&gt; Perhaps I am just wrong.<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Matthias Wessendorf<br>
&gt;<br>
&gt; blog: <a href="http://matthiaswessendorf.wordpress.com/" target="_blank">http://matthiaswessendorf.wordpress.com/</a><br>
&gt; sessions: <a href="http://www.slideshare.net/mwessendorf" target="_blank">http://www.slideshare.net/mwessendorf</a><br>
</div></div>&gt; twitter: <a href="http://twitter.com/mwessendorf" target="_blank">http://twitter.com/mwessendorf</a> _______________________________________________<br>
<div class="HOEnZb"><div class="h5">&gt; aerogear-dev mailing list<br>
&gt; <a href="mailto:aerogear-dev@lists.jboss.org">aerogear-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/aerogear-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/aerogear-dev</a><br>
<br>
<br>
_______________________________________________<br>
aerogear-dev mailing list<br>
<a href="mailto:aerogear-dev@lists.jboss.org">aerogear-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/aerogear-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/aerogear-dev</a><br>
</div></div></blockquote></div><br></div></div>