Skip to content

Commit

Permalink
Merge pull request #41667 from geoand/HeaderUtil-polish
Browse files Browse the repository at this point in the history
Polish HeaderUtil
  • Loading branch information
geoand authored Jul 4, 2024
2 parents bcc66be + 21ce94b commit 541f56d
Showing 1 changed file with 7 additions and 10 deletions.
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

0 comments on commit 541f56d

Please sign in to comment.