Use Collection.removeIf() where possible (#1747)

Use Collection.removeIf() where possible

Issue: SPR-16622
This commit is contained in:
Christoph Dreis
2018-03-22 11:36:11 +01:00
committed by Juergen Hoeller
parent e0de9126ed
commit d3a0a8e007
7 changed files with 19 additions and 67 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ package org.springframework.web.reactive.result.condition;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -168,12 +167,7 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition<Con
return this;
}
Set<ConsumeMediaTypeExpression> result = new LinkedHashSet<>(expressions);
for (Iterator<ConsumeMediaTypeExpression> iterator = result.iterator(); iterator.hasNext();) {
ConsumeMediaTypeExpression expression = iterator.next();
if (!expression.match(exchange)) {
iterator.remove();
}
}
result.removeIf(expression -> !expression.match(exchange));
return (result.isEmpty()) ? null : new ConsumesRequestCondition(result);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ package org.springframework.web.reactive.result.condition;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -192,12 +191,7 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
return this;
}
Set<ProduceMediaTypeExpression> result = new LinkedHashSet<>(expressions);
for (Iterator<ProduceMediaTypeExpression> iterator = result.iterator(); iterator.hasNext();) {
ProduceMediaTypeExpression expression = iterator.next();
if (!expression.match(exchange)) {
iterator.remove();
}
}
result.removeIf(expression -> !expression.match(exchange));
return (result.isEmpty()) ? null : new ProducesRequestCondition(result, this.contentTypeResolver);
}