Use lambda expressions for lazy instantiation (#1911)

Issue: SPR-17074
This commit is contained in:
Сергей Цыпанов
2018-07-31 14:03:18 +03:00
committed by Sam Brannen
parent 487e14d549
commit f8340838b3
11 changed files with 11 additions and 11 deletions

View File

@@ -172,7 +172,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
@Override
protected <T> T getBean(Class<T> type) {
Assert.state(this.beanFactory != null, "BeanFactory required for resolution of [" + type + "]");
Assert.state(this.beanFactory != null, () -> "BeanFactory required for resolution of [" + type + "]");
try {
return this.beanFactory.getBean(type);
}

View File

@@ -55,7 +55,7 @@ public class NoOpCacheManager implements CacheManager {
public Cache getCache(String name) {
Cache cache = this.caches.get(name);
if (cache == null) {
this.caches.putIfAbsent(name, new NoOpCache(name));
this.caches.computeIfAbsent(name, key -> new NoOpCache(name));
synchronized (this.cacheNames) {
this.cacheNames.add(name);
}

View File

@@ -147,7 +147,7 @@ class DefaultMvcResult implements MvcResult {
" was not set during the specified timeToWait=" + timeToWait);
}
Object result = this.asyncResult.get();
Assert.state(result != RESULT_NONE, "Async result for handler [" + this.handler + "] was not set");
Assert.state(result != RESULT_NONE, () -> "Async result for handler [" + this.handler + "] was not set");
return this.asyncResult.get();
}

View File

@@ -90,7 +90,7 @@ public interface ServerWebExchange {
@SuppressWarnings("unchecked")
default <T> T getRequiredAttribute(String name) {
T value = getAttribute(name);
Assert.notNull(value, "Required attribute '" + name + "' is missing.");
Assert.notNull(value, () -> "Required attribute '" + name + "' is missing.");
return value;
}

View File

@@ -71,7 +71,7 @@ public interface WebSession {
@SuppressWarnings("unchecked")
default <T> T getRequiredAttribute(String name) {
T value = getAttribute(name);
Assert.notNull(value, "Required attribute '" + name + "' is missing.");
Assert.notNull(value, () -> "Required attribute '" + name + "' is missing.");
return value;
}

View File

@@ -94,7 +94,7 @@ public abstract class ExchangeFilterFunctions {
return ExchangeFilterFunction.ofRequestProcessor(request ->
credentialsFunction.apply(request)
.map(credentials -> Mono.just(insertAuthorizationHeader(request, credentials)))
.orElse(Mono.just(request)));
.orElseGet(() -> Mono.just(request)));
}
private static void checkIllegalCharacters(String username, String password) {

View File

@@ -139,7 +139,7 @@ class ModelInitializer {
.ofNullable(AnnotatedElementUtils.findMergedAnnotation(param.getAnnotatedElement(), ModelAttribute.class))
.filter(ann -> StringUtils.hasText(ann.value()))
.map(ModelAttribute::value)
.orElse(Conventions.getVariableNameForParameter(param));
.orElseGet(() -> Conventions.getVariableNameForParameter(param));
}
/** Find {@code @ModelAttribute} arguments also listed as {@code @SessionAttributes}. */

View File

@@ -244,7 +244,7 @@ public class RedirectView extends AbstractUrlBasedView {
while (found) {
String name = matcher.group(1);
Object value = (model.containsKey(name) ? model.get(name) : uriVariables.get(name));
Assert.notNull(value, "No value for URI variable '" + name + "'");
Assert.notNull(value, () -> "No value for URI variable '" + name + "'");
result.append(targetUrl.substring(endLastMatch, matcher.start()));
result.append(encodeUriVariable(value.toString()));
endLastMatch = matcher.end();

View File

@@ -286,7 +286,7 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport
return Optional.ofNullable(returnType.getMethodAnnotation(ModelAttribute.class))
.filter(ann -> StringUtils.hasText(ann.value()))
.map(ModelAttribute::value)
.orElse(Conventions.getVariableNameForParameter(returnType));
.orElseGet(() -> Conventions.getVariableNameForParameter(returnType));
}
private void updateBindingContext(BindingContext context, ServerWebExchange exchange) {

View File

@@ -120,7 +120,7 @@ class ReactiveTypeHandler {
Assert.notNull(returnValue, "Expected return value");
ReactiveAdapter adapter = this.reactiveRegistry.getAdapter(returnValue.getClass());
Assert.state(adapter != null, "Unexpected return value: " + returnValue);
Assert.state(adapter != null, () -> "Unexpected return value: " + returnValue);
ResolvableType elementType = ResolvableType.forMethodParameter(returnType).getGeneric();
Class<?> elementClass = elementType.toClass();

View File

@@ -159,7 +159,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
List<String> paths = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
for (String path : paths) {
path = path.trim();
Assert.state(StringUtils.hasText(path), "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
Assert.state(StringUtils.hasText(path), () -> "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
if (DomUtils.getChildElementByTagName(endpointElem, "sockjs") != null) {
path = path.endsWith("/") ? path + "**" : path + "/**";
}