Skip to content

Commit f749280

Browse files
author
Stephane Landelle
committed
Optimize Fluent(CaseInsensitive)StringsMap for single value, close AsyncHttpClient#580
1 parent e5f188a commit f749280

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

api/src/main/java/org/asynchttpclient/FluentCaseInsensitiveStringsMap.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ public FluentCaseInsensitiveStringsMap(Map<String, Collection<String>> src) {
6060
}
6161
}
6262

63+
public FluentCaseInsensitiveStringsMap add(String key, String value) {
64+
if (key != null) {
65+
String lcKey = key.toLowerCase(Locale.ENGLISH);
66+
String realKey = keyLookup.get(lcKey);
67+
68+
List<String> curValues = null;
69+
if (realKey == null) {
70+
keyLookup.put(lcKey, key);
71+
curValues = new ArrayList<String>();
72+
values.put(key, curValues);
73+
} else {
74+
curValues = values.get(realKey);
75+
}
76+
77+
String nonNullValue = value != null? value : "";
78+
curValues.add(nonNullValue);
79+
}
80+
return this;
81+
}
82+
6383
/**
6484
* Adds the specified values and returns this object.
6585
*

api/src/main/java/org/asynchttpclient/FluentStringsMap.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ public FluentStringsMap(Map<String, Collection<String>> src) {
5454
}
5555
}
5656

57+
public FluentStringsMap add(String key, String value) {
58+
if (key != null) {
59+
List<String> curValues = values.get(key);
60+
61+
if (curValues == null) {
62+
curValues = new ArrayList<String>(1);
63+
values.put(key, curValues);
64+
}
65+
curValues.add(value);
66+
}
67+
return this;
68+
}
69+
5770
/**
5871
* Adds the specified values and returns this object.
5972
*

0 commit comments

Comments
 (0)