Coverage Report - com.jcabi.github.RtPagination
 
Classes in this File Line Coverage Branch Coverage Complexity
RtPagination
100%
8/8
N/A
1
RtPagination$1
100%
2/2
N/A
1
 
 1  1
 /**
 2  
  * Copyright (c) 2013-2017, jcabi.com
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the jcabi.com nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package com.jcabi.github;
 31  
 
 32  
 import com.jcabi.aspects.Immutable;
 33  
 import com.jcabi.http.Request;
 34  
 import java.util.Iterator;
 35  
 import javax.json.JsonObject;
 36  
 
 37  
 /**
 38  
  * Github pagination.
 39  
  *
 40  
  * <p>This class is a convenient iterator over multiple JSON objects
 41  
  * returned by Github API. For example, to iterate through notifications
 42  
  * (see Notifications API) you can use this code:</p>
 43  
  *
 44  
  * <pre> Iterable&lt;JsonObject&gt; notifications = new RtPagination&lt;&gt;(
 45  
  *   new RtGithub(oauth).entry()
 46  
  *     .uri().path("/notifications").back(),
 47  
  *   RtPagination.COPYING
 48  
  * );</pre>
 49  
  *
 50  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 51  
  * @version $Id: 936f3104cf34dc12a1cd0da2777fa0cfb7e37404 $
 52  
  * @since 0.4
 53  
  * @param <T> Type of iterable objects
 54  
  * @see <a href="http://developer.github.com/v3/#pagination">Pagination</a>
 55  
  * @since 0.11
 56  
  */
 57  
 @Immutable
 58  
 public final class RtPagination<T> implements Iterable<T> {
 59  
 
 60  
     /**
 61  
      * Mapping that just copies JsonObject.
 62  
      * @checkstyle LineLength (3 lines)
 63  
      */
 64  1
     public static final RtValuePagination.Mapping<JsonObject, JsonObject> COPYING =
 65  2
         new RtValuePagination.Mapping<JsonObject, JsonObject>() {
 66  
             @Override
 67  
             public JsonObject map(final JsonObject value) {
 68  1
                 return value;
 69  
             }
 70  
         };
 71  
 
 72  
     /**
 73  
      * Encapsulated paging.
 74  
      */
 75  
     private final transient RtValuePagination<T, JsonObject> pages;
 76  
 
 77  
     /**
 78  
      * Public ctor.
 79  
      * @param req Request
 80  
      * @param mpp Mapping
 81  
      */
 82  
     public RtPagination(
 83  
         final Request req,
 84  
         final RtValuePagination.Mapping<T, JsonObject> mpp
 85  44
     ) {
 86  44
         this.pages = new RtValuePagination<T, JsonObject>(req, mpp);
 87  44
     }
 88  
 
 89  
     @Override
 90  
     public Iterator<T> iterator() {
 91  40
         return this.pages.iterator();
 92  
     }
 93  
 
 94  
     /**
 95  
      * Entry.
 96  
      * @return Entry point
 97  
      */
 98  
     public Request request() {
 99  1
         return this.pages.request();
 100  
     }
 101  
 
 102  
     /**
 103  
      * Mapping.
 104  
      * @return Mapping
 105  
      */
 106  
     public RtValuePagination.Mapping<T, JsonObject> mapping() {
 107  1
         return this.pages.mapping();
 108  
     }
 109  
 }