Coverage Report - com.jcabi.github.Label
 
Classes in this File Line Coverage Branch Coverage Complexity
Label
N/A
N/A
1.062
Label$Smart
47%
8/17
0%
0/16
1.062
Label$Smart$AjcClosure1
100%
1/1
N/A
1.062
Label$Smart$AjcClosure11
0%
0/1
N/A
1.062
Label$Smart$AjcClosure13
100%
1/1
N/A
1.062
Label$Smart$AjcClosure3
0%
0/1
N/A
1.062
Label$Smart$AjcClosure5
0%
0/1
N/A
1.062
Label$Smart$AjcClosure7
100%
1/1
N/A
1.062
Label$Smart$AjcClosure9
0%
0/1
N/A
1.062
Label$Unmodified
76%
10/13
25%
4/16
1.062
Label$Unmodified$AjcClosure1
100%
1/1
N/A
1.062
Label$Unmodified$AjcClosure3
100%
1/1
N/A
1.062
Label$Unmodified$AjcClosure5
100%
1/1
N/A
1.062
Label$Unmodified$AjcClosure7
0%
0/1
N/A
1.062
Label$Unmodified$AjcClosure9
100%
1/1
N/A
1.062
 
 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 java.io.StringReader;
 36  
 import javax.json.Json;
 37  
 import javax.json.JsonObject;
 38  
 import javax.validation.constraints.NotNull;
 39  
 import lombok.EqualsAndHashCode;
 40  
 import lombok.ToString;
 41  
 import org.apache.commons.lang3.builder.CompareToBuilder;
 42  
 
 43  
 /**
 44  
  * Github label.
 45  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 46  
  * @version $Id$
 47  
  * @checkstyle MultipleStringLiterals (500 lines)
 48  
  * @see <a href="http://developer.github.com/v3/issues/labels/">Labels API</a>
 49  
  * @since 0.1
 50  
  */
 51  
 @Immutable
 52  
 @SuppressWarnings("PMD.TooManyMethods")
 53  
 public interface Label extends Comparable<Label>, JsonReadable, JsonPatchable {
 54  
 
 55  
     /**
 56  
      * The repo we're in.
 57  
      * @return Issue
 58  
      * @since 0.6
 59  
      */
 60  
     @NotNull(message = "repo is never NULL")
 61  
     Repo repo();
 62  
 
 63  
     /**
 64  
      * Name of it.
 65  
      * @return Name
 66  
      */
 67  
     @NotNull(message = "label name is never NULL")
 68  
     String name();
 69  
 
 70  
     /**
 71  
      * Smart Label with extra features.
 72  
      */
 73  0
     @Immutable
 74  0
     @ToString
 75  
     @Loggable(Loggable.DEBUG)
 76  0
     @EqualsAndHashCode(of = { "label", "jsn" })
 77  
     final class Smart implements Label {
 78  
         /**
 79  
          * Encapsulated label.
 80  
          */
 81  
         private final transient Label label;
 82  
         /**
 83  
          * SmartJson object for convenient JSON parsing.
 84  
          */
 85  
         private final transient SmartJson jsn;
 86  
 
 87  
         /**
 88  
          * Public ctor.
 89  
          * @param lbl Label
 90  
          */
 91  8
         public Smart(@NotNull(message = "lbl can't be NULL") final Label lbl) {
 92  8
             this.label = lbl;
 93  8
             this.jsn = new SmartJson(lbl);
 94  8
         }
 95  
 
 96  
         /**
 97  
          * Get its color.
 98  
          * @return Color of it
 99  
          * @throws IOException If there is any I/O problem
 100  
          */
 101  
         @NotNull(message = "color is never NULL")
 102  
         public String color() throws IOException {
 103  12
             return this.jsn.text("color");
 104  
         }
 105  
 
 106  
         /**
 107  
          * Set its color.
 108  
          * @param color Color to set
 109  
          * @throws IOException If there is any I/O problem
 110  
          */
 111  
         public void color(
 112  
             @NotNull(message = "color can't be NULL") final String color
 113  
         ) throws IOException {
 114  0
             this.label.patch(
 115  
                 Json.createObjectBuilder().add("color", color).build()
 116  
             );
 117  0
         }
 118  
 
 119  
         @Override
 120  
         @NotNull(message = "repo is never NULL")
 121  
         public Repo repo() {
 122  0
             return this.label.repo();
 123  
         }
 124  
 
 125  
         @Override
 126  
         @NotNull(message = "name is never NULL")
 127  
         public String name() {
 128  2
             return this.label.name();
 129  
         }
 130  
 
 131  
         @Override
 132  
         public int compareTo(
 133  
             @NotNull(message = "lbl can't be NULL") final Label lbl
 134  
         ) {
 135  0
             return this.label.compareTo(lbl);
 136  
         }
 137  
 
 138  
         @Override
 139  
         public void patch(
 140  
             @NotNull(message = "json can't be NULL") final JsonObject json
 141  
         ) throws IOException {
 142  0
             this.label.patch(json);
 143  0
         }
 144  
 
 145  
         @Override
 146  
         @NotNull(message = "JSON is never NULL")
 147  
         public JsonObject json() throws IOException {
 148  2
             return this.label.json();
 149  
         }
 150  
     }
 151  
 
 152  
     /**
 153  
      * Unmodified Label with extra features.
 154  
      */
 155  0
     @Immutable
 156  0
     @ToString
 157  
     @Loggable(Loggable.DEBUG)
 158  1
     @EqualsAndHashCode(of = { "repo", "obj" })
 159  
     final class Unmodified implements Label {
 160  
         /**
 161  
          * Encapsulated Repo.
 162  
          */
 163  
         private final transient Repo repo;
 164  
         /**
 165  
          * Encapsulated String.
 166  
          */
 167  
         private final transient String obj;
 168  
 
 169  
         /**
 170  
          * Public ctor.
 171  
          * @param rep Repo
 172  
          * @param object String
 173  
          */
 174  
         public Unmodified(
 175  
             @NotNull(message = "rep can't be NULL") final Repo rep,
 176  
             @NotNull(message = "object can't be NULL") final String object
 177  4
         ) {
 178  4
             this.repo = rep;
 179  4
             this.obj = object;
 180  4
         }
 181  
 
 182  
         @Override
 183  
         @NotNull(message = "repo is never NULL")
 184  
         public Repo repo() {
 185  4
             return this.repo;
 186  
         }
 187  
 
 188  
         @Override
 189  
         @NotNull(message = "name is never NULL")
 190  
         public String name() {
 191  4
             return this.json().getString("name");
 192  
         }
 193  
 
 194  
         @Override
 195  
         public int compareTo(
 196  
             @NotNull(message = "label can't be NULL") final Label label
 197  
         ) {
 198  2
             return new CompareToBuilder()
 199  
                 .append(this.repo().coordinates(), label.repo().coordinates())
 200  
                 .append(this.obj, label.name())
 201  
                 .build();
 202  
         }
 203  
 
 204  
         @Override
 205  
         public void patch(
 206  
             @NotNull(message = "json can't be NULL") final JsonObject json
 207  
         ) throws IOException {
 208  0
             throw new UnsupportedOperationException("#patch()");
 209  
         }
 210  
 
 211  
         @Override
 212  
         @NotNull(message = "JSON is never NULL")
 213  
         public JsonObject json() {
 214  4
             return Json.createReader(new StringReader(this.obj)).readObject();
 215  
         }
 216  
     }
 217  
 }