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