Coverage Report - com.jcabi.github.RtRepo
 
Classes in this File Line Coverage Branch Coverage Complexity
RtRepo
77%
31/40
8%
2/24
1.042
RtRepo$AjcClosure1
0%
0/1
N/A
1.042
RtRepo$AjcClosure11
100%
1/1
N/A
1.042
RtRepo$AjcClosure13
100%
1/1
N/A
1.042
RtRepo$AjcClosure15
100%
1/1
N/A
1.042
RtRepo$AjcClosure17
0%
0/1
N/A
1.042
RtRepo$AjcClosure19
100%
1/1
N/A
1.042
RtRepo$AjcClosure21
100%
1/1
N/A
1.042
RtRepo$AjcClosure23
0%
0/1
N/A
1.042
RtRepo$AjcClosure25
100%
1/1
N/A
1.042
RtRepo$AjcClosure27
0%
0/1
N/A
1.042
RtRepo$AjcClosure29
100%
1/1
N/A
1.042
RtRepo$AjcClosure3
100%
1/1
N/A
1.042
RtRepo$AjcClosure31
100%
1/1
N/A
1.042
RtRepo$AjcClosure33
100%
1/1
N/A
1.042
RtRepo$AjcClosure35
100%
1/1
N/A
1.042
RtRepo$AjcClosure37
100%
1/1
N/A
1.042
RtRepo$AjcClosure39
100%
1/1
N/A
1.042
RtRepo$AjcClosure41
100%
1/1
N/A
1.042
RtRepo$AjcClosure43
0%
0/1
N/A
1.042
RtRepo$AjcClosure5
100%
1/1
N/A
1.042
RtRepo$AjcClosure7
0%
0/1
N/A
1.042
RtRepo$AjcClosure9
100%
1/1
N/A
1.042
 
 1  2
 /**
 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 com.jcabi.http.Request;
 35  
 import java.io.IOException;
 36  
 import java.util.ArrayList;
 37  
 import java.util.List;
 38  
 import java.util.Map;
 39  
 import javax.json.JsonObject;
 40  
 import javax.json.JsonValue;
 41  
 import javax.validation.constraints.NotNull;
 42  
 import lombok.EqualsAndHashCode;
 43  
 
 44  
 /**
 45  
  * Github repository.
 46  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 47  
  * @version $Id$
 48  
  * @since 0.1
 49  
  * @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
 50  
  * @checkstyle ClassFanOutComplexity (10 lines)
 51  
  */
 52  0
 @Immutable
 53  
 @Loggable(Loggable.DEBUG)
 54  0
 @EqualsAndHashCode(of = { "ghub", "entry", "coords" })
 55  
 @SuppressWarnings({
 56  
     "PMD.TooManyMethods",
 57  
     "PMD.CouplingBetweenObjects"
 58  
 })
 59  
 final class RtRepo implements Repo {
 60  
 
 61  
     /**
 62  
      * Github.
 63  
      */
 64  
     private final transient Github ghub;
 65  
 
 66  
     /**
 67  
      * RESTful entry.
 68  
      */
 69  
     private final transient Request entry;
 70  
 
 71  
     /**
 72  
      * RESTful request.
 73  
      */
 74  
     private final transient Request request;
 75  
 
 76  
     /**
 77  
      * Repository coordinates.
 78  
      */
 79  
     private final transient Coordinates coords;
 80  
 
 81  
     /**
 82  
      * Public ctor.
 83  
      * @param github Github
 84  
      * @param req Request
 85  
      * @param crd Coordinate of the repo
 86  
      */
 87  35
     RtRepo(final Github github, final Request req, final Coordinates crd) {
 88  35
         this.ghub = github;
 89  35
         this.entry = req;
 90  35
         this.coords = crd;
 91  35
         this.request = this.entry.uri()
 92  
             .path("/repos")
 93  
             .path(this.coords.user())
 94  
             .path(this.coords.repo())
 95  
             .back();
 96  35
     }
 97  
 
 98  
     @Override
 99  
     @NotNull(message = "toString is never NULL")
 100  
     public String toString() {
 101  0
         return this.coords.toString();
 102  
     }
 103  
 
 104  
     @Override
 105  
     @NotNull(message = "Github is never NULL")
 106  
     public Github github() {
 107  0
         return this.ghub;
 108  
     }
 109  
 
 110  
     @Override
 111  
     @NotNull(message = "Coordinates is never NULL")
 112  
     public Coordinates coordinates() {
 113  102
         return this.coords;
 114  
     }
 115  
 
 116  
     @Override
 117  
     @NotNull(message = "Issues is never NULL")
 118  
     public Issues issues() {
 119  4
         return new RtIssues(this.entry, this);
 120  
     }
 121  
 
 122  
     @Override
 123  
     @NotNull(message = "Milestones is never NULL")
 124  
     public Milestones milestones() {
 125  0
         return new RtMilestones(this.entry, this);
 126  
     }
 127  
 
 128  
     @Override
 129  
     @NotNull(message = "Pulls is never NULL")
 130  
     public Pulls pulls() {
 131  2
         return new RtPulls(this.entry, this);
 132  
     }
 133  
 
 134  
     @Override
 135  
     @NotNull(message = "Hooks is never NULL")
 136  
     public Hooks hooks() {
 137  2
         return new RtHooks(this.entry, this);
 138  
     }
 139  
 
 140  
     @Override
 141  
     @NotNull(message = "events are never NULL")
 142  
     public IssueEvents issueEvents() {
 143  2
         return new RtIssueEvents(this.entry, this);
 144  
     }
 145  
 
 146  
     @Override
 147  
     @NotNull(message = "Labels is never NULL")
 148  
     public Labels labels() {
 149  2
         return new RtLabels(this.entry, this);
 150  
     }
 151  
 
 152  
     @Override
 153  
     @NotNull(message = "Assignees is never NULL")
 154  
     public Assignees assignees() {
 155  0
         return new RtAssignees(this.entry, this);
 156  
     }
 157  
 
 158  
     @Override
 159  
     @NotNull(message = "Releases is never NULL")
 160  
     public Releases releases() {
 161  2
         return new RtReleases(this.entry, this);
 162  
     }
 163  
 
 164  
     @Override
 165  
     @NotNull(message = "DeployKeys is never NULL")
 166  
     public DeployKeys keys() {
 167  2
         return new RtDeployKeys(this.entry, this);
 168  
     }
 169  
 
 170  
     @Override
 171  
     @NotNull(message = "Forks is never NULL")
 172  
     public Forks forks() {
 173  0
         return new RtForks(this.entry, this);
 174  
     }
 175  
 
 176  
     @Override
 177  
     @NotNull(message = "Contents is never NULL")
 178  
     public Contents contents() {
 179  6
         return new RtContents(this.entry, this);
 180  
     }
 181  
 
 182  
     @Override
 183  
     @NotNull(message = "Collaborators is never NULL")
 184  
     public Collaborators collaborators() {
 185  0
         return new RtCollaborators(this.entry, this);
 186  
     }
 187  
 
 188  
     @Override
 189  
     @NotNull(message = "Git is never NULL")
 190  
     public Git git() {
 191  2
         return new RtGit(this.entry, this);
 192  
     }
 193  
 
 194  
     @Override
 195  
     @NotNull(message = "Stars is never NULL")
 196  
     public Stars stars() {
 197  2
         return new RtStars(this.entry, this);
 198  
     }
 199  
 
 200  
     @Override
 201  
     @NotNull(message = "Notifications is never NULL")
 202  
     public Notifications notifications() {
 203  2
         return new RtNotifications();
 204  
     }
 205  
 
 206  
     @Override
 207  
     @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
 208  
     public Iterable<Language> languages() throws IOException {
 209  4
         final RtJson json = new RtJson(
 210  
             this.request.uri()
 211  
                 .path("/languages")
 212  
                 .back()
 213  
         );
 214  2
         final JsonObject object = json.fetch();
 215  2
         final List<Language> languages =
 216  
             new ArrayList<Language>(object.size());
 217  2
         for (final Map.Entry<String, JsonValue> value : object.entrySet()) {
 218  3
             final String name = value.getKey();
 219  3
             languages.add(
 220  
                 new RtLanguage(
 221  
                     name,
 222  
                     object.getJsonNumber(name).longValue()
 223  
                 )
 224  
             );
 225  3
         }
 226  2
         return languages;
 227  
     }
 228  
 
 229  
     @Override
 230  
     public void patch(
 231  
         @NotNull(message = "JSON is never NULL") final JsonObject json)
 232  
         throws IOException {
 233  2
         new RtJson(this.request).patch(json);
 234  1
     }
 235  
 
 236  
     @Override
 237  
     @NotNull(message = "RepoCommits is never NULL")
 238  
     public RepoCommits commits() {
 239  4
         return new RtRepoCommits(this.entry, this);
 240  
     }
 241  
 
 242  
     @Override
 243  
     @NotNull(message = "JSON is never NULL")
 244  
     public JsonObject json() throws IOException {
 245  2
         return new RtJson(this.request).fetch();
 246  
     }
 247  
 
 248  
     @Override
 249  
     public int compareTo(final Repo repo) {
 250  0
         return this.coords.compareTo(repo.coordinates());
 251  
     }
 252  
 }