Skip to content

Commit

Permalink
WW-5370 Uses TreeMap with case-insensitive comparator
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Dec 12, 2023
1 parent 13d972d commit c40978f
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class HttpParameters implements Map<String, Parameter> {
final private Map<String, Parameter> parameters;

private HttpParameters(Map<String, Parameter> parameters) {
this.parameters = parameters;
this.parameters = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
this.parameters.putAll(parameters);
}

@SuppressWarnings("rawtypes")
Expand All @@ -43,7 +44,7 @@ public static Builder create(Map requestParameterMap) {
}

public static Builder create() {
return new Builder(new HashMap<>());
return new Builder(new TreeMap<>(String.CASE_INSENSITIVE_ORDER));
}

public HttpParameters remove(Set<String> paramsToRemove) {
Expand All @@ -60,7 +61,7 @@ public HttpParameters remove(final String paramToRemove) {
}

public boolean contains(String name) {
return parameters.keySet().stream().anyMatch(p -> p.equalsIgnoreCase(name));
return parameters.containsKey(name);
}

/**
Expand Down Expand Up @@ -112,10 +113,7 @@ public boolean containsValue(Object value) {
@Override
public Parameter get(Object key) {
if (key != null && contains(String.valueOf(key))) {
return parameters.entrySet().stream()
.filter(p -> p.getKey().equalsIgnoreCase(String.valueOf(key)))
.findFirst().map(Entry::getValue)
.orElse(new Parameter.Empty(String.valueOf(key)));
return parameters.get(key);
} else {
return new Parameter.Empty(String.valueOf(key));
}
Expand Down

0 comments on commit c40978f

Please sign in to comment.