Skip to content

Commit

Permalink
Apply code improvements suggested by IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
dstepanov committed Jun 14, 2024
1 parent 0118db9 commit 38efe12
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 154 deletions.
22 changes: 10 additions & 12 deletions http/src/main/java/io/micronaut/http/uri/DefaultUriBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@
*/
package io.micronaut.http.uri;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.core.convert.value.MutableConvertibleMultiValues;
import io.micronaut.core.convert.value.MutableConvertibleMultiValuesMap;
import io.micronaut.core.util.ArrayUtils;
import io.micronaut.core.util.CollectionUtils;
import io.micronaut.core.util.StringUtils;
import io.micronaut.http.exceptions.UriSyntaxException;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -57,7 +59,7 @@ class DefaultUriBuilder implements UriBuilder {
private static final Pattern PATTERN_FULL_URI = Pattern.compile(
"^(" + STRING_PATTERN_SCHEME + ")?" + "(//(" + STRING_PATTERN_USER_INFO + "@)?" + STRING_PATTERN_HOST + "(:" + STRING_PATTERN_PORT +
")?" + ")?" + STRING_PATTERN_PATH + "(\\?" + STRING_PATTERN_QUERY + ")?" + "(#" + STRING_PATTERN_REMAINING + ")?");

private String authority;
private final MutableConvertibleMultiValues<String> queryParams;
private String scheme;
Expand Down Expand Up @@ -120,7 +122,7 @@ class DefaultUriBuilder implements UriBuilder {
this.host = host;
}
if (port != null) {
this.port = Integer.valueOf(port);
this.port = Integer.parseInt(port);
}
if (path != null) {

Expand Down Expand Up @@ -345,7 +347,7 @@ private String reconstructAsString(Map<String, ? super Object> values) {

StringBuilder path = this.path;
if (StringUtils.isNotEmpty(path)) {
if (builder.length() > 0 && path.charAt(0) != '/') {
if (!builder.isEmpty() && path.charAt(0) != '/') {
builder.append('/');
}
String pathStr = path.toString();
Expand Down Expand Up @@ -413,10 +415,6 @@ private String expandOrEncode(String value, Map<String, ? super Object> values)
}

private String encode(String userInfo) {
try {
return URLEncoder.encode(userInfo, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("No available charset: " + e.getMessage());
}
return URLEncoder.encode(userInfo, StandardCharsets.UTF_8);
}
}
Loading

0 comments on commit 38efe12

Please sign in to comment.