Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polish HeaderUtil #41667

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public static URI getLocation(MultivaluedMap<String, ? extends Object> headers)

public static MediaType getMediaType(MultivaluedMap<String, ? extends Object> headers) {
Object first = headers.getFirst(HttpHeaders.CONTENT_TYPE);
if (first instanceof String) {
String contentType = (String) first;
if (first instanceof String contentType) {
return MediaType.valueOf(contentType);
} else {
return (MediaType) first;
Expand Down Expand Up @@ -150,8 +149,7 @@ public static Map<String, Cookie> getCookies(MultivaluedMap<String, ? extends Ob
return Collections.emptyMap();
Map<String, Cookie> cookies = new HashMap<String, Cookie>();
for (Object obj : list) {
if (obj instanceof Cookie) {
Cookie cookie = (Cookie) obj;
if (obj instanceof Cookie cookie) {
cookies.put(cookie.getName(), cookie);
} else {
String str = headerToString(obj);
Expand All @@ -170,8 +168,7 @@ public static Map<String, NewCookie> getNewCookies(MultivaluedMap<String, ? exte
}
Map<String, NewCookie> cookies = new HashMap<>();
for (Object obj : list) {
if (obj instanceof NewCookie) {
NewCookie cookie = (NewCookie) obj;
if (obj instanceof NewCookie cookie) {
cookies.put(cookie.getName(), cookie);
} else {
String str = HeaderUtil.headerToString(obj);
Expand Down Expand Up @@ -203,7 +200,7 @@ public static String getHeaderString(MultivaluedMap<String, ? extends Object> he
}
StringBuilder sb = new StringBuilder();
for (Object s : list) {
if (sb.length() > 0) {
if (!sb.isEmpty()) {
sb.append(",");
}
sb.append(headerToString(s));
Expand Down Expand Up @@ -267,13 +264,13 @@ public static List<MediaType> getAcceptableMediaTypes(MultivaluedMap<String, ? e
if (accepts == null || accepts.isEmpty()) {
return Collections.singletonList(MediaType.WILDCARD_TYPE);
}
List<MediaType> list = new ArrayList<MediaType>();
List<MediaType> list = new ArrayList<>();
for (Object obj : accepts) {
if (obj instanceof MediaType) {
list.add((MediaType) obj);
continue;
}
String accept = null;
String accept;
if (obj instanceof String) {
accept = (String) obj;
} else {
Expand Down Expand Up @@ -315,7 +312,7 @@ public static List<Locale> getAcceptableLanguages(MultivaluedMap<String, ? exten
}
}
Collections.sort(languages);
List<Locale> list = new ArrayList<Locale>(languages.size());
List<Locale> list = new ArrayList<>(languages.size());
for (WeightedLanguage language : languages)
list.add(language.getLocale());
return list;
Expand Down
Loading