Skip to content

Commit 3d2c386

Browse files
committed
#1807: Refactor Blob and Comment interfaces for better readability.
1 parent 9f1ebe2 commit 3d2c386

76 files changed

Lines changed: 302 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/com/jcabi/github/Blob.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public interface Blob extends JsonReadable {
2727
/**
2828
* Smart Blob with extra features.
2929
*/
30+
3031
@Immutable
3132
@ToString
3233
@Loggable(Loggable.DEBUG)
@@ -39,11 +40,13 @@ final class Smart implements Blob {
3940
/**
4041
* SmartJson object for convenient JSON parsing.
4142
*/
43+
4244
private final transient SmartJson jsn;
4345
/**
4446
* Public ctor.
4547
* @param blb Blob
4648
*/
49+
4750
public Smart(final Blob blb) {
4851
this.blob = blb;
4952
this.jsn = new SmartJson(blb);

src/main/java/com/jcabi/github/Comment.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public Smart(final Comment cmt) {
106106
* @return Author of comment
107107
* @throws IOException If there is any I/O problem
108108
*/
109+
109110
public User author() throws IOException {
110111
return this.comment.issue().repo().github().users().get(
111112
this.comment.json().getJsonObject("user").getString("login")
@@ -116,6 +117,7 @@ public User author() throws IOException {
116117
* @return Body of comment
117118
* @throws IOException If there is any I/O problem
118119
*/
120+
119121
public String body() throws IOException {
120122
return this.jsn.text("body");
121123
}
@@ -124,6 +126,7 @@ public String body() throws IOException {
124126
* @param text Body of comment
125127
* @throws IOException If there is any I/O problem
126128
*/
129+
127130
public void body(final String text) throws IOException {
128131
this.comment.patch(
129132
Json.createObjectBuilder().add("body", text).build()
@@ -134,6 +137,7 @@ public void body(final String text) throws IOException {
134137
* @return URL of comment
135138
* @throws IOException If there is any I/O problem
136139
*/
140+
137141
public URL url() throws IOException {
138142
try {
139143
return new URI(this.jsn.text("url")).toURL();
@@ -146,6 +150,7 @@ public URL url() throws IOException {
146150
* @return Date of creation
147151
* @throws IOException If there is any I/O problem
148152
*/
153+
149154
public Date createdAt() throws IOException {
150155
try {
151156
return new GitHub.Time(
@@ -160,6 +165,7 @@ public Date createdAt() throws IOException {
160165
* @return Date of update
161166
* @throws IOException If there is any I/O problem
162167
*/
168+
163169
public Date updatedAt() throws IOException {
164170
try {
165171
return new GitHub.Time(
@@ -169,14 +175,17 @@ public Date updatedAt() throws IOException {
169175
throw new IOException(ex);
170176
}
171177
}
178+
172179
@Override
173180
public Issue issue() {
174181
return this.comment.issue();
175182
}
183+
176184
@Override
177185
public long number() {
178186
return this.comment.number();
179187
}
188+
180189
@Override
181190
public void remove() throws IOException {
182191
this.comment.remove();
@@ -198,10 +207,12 @@ public Collection<Reaction> reactions() {
198207
public JsonObject json() throws IOException {
199208
return this.comment.json();
200209
}
210+
201211
@Override
202212
public void patch(final JsonObject json) throws IOException {
203213
this.comment.patch(json);
204214
}
215+
205216
@Override
206217
public int compareTo(final Comment obj) {
207218
return this.comment.compareTo(obj);

src/main/java/com/jcabi/github/Commit.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ final class Smart implements Commit {
5858
/**
5959
* SmartJson object for convenient JSON parsing.
6060
*/
61+
6162
private final transient SmartJson jsn;
6263
/**
6364
* Public ctor.
6465
* @param cmt Commit
6566
*/
67+
6668
public Smart(final Commit cmt) {
6769
this.commit = cmt;
6870
this.jsn = new SmartJson(cmt);
@@ -72,6 +74,7 @@ public Smart(final Commit cmt) {
7274
* @return Message of commit
7375
* @throws IOException If there is any I/O problem
7476
*/
77+
7578
public String message() throws IOException {
7679
return this.jsn.json().getJsonObject("commit").getString("message");
7780
}
@@ -80,25 +83,30 @@ public String message() throws IOException {
8083
* @return URL of comment
8184
* @throws IOException If there is any I/O problem
8285
*/
86+
8387
public URL url() throws IOException {
8488
try {
8589
return new URI(this.jsn.text("url")).toURL();
8690
} catch (final URISyntaxException ex) {
8791
throw new IllegalArgumentException(ex);
8892
}
8993
}
94+
9095
@Override
9196
public Repo repo() {
9297
return this.commit.repo();
9398
}
99+
94100
@Override
95101
public String sha() {
96102
return this.commit.sha();
97103
}
104+
98105
@Override
99106
public JsonObject json() throws IOException {
100107
return this.commit.json();
101108
}
109+
102110
@Override
103111
public int compareTo(final Commit obj) {
104112
return this.commit.compareTo(obj);

src/main/java/com/jcabi/github/Content.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ final class Smart implements Content {
6161
/**
6262
* SmartJson object for convenient JSON parsing.
6363
*/
64+
6465
private final transient SmartJson jsn;
6566
/**
6667
* Public ctor.
6768
* @param cont Content
6869
*/
70+
6971
public Smart(
7072
final Content cont) {
7173
this.content = cont;
@@ -76,6 +78,7 @@ public Smart(
7678
* @return Name of content
7779
* @throws IOException If there is any I/O problem
7880
*/
81+
7982
public String name() throws IOException {
8083
return this.jsn.text("name");
8184
}
@@ -84,6 +87,7 @@ public String name() throws IOException {
8487
* @return Type of content
8588
* @throws IOException If there is any I/O problem
8689
*/
90+
8791
public String type() throws IOException {
8892
return this.jsn.text("type");
8993
}
@@ -92,6 +96,7 @@ public String type() throws IOException {
9296
* @return Size content
9397
* @throws IOException If it fails
9498
*/
99+
95100
public int size() throws IOException {
96101
return this.jsn.number("size");
97102
}
@@ -100,6 +105,7 @@ public int size() throws IOException {
100105
* @return Sha hash of content
101106
* @throws IOException If there is any I/O problem
102107
*/
108+
103109
public String sha() throws IOException {
104110
return this.jsn.text("sha");
105111
}
@@ -108,6 +114,7 @@ public String sha() throws IOException {
108114
* @return URL of content
109115
* @throws IOException If there is any I/O problem
110116
*/
117+
111118
public URL url() throws IOException {
112119
try {
113120
return new URI(this.jsn.text("url")).toURL();
@@ -120,6 +127,7 @@ public URL url() throws IOException {
120127
* @return URL of content
121128
* @throws IOException If there is any I/O problem
122129
*/
130+
123131
public URL htmlUrl() throws IOException {
124132
try {
125133
return new URI(this.jsn.text("html_url")).toURL();
@@ -132,6 +140,7 @@ public URL htmlUrl() throws IOException {
132140
* @return URL of content
133141
* @throws IOException If there is any I/O problem
134142
*/
143+
135144
public URL gitUrl() throws IOException {
136145
try {
137146
return new URI(this.jsn.text("git_url")).toURL();
@@ -144,6 +153,7 @@ public URL gitUrl() throws IOException {
144153
* @return Base64 encoded content
145154
* @throws IOException If there is any I/O problem
146155
*/
156+
147157
public String content() throws IOException {
148158
return this.jsn.text("content");
149159
}
@@ -152,29 +162,36 @@ public String content() throws IOException {
152162
* @return Decoded content
153163
* @throws IOException If there is any I/O problem
154164
*/
165+
155166
public byte[] decoded() throws IOException {
156167
return DatatypeConverter.parseBase64Binary(this.content());
157168
}
169+
158170
@Override
159171
public int compareTo(final Content cont) {
160172
return this.content.compareTo(cont);
161173
}
174+
162175
@Override
163176
public void patch(final JsonObject json) throws IOException {
164177
this.content.patch(json);
165178
}
179+
166180
@Override
167181
public JsonObject json() throws IOException {
168182
return this.content.json();
169183
}
184+
170185
@Override
171186
public Repo repo() {
172187
return this.content.repo();
173188
}
189+
174190
@Override
175191
public String path() {
176192
return this.content.path();
177193
}
194+
178195
@Override
179196
public InputStream raw() throws IOException {
180197
return this.content.raw();

src/main/java/com/jcabi/github/Coordinates.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ final class Simple implements Coordinates {
4646
/**
4747
* Repository name.
4848
*/
49+
4950
private final transient String rpo;
5051

5152
/**

src/main/java/com/jcabi/github/Event.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,13 @@ final class Smart implements Event {
157157
/**
158158
* SmartJson object for convenient JSON parsing.
159159
*/
160+
160161
private final transient SmartJson jsn;
161162
/**
162163
* Public ctor.
163164
* @param evt Event
164165
*/
166+
165167
public Smart(final Event evt) {
166168
this.event = evt;
167169
this.jsn = new SmartJson(evt);
@@ -171,6 +173,7 @@ public Smart(final Event evt) {
171173
* @return TRUE if the author exists
172174
* @throws IOException If there is any I/O problem
173175
*/
176+
174177
public boolean hasAuthor() throws IOException {
175178
return !this.event.json().isNull("actor");
176179
}
@@ -179,6 +182,7 @@ public boolean hasAuthor() throws IOException {
179182
* @return Author of comment
180183
* @throws IOException If there is any I/O problem
181184
*/
185+
182186
public User author() throws IOException {
183187
return this.event.repo().github().users().get(
184188
this.event.json().getJsonObject("actor").getString("login")
@@ -189,6 +193,7 @@ public User author() throws IOException {
189193
* @return State of issue
190194
* @throws IOException If there is any I/O problem
191195
*/
196+
192197
public String type() throws IOException {
193198
return this.jsn.text("event");
194199
}
@@ -197,6 +202,7 @@ public String type() throws IOException {
197202
* @return URL of issue
198203
* @throws IOException If there is any I/O problem
199204
*/
205+
200206
public URL url() throws IOException {
201207
try {
202208
return new URI(this.jsn.text("url")).toURL();
@@ -209,6 +215,7 @@ public URL url() throws IOException {
209215
* @return Date of creation
210216
* @throws IOException If there is any I/O problem
211217
*/
218+
212219
public Date createdAt() throws IOException {
213220
try {
214221
return new GitHub.Time(
@@ -224,6 +231,7 @@ public Date createdAt() throws IOException {
224231
* @throws IOException If there is any I/O problem
225232
* @since 0.24
226233
*/
234+
227235
public Optional<Label> label() throws IOException {
228236
Optional<Label> lab = Optional.absent();
229237
final JsonObject lbl = this.jsn.json().getJsonObject("label");
@@ -236,18 +244,22 @@ public Optional<Label> label() throws IOException {
236244
}
237245
return lab;
238246
}
247+
239248
@Override
240249
public Repo repo() {
241250
return this.event.repo();
242251
}
252+
243253
@Override
244254
public int number() {
245255
return this.event.number();
246256
}
257+
247258
@Override
248259
public JsonObject json() throws IOException {
249260
return this.event.json();
250261
}
262+
251263
@Override
252264
public int compareTo(final Event obj) {
253265
return this.event.compareTo(obj);

src/main/java/com/jcabi/github/FileChange.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ final class Smart implements FileChange {
8383
/**
8484
* SmartJson object for convenient JSON parsing.
8585
*/
86+
8687
private final transient SmartJson jsn;
8788

8889
/**

src/main/java/com/jcabi/github/Fork.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ final class Smart implements Fork {
4444
/**
4545
* SmartJson object for convenient JSON parsing.
4646
*/
47+
4748
private final transient SmartJson jsn;
4849
/**
4950
* Public ctor.
5051
* @param frk Fork
5152
*/
53+
5254
public Smart(final Fork frk) {
5355
this.fork = frk;
5456
this.jsn = new SmartJson(frk);

0 commit comments

Comments
 (0)