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