Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90b98b5

Browse files
committed
Replaced loops with Java8 idioms
Cleaned up unescessary casting (1773)
1 parent 6cc49b2 commit 90b98b5

4 files changed

Lines changed: 22 additions & 35 deletions

File tree

springfox-spring-webflux/src/main/java/springfox/documentation/spring/web/WebFluxNameValueExpressionWrapper.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@
2727
public class WebFluxNameValueExpressionWrapper<T> implements NameValueExpression {
2828
private org.springframework.web.reactive.result.condition.NameValueExpression<T> e;
2929

30-
public static <T> Set<NameValueExpression<T>> from(Set<org.springframework.web.reactive.result.condition.NameValueExpression<T>> springSet) {
31-
Set<NameValueExpression<T>> wrapped = new HashSet<NameValueExpression<T>>();
3230

33-
for (org.springframework.web.reactive.result.condition.NameValueExpression e: springSet) {
34-
wrapped.add(new WebFluxNameValueExpressionWrapper<T>(e));
35-
}
31+
public static <T> Set<NameValueExpression<T>> from(
32+
Set<org.springframework.web.reactive.result.condition.NameValueExpression<T>> springSet) {
3633

37-
return wrapped;
38-
}
34+
return springSet.stream()
35+
.map(WebFluxNameValueExpressionWrapper::new)
36+
.collect(Collectors.toSet());
37+
}
3938

4039
public WebFluxNameValueExpressionWrapper(org.springframework.web.reactive.result.condition.NameValueExpression<T> e) {
4140
this.e = e;

springfox-spring-webflux/src/main/java/springfox/documentation/spring/web/plugins/WebFluxRequestHandlerProvider.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,15 @@ public List<RequestHandler> requestHandlers() {
6363
.collect(toList());
6464
}
6565

66-
private Function<? super RequestMappingInfoHandlerMapping,
67-
Iterable<Map.Entry<RequestMappingInfo, HandlerMethod>>> toMappingEntries() {
68-
return new Function<RequestMappingInfoHandlerMapping, Iterable<Map.Entry<RequestMappingInfo, HandlerMethod>>>() {
69-
@Override
70-
public Iterable<Map.Entry<RequestMappingInfo, HandlerMethod>> apply(RequestMappingInfoHandlerMapping input) {
71-
return input.getHandlerMethods().entrySet();
72-
}
73-
};
66+
private Function<RequestMappingInfoHandlerMapping,
67+
Iterable<Map.Entry<RequestMappingInfo, HandlerMethod>>> toMappingEntries() {
68+
return input -> input.getHandlerMethods().entrySet();
7469
}
7570

7671
private Function<Map.Entry<RequestMappingInfo, HandlerMethod>, RequestHandler> toRequestHandler() {
77-
return new Function<Map.Entry<RequestMappingInfo, HandlerMethod>, RequestHandler>() {
78-
@Override
79-
public WebFluxRequestHandler apply(Map.Entry<RequestMappingInfo, HandlerMethod> input) {
80-
return new WebFluxRequestHandler(
81-
methodResolver,
82-
input.getKey(),
83-
input.getValue());
84-
}
85-
};
72+
return input -> new WebFluxRequestHandler(
73+
methodResolver,
74+
input.getKey(),
75+
input.getValue());
8676
}
8777
}

springfox-spring-webmvc/src/main/java/springfox/documentation/spring/web/WebMvcNameValueExpressionWrapper.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@
2727
public class WebMvcNameValueExpressionWrapper<T> implements NameValueExpression {
2828
private org.springframework.web.servlet.mvc.condition.NameValueExpression<T> e;
2929

30-
public static <T> Set<NameValueExpression<T>> from(Set<org.springframework.web.servlet.mvc.condition.NameValueExpression<T>> springSet) {
31-
Set<NameValueExpression<T>> wrapped = new HashSet<NameValueExpression<T>>();
3230

33-
for (org.springframework.web.servlet.mvc.condition.NameValueExpression e: springSet) {
34-
wrapped.add(new WebMvcNameValueExpressionWrapper<T>(e));
35-
}
31+
public static <T> Set<NameValueExpression<T>> from(
32+
Set<org.springframework.web.servlet.mvc.condition.NameValueExpression<T>> springSet) {
3633

37-
return wrapped;
38-
}
34+
return springSet.stream()
35+
.map(WebMvcNameValueExpressionWrapper::new)
36+
.collect(Collectors.toSet());
37+
}
3938

4039
public WebMvcNameValueExpressionWrapper(org.springframework.web.servlet.mvc.condition.NameValueExpression<T> e) {
4140
this.e = e;

springfox-spring-webmvc/src/main/java/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ public List<RequestHandler> requestHandlers() {
6464
.collect(toList());
6565
}
6666

67-
private Function<? super RequestMappingInfoHandlerMapping,
68-
Iterable<Map.Entry<RequestMappingInfo, HandlerMethod>>> toMappingEntries() {
69-
return (Function<RequestMappingInfoHandlerMapping, Iterable<Map.Entry<RequestMappingInfo, HandlerMethod>>>)
70-
input -> input.getHandlerMethods().entrySet();
67+
private Function<RequestMappingInfoHandlerMapping,
68+
Iterable<Map.Entry<RequestMappingInfo, HandlerMethod>>> toMappingEntries() {
69+
return input -> input.getHandlerMethods().entrySet();
7170
}
7271

7372
private Function<Map.Entry<RequestMappingInfo, HandlerMethod>, RequestHandler> toRequestHandler() {

0 commit comments

Comments
 (0)