From 21ce94b16494b128e7cad3f5ca713b793b8b92b9 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 3 Jul 2024 17:25:31 +0300 Subject: [PATCH] Polish HeaderUtil I stumbled upon this when looking at #41639 --- .../reactive/common/headers/HeaderUtil.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/HeaderUtil.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/HeaderUtil.java index 28d078838e5fb..15239f7aa1cc5 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/HeaderUtil.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/HeaderUtil.java @@ -114,8 +114,7 @@ public static URI getLocation(MultivaluedMap headers) public static MediaType getMediaType(MultivaluedMap 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; @@ -150,8 +149,7 @@ public static Map getCookies(MultivaluedMap cookies = new HashMap(); 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); @@ -170,8 +168,7 @@ public static Map getNewCookies(MultivaluedMap 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); @@ -203,7 +200,7 @@ public static String getHeaderString(MultivaluedMap he } StringBuilder sb = new StringBuilder(); for (Object s : list) { - if (sb.length() > 0) { + if (!sb.isEmpty()) { sb.append(","); } sb.append(headerToString(s)); @@ -267,13 +264,13 @@ public static List getAcceptableMediaTypes(MultivaluedMap list = new ArrayList(); + List 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 { @@ -315,7 +312,7 @@ public static List getAcceptableLanguages(MultivaluedMap list = new ArrayList(languages.size()); + List list = new ArrayList<>(languages.size()); for (WeightedLanguage language : languages) list.add(language.getLocale()); return list;