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