This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git
The following commit(s) were added to refs/heads/master by this push: new a655e14 Refactor common code a655e14 is described below commit a655e1408630c053143a9b94bf97a60b36676230 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu Apr 6 12:34:13 2023 -0400 Refactor common code --- .../fileupload2/util/FileItemHeadersImpl.java | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/apache/commons/fileupload2/util/FileItemHeadersImpl.java b/src/main/java/org/apache/commons/fileupload2/util/FileItemHeadersImpl.java index 2aadf13..6778443 100644 --- a/src/main/java/org/apache/commons/fileupload2/util/FileItemHeadersImpl.java +++ b/src/main/java/org/apache/commons/fileupload2/util/FileItemHeadersImpl.java @@ -40,21 +40,18 @@ public class FileItemHeadersImpl implements FileItemHeaders, Serializable { private static final long serialVersionUID = 2; /** - * Map of {@code String} keys to a {@code List} of - * {@code String} instances. + * Map of {@code String} keys to a {@code List} of {@code String} instances. */ private final Map<String, List<String>> headerNameToValueListMap = new LinkedHashMap<>(); /** * Method to add header values to this instance. * - * @param name name of this header + * @param name name of this header * @param value value of this header */ public synchronized void addHeader(final String name, final String value) { - final String nameLower = name.toLowerCase(Locale.ENGLISH); - final List<String> headerValueList = headerNameToValueListMap. - computeIfAbsent(nameLower, k -> new ArrayList<>()); + final List<String> headerValueList = headerNameToValueListMap.computeIfAbsent(toLowerCase(name), k -> new ArrayList<>()); headerValueList.add(value); } @@ -63,8 +60,7 @@ public class FileItemHeadersImpl implements FileItemHeaders, Serializable { */ @Override public String getHeader(final String name) { - final String nameLower = name.toLowerCase(Locale.ENGLISH); - final List<String> headerValueList = headerNameToValueListMap.get(nameLower); + final List<String> headerValueList = getList(name); if (null == headerValueList) { return null; } @@ -84,12 +80,19 @@ public class FileItemHeadersImpl implements FileItemHeaders, Serializable { */ @Override public Iterator<String> getHeaders(final String name) { - final String nameLower = name.toLowerCase(Locale.ENGLISH); - List<String> headerValueList = headerNameToValueListMap.get(nameLower); + List<String> headerValueList = getList(name); if (null == headerValueList) { headerValueList = Collections.emptyList(); } return headerValueList.iterator(); } + private List<String> getList(final String name) { + return headerNameToValueListMap.get(toLowerCase(name)); + } + + private String toLowerCase(final String value) { + return value.toLowerCase(Locale.ENGLISH); + } + }