Skip to content

Commit

Permalink
Simplify code by using Map computeIfAbsent
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-suhorukov authored and snicoll committed Dec 21, 2018
1 parent b8c82ec commit cbf6b33
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ private void processMethod(ExecutableElement method) {
else if (isSetter(method)) {
String propertyName = getAccessorName(name);
List<ExecutableElement> matchingSetters = this.publicSetters
.get(propertyName);
if (matchingSetters == null) {
matchingSetters = new ArrayList<>();
this.publicSetters.put(propertyName, matchingSetters);
}
.computeIfAbsent(propertyName, (k) -> new ArrayList<>());
TypeMirror paramType = method.getParameters().get(0).asType();
if (getMatchingSetter(matchingSetters, paramType) == null) {
matchingSetters.add(method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,7 @@ protected void mergeItemMetadata(ItemMetadata metadata) {
}

private <K, V> void add(Map<K, List<V>> map, K key, V value) {
List<V> values = map.get(key);
if (values == null) {
values = new ArrayList<>();
map.put(key, values);
}
List<V> values = map.computeIfAbsent(key, (k) -> new ArrayList<>());
values.add(value);
}

Expand Down

0 comments on commit cbf6b33

Please sign in to comment.