Coverage Report - com.jcabi.github.PullComment
 
Classes in this File Line Coverage Branch Coverage Complexity
PullComment
N/A
N/A
1
PullComment$Smart
71%
20/28
0%
0/16
1
PullComment$Smart$AjcClosure1
100%
1/1
N/A
1
PullComment$Smart$AjcClosure11
100%
1/1
N/A
1
PullComment$Smart$AjcClosure13
100%
1/1
N/A
1
PullComment$Smart$AjcClosure15
100%
1/1
N/A
1
PullComment$Smart$AjcClosure17
100%
1/1
N/A
1
PullComment$Smart$AjcClosure19
0%
0/1
N/A
1
PullComment$Smart$AjcClosure21
0%
0/1
N/A
1
PullComment$Smart$AjcClosure23
0%
0/1
N/A
1
PullComment$Smart$AjcClosure25
0%
0/1
N/A
1
PullComment$Smart$AjcClosure27
100%
1/1
N/A
1
PullComment$Smart$AjcClosure29
100%
1/1
N/A
1
PullComment$Smart$AjcClosure3
100%
1/1
N/A
1
PullComment$Smart$AjcClosure5
100%
1/1
N/A
1
PullComment$Smart$AjcClosure7
100%
1/1
N/A
1
PullComment$Smart$AjcClosure9
100%
1/1
N/A
1
 
 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 java.io.IOException;
 35  
 import javax.json.Json;
 36  
 import javax.json.JsonObject;
 37  
 import javax.validation.constraints.NotNull;
 38  
 import lombok.EqualsAndHashCode;
 39  
 import lombok.ToString;
 40  
 
 41  
 /**
 42  
  * Github pull comment.
 43  
  *
 44  
  * <p>PullComment implements {@link JsonReadable},
 45  
  * that's how you can get its full details in JSON format.
 46  
  * For example, to get its id, you get the entire JSON and
 47  
  * then gets its element:
 48  
  *
 49  
  * <pre>String id = comment.jsn().getString("id");</pre>
 50  
  *
 51  
  * <p>However, it's better to use a supplementary "smart" decorator, which
 52  
  * automates most of these operations:
 53  
  *
 54  
  * <pre>String id = new PullComment.Smart(comment).identifier();</pre>
 55  
  *
 56  
  * @author Carlos Miranda (miranda.cma@gmail.com)
 57  
  * @version $Id$
 58  
  * @since 0.8
 59  
  * @see <a href="http://developer.github.com/v3/pulls/comments/">Pull Comments API</a>
 60  
  */
 61  
 @Immutable
 62  
 @SuppressWarnings("PMD.TooManyMethods")
 63  
 public interface PullComment extends JsonReadable, JsonPatchable,
 64  
     Comparable<PullComment> {
 65  
 
 66  
     /**
 67  
      * Pull we're in.
 68  
      * @return Pull
 69  
      */
 70  
     @NotNull(message = "pull is never NULL")
 71  
     Pull pull();
 72  
 
 73  
     /**
 74  
      * Get its number.
 75  
      * @return Pull comment number
 76  
      */
 77  
     int number();
 78  
 
 79  
     /**
 80  
      * Smart PullComment with extra features.
 81  
      */
 82  0
     @Immutable
 83  0
     @ToString
 84  
     @Loggable(Loggable.DEBUG)
 85  0
     @EqualsAndHashCode(of = { "cmnt", "jsn" })
 86  
     final class Smart implements PullComment {
 87  
 
 88  
         /**
 89  
          * Id field's name in JSON.
 90  
          */
 91  
         private static final String ID = "id";
 92  
 
 93  
         /**
 94  
          * Commit id field's name in JSON.
 95  
          */
 96  
         private static final String COMMIT_ID = "commit_id";
 97  
 
 98  
         /**
 99  
          * Url field's name in JSON.
 100  
          */
 101  
         private static final String URL = "url";
 102  
 
 103  
         /**
 104  
          * Body field's name in JSON.
 105  
          */
 106  
         private static final String BODY = "body";
 107  
 
 108  
         /**
 109  
          * Encapsulated pull comment.
 110  
          */
 111  
         private final transient PullComment cmnt;
 112  
 
 113  
         /**
 114  
          * SmartJson object for convenient JSON parsing.
 115  
          */
 116  
         private final transient SmartJson jsn;
 117  
 
 118  
         /**
 119  
          * Public ctor.
 120  
          * @param pcomment Pull comment
 121  
          */
 122  
         public Smart(
 123  
             @NotNull(message = "pull comment is never NULL")
 124  
             final PullComment pcomment
 125  11
         ) {
 126  11
             this.cmnt = pcomment;
 127  11
             this.jsn = new SmartJson(pcomment);
 128  11
         }
 129  
 
 130  
         /**
 131  
          * Get its id value.
 132  
          * @return Id of pull comment
 133  
          * @throws IOException If there is any I/O problem
 134  
          */
 135  
         @NotNull(message = "identifier is never NULL")
 136  
         public String identifier() throws IOException {
 137  2
             return this.jsn.text(ID);
 138  
         }
 139  
 
 140  
         /**
 141  
          * Change its id value.
 142  
          * @param value Id of pull comment
 143  
          * @throws IOException If there is any I/O problem
 144  
          */
 145  
         public void identifier(
 146  
             @NotNull(message = "value cannot be NULL") final String value
 147  
         ) throws IOException {
 148  2
             this.cmnt.patch(
 149  
                 Json.createObjectBuilder().add(ID, value).build()
 150  
             );
 151  1
         }
 152  
 
 153  
         /**
 154  
          * Get its commit id value.
 155  
          * @return Commit id of pull comment
 156  
          * @throws IOException If there is any I/O problem
 157  
          */
 158  
         @NotNull(message = "commit id is never NULL")
 159  
         public String commitId() throws IOException {
 160  4
             return this.jsn.text(COMMIT_ID);
 161  
         }
 162  
 
 163  
         /**
 164  
          * Change its commit id value.
 165  
          * @param value Commit id of pull comment
 166  
          * @throws IOException If there is any I/O problem
 167  
          */
 168  
         public void commitId(
 169  
             @NotNull(message = "value shouldn't be NULL") final String value
 170  
         ) throws IOException {
 171  2
             this.cmnt.patch(
 172  
                 Json.createObjectBuilder().add(COMMIT_ID, value).build()
 173  
             );
 174  1
         }
 175  
 
 176  
         /**
 177  
          * Get its url value.
 178  
          * @return Url of pull comment
 179  
          * @throws IOException If there is any I/O problem
 180  
          */
 181  
         @NotNull(message = "URL is never NULL")
 182  
         public String url() throws IOException {
 183  2
             return this.jsn.text(URL);
 184  
         }
 185  
 
 186  
         /**
 187  
          * Get its reply id value.
 188  
          * @return Reply id of pull comment
 189  
          * @throws IOException If there is any I/O problem
 190  
          */
 191  
         @NotNull(message = "URL is never NULL")
 192  
         public int reply() throws IOException {
 193  2
             return this.jsn.number("in_reply_to");
 194  
         }
 195  
 
 196  
         /**
 197  
          * Change its url value.
 198  
          * @param value Url of pull comment
 199  
          * @throws IOException If there is any I/O problem
 200  
          */
 201  
         public void url(
 202  
             @NotNull(message = "value is never NULL") final String value
 203  
         ) throws IOException {
 204  2
             this.cmnt.patch(
 205  
                 Json.createObjectBuilder().add(URL, value).build()
 206  
             );
 207  1
         }
 208  
 
 209  
         /**
 210  
          * Get its body value.
 211  
          * @return Url of pull comment
 212  
          * @throws IOException If there is any I/O problem
 213  
          */
 214  
         @NotNull(message = "body is never NULL")
 215  
         public String body() throws IOException {
 216  2
             return this.jsn.text(BODY);
 217  
         }
 218  
 
 219  
         /**
 220  
          * Change its body value.
 221  
          * @param value Url of pull comment
 222  
          * @throws IOException If there is any I/O problem
 223  
          */
 224  
         public void body(
 225  
             @NotNull(message = "value can't be NULL") final String value
 226  
         ) throws IOException {
 227  2
             this.cmnt.patch(
 228  
                 Json.createObjectBuilder().add(BODY, value).build()
 229  
             );
 230  1
         }
 231  
 
 232  
         @Override
 233  
         @NotNull(message = "pull is never NULL")
 234  
         public Pull pull() {
 235  0
             return this.cmnt.pull();
 236  
         }
 237  
 
 238  
         @Override
 239  
         public int number() {
 240  0
             return this.cmnt.number();
 241  
         }
 242  
 
 243  
         @Override
 244  
         public int compareTo(
 245  
             @NotNull(message = "comment can't be NULL")
 246  
             final PullComment comment
 247  
         ) {
 248  0
             return this.cmnt.compareTo(comment);
 249  
         }
 250  
 
 251  
         @Override
 252  
         public void patch(
 253  
             @NotNull(message = "JSON is never NULL") final JsonObject json
 254  
         ) throws IOException {
 255  0
             this.cmnt.patch(json);
 256  0
         }
 257  
 
 258  
         @Override
 259  
         @NotNull(message = "JSON is never NULL")
 260  
         public JsonObject json() throws IOException {
 261  2
             return this.cmnt.json();
 262  
         }
 263  
 
 264  
         /**
 265  
          * Get its author.
 266  
          * @return Pull comment author
 267  
          * @throws IOException If there is any I/O problem
 268  
          */
 269  
         @NotNull(message = "Comment author is never NULL")
 270  
         public String author() throws IOException {
 271  2
             return this.json().getJsonObject("user")
 272  
                 .getString("login");
 273  
         }
 274  
     }
 275  
 }