Coverage Report - com.jcabi.github.CommitsComparison
 
Classes in this File Line Coverage Branch Coverage Complexity
CommitsComparison
N/A
N/A
1.167
CommitsComparison$Smart
75%
12/16
16%
2/12
1.167
CommitsComparison$Smart$AjcClosure1
100%
1/1
N/A
1.167
CommitsComparison$Smart$AjcClosure3
100%
1/1
N/A
1.167
CommitsComparison$Smart$AjcClosure5
0%
0/1
N/A
1.167
CommitsComparison$Smart$AjcClosure7
0%
0/1
N/A
1.167
 
 1  4
 /**
 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 java.io.IOException;
 35  
 import java.util.ArrayList;
 36  
 import java.util.Collection;
 37  
 import javax.json.JsonArray;
 38  
 import javax.json.JsonObject;
 39  
 import javax.json.JsonValue;
 40  
 import javax.validation.constraints.NotNull;
 41  
 import lombok.EqualsAndHashCode;
 42  
 import lombok.ToString;
 43  
 
 44  
 /**
 45  
  * Commits comparison.
 46  
  * @author Alexander Sinyagin (sinyagin.alexander@gmail.com)
 47  
  * @version $Id$
 48  
  * @see <a href="http://developer.github.com/v3/repos/commits/#compare-two-commits">Compare two commits</a>
 49  
  */
 50  
 @Immutable
 51  
 public interface CommitsComparison extends JsonReadable {
 52  
 
 53  
     /**
 54  
      * Get a parent repository of commits.
 55  
      * @return Repository
 56  
      */
 57  
     @NotNull(message = "repo is never NULL")
 58  
     Repo repo();
 59  
 
 60  
     /**
 61  
      * Smart commits comparison with extra features.
 62  
      */
 63  
     @Immutable
 64  0
     @ToString
 65  
     @Loggable(Loggable.DEBUG)
 66  0
     @EqualsAndHashCode(of = "comparison")
 67  
     final class Smart implements CommitsComparison {
 68  
 
 69  
         /**
 70  
          * Encapsulated commits comparison.
 71  
          */
 72  
         private final transient CommitsComparison comparison;
 73  
 
 74  
         /**
 75  
          * Public ctor.
 76  
          * @param cmprsn Commits comparison
 77  
          */
 78  
         public Smart(
 79  
             @NotNull(message = "cmprsn can't be NULL")
 80  
             final CommitsComparison cmprsn
 81  3
         ) {
 82  3
             this.comparison = cmprsn;
 83  3
         }
 84  
 
 85  
         /**
 86  
          * Get commits.
 87  
          * @return Commits
 88  
          * @throws IOException If there is any I/O problem
 89  
          */
 90  
         @NotNull(message = "Iterable of commits is never NULL")
 91  
         public Iterable<RepoCommit> commits() throws IOException {
 92  4
             final JsonArray array = this.comparison.json()
 93  
                 .getJsonArray("commits");
 94  2
             final Collection<RepoCommit> commits =
 95  
                 new ArrayList<RepoCommit>(array.size());
 96  2
             final RepoCommits repo = this.comparison.repo().commits();
 97  2
             for (final JsonValue value : array) {
 98  1
                 commits.add(
 99  
                     repo.get(JsonObject.class.cast(value).getString("sha"))
 100  
                 );
 101  1
             }
 102  2
             return commits;
 103  
         }
 104  
 
 105  
         /**
 106  
          * Get a JSON-array of objects with information about files.
 107  
          * @return JSON-array
 108  
          * @throws IOException If there is any I/O problem
 109  
          */
 110  
         @NotNull(message = "json array is never NULL")
 111  
         public JsonArray files() throws IOException {
 112  2
             return this.comparison.json().getJsonArray("files");
 113  
         }
 114  
 
 115  
         @Override
 116  
         @NotNull(message = "Repository is never NULL")
 117  
         public Repo repo() {
 118  0
             return this.comparison.repo();
 119  
         }
 120  
 
 121  
         @Override
 122  
         @NotNull(message = "JSON is never NULL")
 123  
         public JsonObject json() throws IOException {
 124  0
             return this.comparison.json();
 125  
         }
 126  
     }
 127  
 }