Coverage Report - com.jcabi.github.Limits
 
Classes in this File Line Coverage Branch Coverage Complexity
Limits
N/A
N/A
1
Limits$Throttled
0%
0/9
0%
0/10
1
Limits$Throttled$AjcClosure1
0%
0/1
N/A
1
Limits$Throttled$AjcClosure3
0%
0/1
N/A
1
 
 1  0
 /**
 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.aspects.Loggable;
 34  
 import javax.validation.constraints.NotNull;
 35  
 import lombok.EqualsAndHashCode;
 36  
 import lombok.ToString;
 37  
 
 38  
 /**
 39  
  * Github Rate Limit API.
 40  
  *
 41  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 42  
  * @version $Id$
 43  
  * @since 0.6
 44  
  * @see <a href="http://developer.github.com/v3/rate_limit/">Rate Limit API</a>
 45  
  */
 46  
 @Immutable
 47  
 public interface Limits {
 48  
 
 49  
     /**
 50  
      * Resource name.
 51  
      */
 52  
     String CORE = "core";
 53  
 
 54  
     /**
 55  
      * Resource name.
 56  
      */
 57  
     String SEARCH = "search";
 58  
 
 59  
     /**
 60  
      * Github we're in.
 61  
      * @return Github
 62  
      */
 63  
     @NotNull(message = "Github is never NULL")
 64  
     Github github();
 65  
 
 66  
     /**
 67  
      * Get limit for the given resource.
 68  
      * @param resource Name of resource
 69  
      * @return Limit
 70  
      */
 71  
     @NotNull(message = "Limit si never NULL")
 72  
     Limit get(@NotNull(message = "resource is never NULL") String resource);
 73  
 
 74  
     /**
 75  
      * Throttled Limits.
 76  
      * @since 0.6
 77  
      */
 78  
     @Immutable
 79  0
     @ToString
 80  
     @Loggable(Loggable.DEBUG)
 81  0
     @EqualsAndHashCode(of = "origin")
 82  
     final class Throttled implements Limits {
 83  
         /**
 84  
          * Original.
 85  
          */
 86  
         private final transient Limits origin;
 87  
         /**
 88  
          * Maximum allowed, instead of default 5000.
 89  
          */
 90  
         private final transient int max;
 91  
         /**
 92  
          * Public ctor.
 93  
          * @param limits Original limits
 94  
          * @param allowed Maximum allowed
 95  
          */
 96  
         public Throttled(
 97  
             @NotNull(message = "limits can't be NULL") final Limits limits,
 98  
             final int allowed
 99  0
         ) {
 100  0
             this.origin = limits;
 101  0
             this.max = allowed;
 102  0
         }
 103  
         @Override
 104  
         @NotNull(message = "github is never NULL")
 105  
         public Github github() {
 106  0
             return this.origin.github();
 107  
         }
 108  
         @Override
 109  
         @NotNull(message = "limit is never NULL")
 110  
         public Limit get(
 111  
             @NotNull(message = "resource can't be NULL") final String resource
 112  
         ) {
 113  0
             return new Limit.Throttled(this.origin.get(resource), this.max);
 114  
         }
 115  
     }
 116  
 
 117  
 }