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<T> {<br><br> PagedResult<T> next();<br><br> PagedResult<T> prev();</div><div><br></div><div> PagedResult<T> withOffset(int offset);</div><div><br>
</div><div> PagedResult<T> withLimit(int limit);<br><br> List<T> 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"><<a href="mailto:qmx@qmx.me" target="_blank">qmx@qmx.me</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'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<T> {<br>
<br>
List<T> next();<br>
<br>
List<T> prev();<br>
<br>
List<T> page(int offset, int limit);<br>
<br>
}<br>
<br>
and the Async counterpart<br>
<br>
public interface AsyncPagedResult<T> {<br>
<br>
void next(Callback<List<T>> callback);<br>
<br>
void prev(Callback<List<T>> callback);<br>
<br>
void page(int offset, int limit, Callback<List<T>> callback);<br>
<br>
public static interface Callback<U> {<br>
public void onResult(U result);<br>
}<br>
}<br>
<br>
I don'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 <<a href="mailto:matzew@apache.org">matzew@apache.org</a>> wrote:<br>
<br>
> Hi Summers,<br>
><br>
><br>
> <a href="https://gist.github.com/4532661" target="_blank">https://gist.github.com/4532661</a><br>
><br>
> That is a way to do paging which keeps Pipes immutable, uses readWithFilter, and doesn't impose any (for convenient definitions of any) bookkeeping on the developer.<br>
><br>
><br>
> from your Andorid gist:<br>
><br>
> 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>
><br>
> Note: There is no 'return' - the readWithFilter is void, instead a Callback is invoked (onSuccess(list)), see Pipe.java<br>
><br>
> 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>
><br>
> Do you mean like:<br>
><br>
> ...<br>
> myPipe.readWithFilter(filter, new Callback<List<Data>>() {<br>
><br>
><br>
> @Override<br>
><br>
><br>
> public void onSuccess(List<Data> data) {<br>
><br>
><br>
><br>
> // get the PageContext:<br>
><br>
><br>
> PageContext ctx = myPipe.getPageContext(data);<br>
><br>
><br>
> ...<br>
><br>
><br>
> }<br>
><br>
><br>
><br>
> @Override<br>
><br>
><br>
> public void onFailure(Exception e) {<br>
><br>
><br>
> }<br>
> });<br>
> Not sure about that.....<br>
><br>
> But for iOS I am thinking about passing in the PageContext into the closure/block of the readWithFilter, like:<br>
><br>
> -(void) readWithFilter:(void (^)(id<AGFilterConfig> config)) config<br>
><br>
><br>
> success:(void (^)(id listOfObjects, id pageContext))success<br>
><br>
><br>
> failure:(void (^)(NSError *error))failure;<br>
> A usage would look like:<br>
><br>
> [pipe readWithFilter:^(id<AGFilterConfig> config) {<br>
><br>
><br>
> // set the filter args and override the given defaults<br>
><br>
><br>
> } success:^(id listOfObjects, id pageContext) {<br>
><br>
><br>
> // work with the listOfObjects reponse.<br>
><br>
><br>
> // for paging/query info, access the given pagecontext,<br>
><br>
><br>
> // of the CURRENT request<br>
><br>
><br>
> ...<br>
><br>
><br>
> } failure:^(NSError *error) {<br>
><br>
><br>
> // handle errorz<br>
><br>
><br>
> }];<br>
> Any thoughts ?<br>
><br>
> 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>
><br>
> // first call:<br>
> List<SomeType> first;<br>
> myPipe.readWithFilter(.....) // set first inside of callback<br>
> ...<br>
> // second call:<br>
> List<SomeType> second;<br>
> myPipe.readWithFilter(.....) // set second inside of callback<br>
> ...<br>
> // third call:<br>
> List<SomeType> third;<br>
> myPipe.readWithFilter(.....) // set third inside of callback<br>
> ...<br>
><br>
><br>
><br>
><br>
> /// A BIT LATER ....:<br>
> myPipe.getPageContext(first);<br>
><br>
><br>
> I am not sure if that (myPipe.getPageContext(first);) is really desired (or would even easily work, as it would need to store the "metadata").....<br>
><br>
><br>
> Perhaps I am just wrong.<br>
><br>
><br>
> --<br>
> Matthias Wessendorf<br>
><br>
> blog: <a href="http://matthiaswessendorf.wordpress.com/" target="_blank">http://matthiaswessendorf.wordpress.com/</a><br>
> sessions: <a href="http://www.slideshare.net/mwessendorf" target="_blank">http://www.slideshare.net/mwessendorf</a><br>
</div></div>> twitter: <a href="http://twitter.com/mwessendorf" target="_blank">http://twitter.com/mwessendorf</a> _______________________________________________<br>
<div class="HOEnZb"><div class="h5">> 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>
<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>