Skip to content

Commit cb5c6d2

Browse files
committed
Remove dead code
1 parent fefde25 commit cb5c6d2

File tree

16 files changed

+180
-289
lines changed

16 files changed

+180
-289
lines changed

httpsnippet-demo/src/main/java/io/github/atkawa7/httpsnippet/demo/console/ConsoleApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.*;
44

5+
import io.github.atkawa7.httpsnippet.utils.HarUtils;
56
import lombok.Data;
67

78
import org.reflections.Reflections;
@@ -22,7 +23,6 @@
2223
import io.github.atkawa7.httpsnippet.http.MediaType;
2324
import io.github.atkawa7.httpsnippet.models.HttpSnippet;
2425
import io.github.atkawa7.httpsnippet.models.Language;
25-
import io.github.atkawa7.httpsnippet.utils.ObjectUtils;
2626

2727
public class ConsoleApp {
2828

@@ -38,7 +38,7 @@ public static void main(String[] args) throws Exception {
3838
HarPostData harPostData =
3939
new HarPostDataBuilder()
4040
.withMimeType(MediaType.APPLICATION_JSON)
41-
.withText(ObjectUtils.toJsonString(user))
41+
.withText(HarUtils.toJsonString(user))
4242
.build();
4343

4444
HarRequest harRequest =

httpsnippet-demo/src/main/java/io/github/atkawa7/httpsnippet/demo/swagger/plugins/CodeSampleOperationBuilderPlugin.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import java.util.*;
44
import java.util.stream.Collectors;
55

6+
import io.github.atkawa7.httpsnippet.utils.HarUtils;
67
import lombok.extern.slf4j.Slf4j;
78

9+
import org.apache.commons.lang3.ObjectUtils;
810
import org.apache.commons.lang3.StringUtils;
911
import org.springframework.core.annotation.Order;
1012
import org.springframework.http.HttpHeaders;
@@ -36,7 +38,6 @@
3638
import io.github.atkawa7.httpsnippet.generators.HttpSnippetCodeGenerator;
3739
import io.github.atkawa7.httpsnippet.http.HttpVersion;
3840
import io.github.atkawa7.httpsnippet.http.MediaType;
39-
import io.github.atkawa7.httpsnippet.utils.ObjectUtils;
4041

4142
@Slf4j
4243
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 100)
@@ -60,13 +61,13 @@ public void apply(OperationContext operationContext) {
6061

6162
String body;
6263
try {
63-
body = ObjectUtils.isNull(example) ? "" : ObjectUtils.toJsonString(example);
64+
body = Objects.isNull(example) ? "" : HarUtils.toJsonString(example);
6465
} catch (JsonProcessingException e) {
6566
throw new RuntimeException("Failed to create json from example");
6667
}
6768

6869
HarPostData postData =
69-
ObjectUtils.isNull(example)
70+
Objects.isNull(example)
7071
? null
7172
: new HarPostDataBuilder()
7273
.withMimeType(MediaType.APPLICATION_JSON)
@@ -117,7 +118,7 @@ private Object getExample(List<ResolvedMethodParameter> resolvedParameters) {
117118
String TWITTER = "https://twitter.com/%s";
118119
Faker FAKER = new Faker();
119120

120-
if (ObjectUtils.isNotNull(resolvedParameters)) {
121+
if (Objects.nonNull(resolvedParameters)) {
121122
for (ResolvedMethodParameter resolvedMethodParameter : resolvedParameters) {
122123
Optional<String> optional = resolvedMethodParameter.defaultName();
123124

@@ -174,7 +175,7 @@ private List<HarHeader> getHarHeaders(OperationContext operationContext) {
174175
}
175176

176177
DocumentationContext documentationContext = operationContext.getDocumentationContext();
177-
if (ObjectUtils.isNotNull(documentationContext)) {
178+
if (Objects.nonNull(documentationContext)) {
178179
Set<String> consumes = documentationContext.getConsumes();
179180
if (ObjectUtils.isNotEmpty(consumes)) {
180181
HarHeader harHeader =

httpsnippet/src/main/java/io/github/atkawa7/httpsnippet/generators/CodeGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
import java.util.Objects;
66

7+
import io.github.atkawa7.httpsnippet.utils.HarUtils;
78
import lombok.Getter;
89

910
import com.smartbear.har.model.HarRequest;
1011

1112
import io.github.atkawa7.httpsnippet.models.Client;
1213
import io.github.atkawa7.httpsnippet.models.Language;
1314
import io.github.atkawa7.httpsnippet.models.internal.CodeRequest;
14-
import io.github.atkawa7.httpsnippet.utils.ObjectUtils;
1515

1616
@Getter
1717
public abstract class CodeGenerator {
@@ -36,11 +36,11 @@ public String code(final HarRequest harRequest) throws Exception {
3636
protected abstract String generateCode(final CodeRequest harRequest) throws Exception;
3737

3838
protected String toJson(Object value) throws Exception {
39-
return ObjectUtils.toJsonString(value);
39+
return HarUtils.toJsonString(value);
4040
}
4141

4242
protected String toPrettyJson(Object value) throws Exception {
43-
return ObjectUtils.toPrettyJsonString(value);
43+
return HarUtils.toPrettyJsonString(value);
4444
}
4545

4646
@Override

httpsnippet/src/main/java/io/github/atkawa7/httpsnippet/generators/c/LibCurl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ protected String generateCode(final CodeRequest codeRequest) throws Exception {
3434
codeRequest
3535
.getHeaders()
3636
.forEach(
37-
harHeader -> {
38-
code.push(
39-
"headers = curl_slist_append(headers, \"%s: %s\");",
40-
harHeader.getName(), harHeader.getValue());
41-
});
37+
harHeader -> code.push(
38+
"headers = curl_slist_append(headers, \"%s: %s\");",
39+
harHeader.getName(), harHeader.getValue()));
4240

4341
code.push("curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);");
4442
}

httpsnippet/src/main/java/io/github/atkawa7/httpsnippet/generators/clojure/CljHttp.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import java.util.*;
44

5+
import io.github.atkawa7.httpsnippet.utils.HarUtils;
56
import lombok.AllArgsConstructor;
67
import lombok.Getter;
78

9+
import org.apache.commons.lang3.ObjectUtils;
810
import org.apache.commons.lang3.StringUtils;
911

1012
import com.smartbear.har.model.HarHeader;
@@ -17,7 +19,6 @@
1719
import io.github.atkawa7.httpsnippet.models.Client;
1820
import io.github.atkawa7.httpsnippet.models.Language;
1921
import io.github.atkawa7.httpsnippet.models.internal.CodeRequest;
20-
import io.github.atkawa7.httpsnippet.utils.ObjectUtils;
2122

2223
public class CljHttp extends CodeGenerator {
2324
private static final List<String> SUPPORTED_METHODS =
@@ -42,7 +43,7 @@ private String padBlock(final int max, String input) {
4243
}
4344

4445
private <T> String literalRepresentation(T value) {
45-
if (ObjectUtils.isNull(value)) {
46+
if (Objects.isNull(value)) {
4647
return "nil";
4748
} else if (value instanceof String) {
4849
return "\"" + ((String) value).replace("\"", "\\\"") + "\"";
@@ -67,7 +68,7 @@ private <T> String literalRepresentation(T value) {
6768
}
6869
return "{" + padBlock(1, String.join("\n ", listBuilder)) + "}";
6970
} else {
70-
return ObjectUtils.defaultIfNull(value, "");
71+
return HarUtils.defaultIfNull(value, "");
7172
}
7273
}
7374

httpsnippet/src/main/java/io/github/atkawa7/httpsnippet/generators/javascript/Fetch.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ protected String generateCode(CodeRequest codeRequest) throws Exception {
3939
fetchOptions.put("body", "[form]");
4040
}
4141
break;
42-
43-
case MediaType.APPLICATION_JSON:
44-
if (codeRequest.hasText()) {
45-
fetchOptions.put("body", codeRequest.getText());
46-
}
47-
break;
48-
4942
case MediaType.MULTIPART_FORM_DATA:
5043
if (codeRequest.hasParams()) {
5144
code.push("let form = new FormData();");
@@ -66,6 +59,8 @@ protected String generateCode(CodeRequest codeRequest) throws Exception {
6659

6760
break;
6861

62+
case MediaType.APPLICATION_JSON:
63+
6964
default:
7065
if (codeRequest.hasText()) {
7166
fetchOptions.put("body", codeRequest.getText());

httpsnippet/src/main/java/io/github/atkawa7/httpsnippet/generators/javascript/XMLHttpRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Map;
44

5+
import org.apache.commons.lang3.ObjectUtils;
56
import org.apache.commons.lang3.StringUtils;
67

78
import com.smartbear.har.model.HarParam;
@@ -12,7 +13,6 @@
1213
import io.github.atkawa7.httpsnippet.models.Client;
1314
import io.github.atkawa7.httpsnippet.models.Language;
1415
import io.github.atkawa7.httpsnippet.models.internal.CodeRequest;
15-
import io.github.atkawa7.httpsnippet.utils.ObjectUtils;
1616

1717
public class XMLHttpRequest extends CodeGenerator {
1818
private boolean cors;

httpsnippet/src/main/java/io/github/atkawa7/httpsnippet/generators/objc/ObjNSURLSession.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.List;
66
import java.util.Map;
7+
import java.util.Objects;
78

89
import com.smartbear.har.model.HarParam;
910

@@ -13,7 +14,8 @@
1314
import io.github.atkawa7.httpsnippet.models.Client;
1415
import io.github.atkawa7.httpsnippet.models.Language;
1516
import io.github.atkawa7.httpsnippet.models.internal.CodeRequest;
16-
import io.github.atkawa7.httpsnippet.utils.ObjectUtils;
17+
import io.github.atkawa7.httpsnippet.utils.HarUtils;
18+
import org.apache.commons.lang3.ObjectUtils;
1719

1820
public class ObjNSURLSession extends CodeGenerator {
1921
private int timeout;
@@ -42,7 +44,7 @@ public String nsDeclaration(String nsClass, String name, Object parameters, Inte
4244

4345
public <T> String literalRepresentation(T value, Integer indentation) throws Exception {
4446
String join = indentation == null ? ", " : ",\n " + this.blankString(indentation);
45-
if (ObjectUtils.isNull(value)) {
47+
if (Objects.isNull(value)) {
4648
return "nil";
4749
} else if (value instanceof Number) {
4850
return "@" + value.toString();
@@ -70,7 +72,7 @@ public <T> String literalRepresentation(T value, Integer indentation) throws Exc
7072
Boolean bool = (Boolean) value;
7173
return bool ? "@YES" : "@NO";
7274
} else {
73-
return String.format("@%s", toJson(ObjectUtils.defaultIfNull(value, "")));
75+
return String.format("@%s", toJson(HarUtils.defaultIfNull(value, "")));
7476
}
7577
}
7678

httpsnippet/src/main/java/io/github/atkawa7/httpsnippet/generators/swift/Swift.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.List;
66
import java.util.Map;
7+
import java.util.Objects;
78

89
import com.smartbear.har.model.HarParam;
910

@@ -13,7 +14,6 @@
1314
import io.github.atkawa7.httpsnippet.models.Client;
1415
import io.github.atkawa7.httpsnippet.models.Language;
1516
import io.github.atkawa7.httpsnippet.models.internal.CodeRequest;
16-
import io.github.atkawa7.httpsnippet.utils.ObjectUtils;
1717

1818
public class Swift extends CodeGenerator {
1919

@@ -26,9 +26,9 @@ private <T> String literalDeclaration(String name, T parameters) {
2626
}
2727

2828
private <T> String literalRepresentation(T value, Integer indent) {
29-
int indentLevel = ObjectUtils.isNull(indent) ? 1 : indent + 1;
29+
int indentLevel = Objects.isNull(indent) ? 1 : indent + 1;
3030

31-
if (ObjectUtils.isNull(value)) {
31+
if (Objects.isNull(value)) {
3232
return "nil";
3333
} else if (value instanceof List) {
3434
List list = (List) value;

httpsnippet/src/main/java/io/github/atkawa7/httpsnippet/models/internal/CodeRequest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import java.util.*;
44
import java.util.stream.Collectors;
55

6+
import org.apache.commons.lang3.ObjectUtils;
67
import org.apache.commons.lang3.StringUtils;
78

89
import com.fasterxml.jackson.core.JsonProcessingException;
910
import com.smartbear.har.model.*;
1011

1112
import io.github.atkawa7.httpsnippet.http.*;
1213
import io.github.atkawa7.httpsnippet.utils.HarUtils;
13-
import io.github.atkawa7.httpsnippet.utils.ObjectUtils;
1414

1515
// internal wrapper class around har request
1616
public final class CodeRequest {
@@ -55,8 +55,8 @@ private CodeRequest(HarRequest harRequest) throws Exception {
5555
this.httpVersion = HttpVersion.resolve(harRequest.getHttpVersion()).getProtocolName();
5656

5757
HarPostData harPostData = harRequest.getPostData();
58-
String mimeType = ObjectUtils.isNotNull(harPostData) ? harPostData.getMimeType() : null;
59-
String text = ObjectUtils.isNotNull(harPostData) ? harPostData.getText() : null;
58+
String mimeType = Objects.nonNull(harPostData) ? harPostData.getMimeType() : null;
59+
String text = Objects.nonNull(harPostData) ? harPostData.getText() : null;
6060

6161
this.params = HarUtils.processParams(harPostData);
6262
this.mimeType = HarUtils.defaultMimeType(mimeType);
@@ -99,7 +99,7 @@ private CodeRequest(HarRequest harRequest) throws Exception {
9999
private void validateMimeType() throws Exception {
100100

101101
if (MediaType.APPLICATION_JSON.equalsIgnoreCase(mimeType)) {
102-
ObjectUtils.validateJSON(this.text);
102+
HarUtils.validateJSON(this.text);
103103
} else if (MediaType.APPLICATION_FORM_URLENCODED.equalsIgnoreCase(mimeType)) {
104104
if (!this._hasParams) {
105105
throw new Exception("Params cannot be empty");
@@ -130,8 +130,8 @@ public Optional<HarHeader> find(String headerName) {
130130
return this.headers.stream()
131131
.filter(
132132
harHeader ->
133-
ObjectUtils.isNotNull(harHeader)
134-
&& ObjectUtils.isNotNull(harHeader.getName())
133+
Objects.nonNull(harHeader)
134+
&& Objects.nonNull(harHeader.getName())
135135
&& harHeader.getName().equalsIgnoreCase(headerName))
136136
.findFirst();
137137
}
@@ -141,15 +141,15 @@ public String getMethod() {
141141
}
142142

143143
public String toJsonString() throws Exception {
144-
return ObjectUtils.toJsonString(text);
144+
return HarUtils.toJsonString(text);
145145
}
146146

147147
public String toPrettyJsonString() throws Exception {
148-
return ObjectUtils.toPrettyJsonString(fromJsonString());
148+
return HarUtils.toPrettyJsonString(fromJsonString());
149149
}
150150

151151
public Map<String, Object> fromJsonString() throws Exception {
152-
return ObjectUtils.fromJsonString(text);
152+
return HarUtils.fromJsonString(text);
153153
}
154154

155155
public String getHttpVersion() {
@@ -239,11 +239,11 @@ public String getCookieString() {
239239
}
240240

241241
public String paramsToJSONString() throws JsonProcessingException {
242-
return ObjectUtils.toJsonString(_params);
242+
return HarUtils.toJsonString(_params);
243243
}
244244

245245
public String paramsToPrettyJSONString() throws JsonProcessingException {
246-
return ObjectUtils.toPrettyJsonString(_params);
246+
return HarUtils.toPrettyJsonString(_params);
247247
}
248248

249249
public String paramsToString() {
@@ -265,11 +265,11 @@ public Map<String, Object> unwrapQueryStrings() {
265265
}
266266

267267
public String queryStringsToJsonString() throws JsonProcessingException {
268-
return ObjectUtils.toPrettyJsonString(this.unwrapQueryStrings());
268+
return HarUtils.toPrettyJsonString(this.unwrapQueryStrings());
269269
}
270270

271271
public String headersToJsonString(boolean pretty) throws JsonProcessingException {
272-
return (pretty) ? ObjectUtils.toPrettyJsonString(_headers) : ObjectUtils.toJsonString(headers);
272+
return (pretty) ? HarUtils.toPrettyJsonString(_headers) : HarUtils.toJsonString(headers);
273273
}
274274

275275
public String headersToJsonString() throws JsonProcessingException {
@@ -278,8 +278,8 @@ public String headersToJsonString() throws JsonProcessingException {
278278

279279
public String allHeadersToJsonString(boolean pretty) throws JsonProcessingException {
280280
return (pretty)
281-
? ObjectUtils.toPrettyJsonString(_allHeaders)
282-
: ObjectUtils.toJsonString(_allHeaders);
281+
? HarUtils.toPrettyJsonString(_allHeaders)
282+
: HarUtils.toJsonString(_allHeaders);
283283
}
284284

285285
public String allHeadersToJsonString() throws JsonProcessingException {

0 commit comments

Comments
 (0)