Coverage Report - com.jcabi.github.RtPagination
 
Classes in this File Line Coverage Branch Coverage Complexity
RtPagination
100%
8/8
N/A
1
RtPagination$1
50%
1/2
N/A
1
 
 1  1
 /**
 2  
  * Copyright (c) 2013-2015, 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  
 import javax.validation.constraints.NotNull;
 37  
 
 38  
 /**
 39  
  * Github pagination.
 40  
  *
 41  
  * <p>This class is a convenient iterator over multiple JSON objects
 42  
  * returned by Github API. For example, to iterate through notifications
 43  
  * (see Notifications API) you can use this code:</p>
 44  
  *
 45  
  * <pre> Iterable&lt;JsonObject&gt; notifications = new RtPagination&lt;&gt;(
 46  
  *   new RtGithub(oauth).entry()
 47  
  *     .uri().path("/notifications").back(),
 48  
  *   RtPagination.COPYING
 49  
  * );</pre>
 50  
  *
 51  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 52  
  * @version $Id$
 53  
  * @since 0.4
 54  
  * @param <T> Type of iterable objects
 55  
  * @see <a href="http://developer.github.com/v3/#pagination">Pagination</a>
 56  
  * @since 0.11
 57  
  */
 58  
 @Immutable
 59  
 public final class RtPagination<T> implements Iterable<T> {
 60  
 
 61  
     /**
 62  
      * Mapping that just copies JsonObject.
 63  
      * @checkstyle LineLength (3 lines)
 64  
      */
 65  1
     public static final RtValuePagination.Mapping<JsonObject, JsonObject> COPYING =
 66  1
         new RtValuePagination.Mapping<JsonObject, JsonObject>() {
 67  
             @Override
 68  
             public JsonObject map(final JsonObject value) {
 69  0
                 return value;
 70  
             }
 71  
         };
 72  
 
 73  
     /**
 74  
      * Encapsulated paging.
 75  
      */
 76  
     private final transient RtValuePagination<T, JsonObject> pages;
 77  
 
 78  
     /**
 79  
      * Public ctor.
 80  
      * @param req Request
 81  
      * @param mpp Mapping
 82  
      */
 83  
     public RtPagination(
 84  
         @NotNull(message = "request can't be NULL") final Request req,
 85  
         @NotNull(message = "mapping can't be NULL")
 86  
         final RtValuePagination.Mapping<T, JsonObject> mpp
 87  40
     ) {
 88  40
         this.pages = new RtValuePagination<T, JsonObject>(req, mpp);
 89  40
     }
 90  
 
 91  
     @Override
 92  
     public Iterator<T> iterator() {
 93  36
         return this.pages.iterator();
 94  
     }
 95  
 
 96  
     /**
 97  
      * Entry.
 98  
      * @return Entry point
 99  
      */
 100  
     @NotNull(message = "Request is never NULL")
 101  
     public Request request() {
 102  1
         return this.pages.request();
 103  
     }
 104  
 
 105  
     /**
 106  
      * Mapping.
 107  
      * @return Mapping
 108  
      */
 109  
     @NotNull(message = "map is never NULLs")
 110  
     public RtValuePagination.Mapping<T, JsonObject> mapping() {
 111  1
         return this.pages.mapping();
 112  
     }
 113  
 }