From 40efcc933ca2cb5733655d114f36be035dc9fd54 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 28 Jun 2018 14:51:31 +0200 Subject: [PATCH] Polishing --- .../aop/framework/CglibAopProxy.java | 12 ++-- .../aop/support/ControlFlowPointcut.java | 4 +- .../aop/support/MethodMatchers.java | 24 ++++---- .../beans/MutablePropertyValues.java | 10 +--- .../factory/CannotLoadBeanClassException.java | 10 ++-- .../config/FieldRetrievingFactoryBean.java | 2 +- .../groovy/GroovyBeanDefinitionReader.java | 5 +- .../beans/factory/parsing/ParseState.java | 4 +- .../support/AbstractBeanDefinition.java | 57 +++++++++---------- .../support/BeanDefinitionResource.java | 9 ++- .../support/DefaultListableBeanFactory.java | 4 +- .../xml/BeanDefinitionParserDelegate.java | 6 +- .../index/CandidateComponentsIndexer.java | 10 ++-- .../interceptor/AbstractJCacheOperation.java | 9 ++- .../DefaultCacheMethodDetails.java | 5 +- .../commonj/TimerManagerTaskScheduler.java | 4 +- .../quartz/SchedulerFactoryBean.java | 2 +- .../cache/interceptor/SimpleKey.java | 13 +++-- .../annotation/ConfigurationClassParser.java | 10 ++-- .../support/AbstractApplicationContext.java | 8 +-- .../scheduling/support/PeriodicTrigger.java | 12 ++-- .../validation/DataBinder.java | 4 +- .../core/AttributeAccessorSupport.java | 10 +--- .../core/ParameterizedTypeReference.java | 6 +- .../core/ReactiveAdapterRegistry.java | 4 -- .../core/env/ProfilesParser.java | 29 ++++------ .../core/env/PropertySource.java | 6 +- .../core/io/AbstractResource.java | 20 +++---- .../core/io/ByteArrayResource.java | 8 +-- .../core/io/ClassPathResource.java | 16 +++--- .../core/io/DescriptiveResource.java | 8 +-- .../core/io/FileSystemResource.java | 6 +- .../core/io/InputStreamResource.java | 8 +-- .../springframework/core/io/PathResource.java | 6 +- .../springframework/core/io/UrlResource.java | 8 +-- .../springframework/core/io/VfsResource.java | 7 ++- .../core/io/buffer/DataBuffer.java | 27 ++++----- .../core/io/buffer/DefaultDataBuffer.java | 48 +++++++--------- .../core/io/buffer/NettyDataBuffer.java | 21 +++---- .../util/ConcurrentReferenceHashMap.java | 8 +-- .../util/comparator/BooleanComparator.java | 8 +-- .../util/comparator/CompoundComparator.java | 12 +--- .../util/comparator/InvertibleComparator.java | 10 ++-- .../util/comparator/NullSafeComparator.java | 10 ++-- .../core/env/DummyEnvironment.java | 1 + .../converter/MessagingMessageConverter.java | 4 +- .../handler/AbstractMessageCondition.java | 41 +++++++------ .../simp/SimpMessageMappingInfo.java | 14 ++--- .../SpringFlushSynchronization.java | 8 +-- .../context/SpringContextResourceAdapter.java | 6 +- .../DelegatingTransactionDefinition.java | 4 +- .../http/client/MultipartBodyBuilder.java | 6 +- .../http/codec/ResourceHttpMessageWriter.java | 5 +- .../http/server/DefaultRequestPath.java | 10 ++-- .../support/ServletContextResource.java | 12 ++-- .../web/multipart/MultipartFileResource.java | 6 +- .../web/util/HierarchicalUriComponents.java | 39 ++++++------- .../web/util/OpaqueUriComponents.java | 18 +++--- .../web/method/ResolvableMethod.java | 16 +++--- .../accept/HeaderContentTypeResolver.java | 3 +- .../RequestedContentTypeResolverBuilder.java | 10 ++-- .../reactive/config/PathMatchConfigurer.java | 4 +- .../function/client/DefaultWebClient.java | 3 +- .../client/DefaultWebClientBuilder.java | 5 +- .../client/ExchangeFilterFunctions.java | 27 +++------ .../function/client/ExchangeFunctions.java | 3 +- .../server/DefaultServerRequestBuilder.java | 2 +- .../server/support/RouterFunctionMapping.java | 6 +- .../AbstractPrefixVersionStrategy.java | 6 +- .../resource/CachingResourceResolver.java | 5 +- .../resource/CssLinkResourceTransformer.java | 15 +++-- .../resource/EncodedResourceResolver.java | 31 ++++------ .../reactive/resource/ResourceWebHandler.java | 10 ++-- .../AbstractMediaTypeExpression.java | 15 ++--- .../AbstractNameValueExpression.java | 18 +++--- .../condition/AbstractRequestCondition.java | 16 +++--- .../condition/CompositeRequestCondition.java | 4 +- .../condition/ConsumesRequestCondition.java | 4 +- .../condition/PatternsRequestCondition.java | 10 +--- .../condition/ProducesRequestCondition.java | 4 +- .../result/method/InvocableHandlerMethod.java | 10 ++-- .../result/method/RequestMappingInfo.java | 4 +- ...AbstractMessageReaderArgumentResolver.java | 9 +-- .../AbstractMessageWriterResultHandler.java | 9 ++- .../HttpEntityArgumentResolver.java | 10 ++-- .../annotation/PrincipalArgumentResolver.java | 9 ++- .../RequestPartMethodArgumentResolver.java | 7 +-- .../ServerWebExchangeArgumentResolver.java | 4 +- .../WebSessionArgumentResolver.java | 4 +- .../result/view/HttpMessageWriterView.java | 16 ++---- .../view/script/ScriptTemplateView.java | 4 +- .../AbstractListenerWebSocketSession.java | 9 ++- .../upgrade/JettyRequestUpgradeStrategy.java | 5 +- .../HeadersRequestConditionTests.java | 2 +- .../annotation/PathMatchConfigurer.java | 6 +- .../AbstractMediaTypeExpression.java | 14 ++--- .../AbstractNameValueExpression.java | 18 +++--- .../condition/AbstractRequestCondition.java | 11 ++-- .../condition/CompositeRequestCondition.java | 2 +- .../condition/ConsumesRequestCondition.java | 2 +- .../condition/PatternsRequestCondition.java | 13 ++--- .../resource/AbstractVersionStrategy.java | 4 +- .../resource/CachingResourceResolver.java | 5 +- .../resource/CssLinkResourceTransformer.java | 14 ++--- .../resource/EncodedResourceResolver.java | 30 ++++------ .../view/script/ScriptTemplateView.java | 2 +- .../HeadersRequestConditionTests.java | 2 +- 107 files changed, 506 insertions(+), 620 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java index 9a9b0e285ad..eb73d50ec6f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java @@ -291,20 +291,20 @@ class CglibAopProxy implements AopProxy, Serializable { // unadvised but can return this). May be required to expose the proxy. Callback targetInterceptor; if (exposeProxy) { - targetInterceptor = isStatic ? + targetInterceptor = (isStatic ? new StaticUnadvisedExposedInterceptor(this.advised.getTargetSource().getTarget()) : - new DynamicUnadvisedExposedInterceptor(this.advised.getTargetSource()); + new DynamicUnadvisedExposedInterceptor(this.advised.getTargetSource())); } else { - targetInterceptor = isStatic ? + targetInterceptor = (isStatic ? new StaticUnadvisedInterceptor(this.advised.getTargetSource().getTarget()) : - new DynamicUnadvisedInterceptor(this.advised.getTargetSource()); + new DynamicUnadvisedInterceptor(this.advised.getTargetSource())); } // Choose a "direct to target" dispatcher (used for // unadvised calls to static targets that cannot return this). - Callback targetDispatcher = isStatic ? - new StaticDispatcher(this.advised.getTargetSource().getTarget()) : new SerializableNoOp(); + Callback targetDispatcher = (isStatic ? + new StaticDispatcher(this.advised.getTargetSource().getTarget()) : new SerializableNoOp()); Callback[] mainCallbacks = new Callback[] { aopInterceptor, // for normal advice diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java index 1f2e65f113c..67fed08bd91 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -131,7 +131,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher return false; } ControlFlowPointcut that = (ControlFlowPointcut) other; - return (this.clazz.equals(that.clazz)) && ObjectUtils.nullSafeEquals(that.methodName, this.methodName); + return (this.clazz.equals(that.clazz)) && ObjectUtils.nullSafeEquals(this.methodName, that.methodName); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java b/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java index 5f6032087fb..12ff34e66e3 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java @@ -144,14 +144,14 @@ public abstract class MethodMatchers { } @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (!(obj instanceof UnionMethodMatcher)) { + if (!(other instanceof UnionMethodMatcher)) { return false; } - UnionMethodMatcher that = (UnionMethodMatcher) obj; + UnionMethodMatcher that = (UnionMethodMatcher) other; return (this.mm1.equals(that.mm1) && this.mm2.equals(that.mm2)); } @@ -239,18 +239,18 @@ public abstract class MethodMatchers { @Override public boolean matches(Method method, @Nullable Class targetClass, boolean hasIntroductions) { - return MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions) && - MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions); + return (MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions) && + MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions)); } @Override public boolean matches(Method method, @Nullable Class targetClass) { - return this.mm1.matches(method, targetClass) && this.mm2.matches(method, targetClass); + return (this.mm1.matches(method, targetClass) && this.mm2.matches(method, targetClass)); } @Override public boolean isRuntime() { - return this.mm1.isRuntime() || this.mm2.isRuntime(); + return (this.mm1.isRuntime() || this.mm2.isRuntime()); } @Override @@ -258,10 +258,10 @@ public abstract class MethodMatchers { // Because a dynamic intersection may be composed of a static and dynamic part, // we must avoid calling the 3-arg matches method on a dynamic matcher, as // it will probably be an unsupported operation. - boolean aMatches = this.mm1.isRuntime() ? - this.mm1.matches(method, targetClass, args) : this.mm1.matches(method, targetClass); - boolean bMatches = this.mm2.isRuntime() ? - this.mm2.matches(method, targetClass, args) : this.mm2.matches(method, targetClass); + boolean aMatches = (this.mm1.isRuntime() ? + this.mm1.matches(method, targetClass, args) : this.mm1.matches(method, targetClass)); + boolean bMatches = (this.mm2.isRuntime() ? + this.mm2.matches(method, targetClass, args) : this.mm2.matches(method, targetClass)); return aMatches && bMatches; } diff --git a/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java b/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java index f173bf70b48..9ba71876870 100644 --- a/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java +++ b/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java @@ -348,14 +348,8 @@ public class MutablePropertyValues implements PropertyValues, Serializable { @Override public boolean equals(Object other) { - if (this == other) { - return true; - } - if (!(other instanceof MutablePropertyValues)) { - return false; - } - MutablePropertyValues that = (MutablePropertyValues) other; - return this.propertyValueList.equals(that.propertyValueList); + return (this == other || (other instanceof MutablePropertyValues && + this.propertyValueList.equals(((MutablePropertyValues) other).propertyValueList))); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java b/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java index b8b2a1e3bbd..e8a3dd10805 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java @@ -32,7 +32,6 @@ public class CannotLoadBeanClassException extends FatalBeanException { @Nullable private final String resourceDescription; - @Nullable private final String beanName; @Nullable @@ -47,8 +46,8 @@ public class CannotLoadBeanClassException extends FatalBeanException { * @param beanClassName the name of the bean class * @param cause the root cause */ - public CannotLoadBeanClassException( - @Nullable String resourceDescription, String beanName, @Nullable String beanClassName, ClassNotFoundException cause) { + public CannotLoadBeanClassException(@Nullable String resourceDescription, String beanName, + @Nullable String beanClassName, ClassNotFoundException cause) { super("Cannot find class [" + beanClassName + "] for bean with name '" + beanName + "'" + (resourceDescription != null ? " defined in " + resourceDescription : ""), cause); @@ -65,8 +64,8 @@ public class CannotLoadBeanClassException extends FatalBeanException { * @param beanClassName the name of the bean class * @param cause the root cause */ - public CannotLoadBeanClassException( - @Nullable String resourceDescription, String beanName, @Nullable String beanClassName, LinkageError cause) { + public CannotLoadBeanClassException(@Nullable String resourceDescription, String beanName, + @Nullable String beanClassName, LinkageError cause) { super("Error loading class [" + beanClassName + "] for bean with name '" + beanName + "'" + (resourceDescription != null ? " defined in " + resourceDescription : "") + @@ -89,7 +88,6 @@ public class CannotLoadBeanClassException extends FatalBeanException { /** * Return the name of the bean requested. */ - @Nullable public String getBeanName() { return this.beanName; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java index ba731cbfff7..99e21c4582f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java @@ -203,7 +203,7 @@ public class FieldRetrievingFactoryBean } // Try to get the exact method first. - Class targetClass = (this.targetObject != null) ? this.targetObject.getClass() : this.targetClass; + Class targetClass = (this.targetObject != null ? this.targetObject.getClass() : this.targetClass); this.fieldObject = targetClass.getField(this.targetField); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java index cb30ff8c88d..a474a0d7918 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java @@ -374,7 +374,6 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp if (args[0] == null) { throw new IllegalArgumentException("Argument to ref() is not a valid bean or was not found"); } - if (args[0] instanceof RuntimeBeanReference) { refName = ((RuntimeBeanReference) args[0]).getBeanName(); } @@ -490,11 +489,11 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp Map.Entry factoryBeanEntry = (Map.Entry) ((Map) args[0]).entrySet().iterator().next(); // If we have a closure body, that will be the last argument. // In between are the constructor args - int constructorArgsTest = hasClosureArgument?2:1; + int constructorArgsTest = (hasClosureArgument ? 2 : 1); // If we have more than this number of args, we have constructor args if (args.length > constructorArgsTest){ // factory-method requires args - int endOfConstructArgs = (hasClosureArgument? args.length - 1 : args.length); + int endOfConstructArgs = (hasClosureArgument ? args.length - 1 : args.length); this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName, null, resolveConstructorArguments(args, 1, endOfConstructArgs)); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java index ec0f9a3ed06..3e0d632a32a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java @@ -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. @@ -82,7 +82,7 @@ public final class ParseState { */ @Nullable public Entry peek() { - return this.state.isEmpty() ? null : this.state.peek(); + return this.state.peek(); } /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java index ec3e2d856e5..d02997186cc 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java @@ -1114,39 +1114,38 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess public abstract AbstractBeanDefinition cloneBeanDefinition(); @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (!(obj instanceof AbstractBeanDefinition)) { + if (!(other instanceof AbstractBeanDefinition)) { return false; } - AbstractBeanDefinition other = (AbstractBeanDefinition) obj; - boolean rtn = true; - rtn = rtn &= ObjectUtils.nullSafeEquals(getBeanClassName(), other.getBeanClassName()); - rtn = rtn &= ObjectUtils.nullSafeEquals(this.scope, other.scope); - rtn = rtn &= this.abstractFlag == other.abstractFlag; - rtn = rtn &= this.lazyInit == other.lazyInit; - rtn = rtn &= this.autowireMode == other.autowireMode; - rtn = rtn &= this.dependencyCheck == other.dependencyCheck; - rtn = rtn &= Arrays.equals(this.dependsOn, other.dependsOn); - rtn = rtn &= this.autowireCandidate == other.autowireCandidate; - rtn = rtn &= ObjectUtils.nullSafeEquals(this.qualifiers, other.qualifiers); - rtn = rtn &= this.primary == other.primary; - rtn = rtn &= this.nonPublicAccessAllowed == other.nonPublicAccessAllowed; - rtn = rtn &= this.lenientConstructorResolution == other.lenientConstructorResolution; - rtn = rtn &= ObjectUtils.nullSafeEquals(this.constructorArgumentValues, other.constructorArgumentValues); - rtn = rtn &= ObjectUtils.nullSafeEquals(this.propertyValues, other.propertyValues); - rtn = rtn &= ObjectUtils.nullSafeEquals(this.methodOverrides, other.methodOverrides); - rtn = rtn &= ObjectUtils.nullSafeEquals(this.factoryBeanName, other.factoryBeanName); - rtn = rtn &= ObjectUtils.nullSafeEquals(this.factoryMethodName, other.factoryMethodName); - rtn = rtn &= ObjectUtils.nullSafeEquals(this.initMethodName, other.initMethodName); - rtn = rtn &= this.enforceInitMethod == other.enforceInitMethod; - rtn = rtn &= ObjectUtils.nullSafeEquals(this.destroyMethodName, other.destroyMethodName); - rtn = rtn &= this.enforceDestroyMethod == other.enforceDestroyMethod; - rtn = rtn &= this.synthetic == other.synthetic; - rtn = rtn &= this.role == other.role; - return rtn && super.equals(obj); + AbstractBeanDefinition that = (AbstractBeanDefinition) other; + boolean rtn = ObjectUtils.nullSafeEquals(getBeanClassName(), that.getBeanClassName()); + rtn = rtn &= ObjectUtils.nullSafeEquals(this.scope, that.scope); + rtn = rtn &= this.abstractFlag == that.abstractFlag; + rtn = rtn &= this.lazyInit == that.lazyInit; + rtn = rtn &= this.autowireMode == that.autowireMode; + rtn = rtn &= this.dependencyCheck == that.dependencyCheck; + rtn = rtn &= Arrays.equals(this.dependsOn, that.dependsOn); + rtn = rtn &= this.autowireCandidate == that.autowireCandidate; + rtn = rtn &= ObjectUtils.nullSafeEquals(this.qualifiers, that.qualifiers); + rtn = rtn &= this.primary == that.primary; + rtn = rtn &= this.nonPublicAccessAllowed == that.nonPublicAccessAllowed; + rtn = rtn &= this.lenientConstructorResolution == that.lenientConstructorResolution; + rtn = rtn &= ObjectUtils.nullSafeEquals(this.constructorArgumentValues, that.constructorArgumentValues); + rtn = rtn &= ObjectUtils.nullSafeEquals(this.propertyValues, that.propertyValues); + rtn = rtn &= ObjectUtils.nullSafeEquals(this.methodOverrides, that.methodOverrides); + rtn = rtn &= ObjectUtils.nullSafeEquals(this.factoryBeanName, that.factoryBeanName); + rtn = rtn &= ObjectUtils.nullSafeEquals(this.factoryMethodName, that.factoryMethodName); + rtn = rtn &= ObjectUtils.nullSafeEquals(this.initMethodName, that.initMethodName); + rtn = rtn &= this.enforceInitMethod == that.enforceInitMethod; + rtn = rtn &= ObjectUtils.nullSafeEquals(this.destroyMethodName, that.destroyMethodName); + rtn = rtn &= this.enforceDestroyMethod == that.enforceDestroyMethod; + rtn = rtn &= this.synthetic == that.synthetic; + rtn = rtn &= this.role == that.role; + return rtn && super.equals(other); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java index 7de75a1be60..59dc1267619 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -80,10 +80,9 @@ class BeanDefinitionResource extends AbstractResource { * This implementation compares the underlying BeanDefinition. */ @Override - public boolean equals(Object obj) { - return (obj == this || - (obj instanceof BeanDefinitionResource && - ((BeanDefinitionResource) obj).beanDefinition.equals(this.beanDefinition))); + public boolean equals(Object other) { + return (this == other || (other instanceof BeanDefinitionResource && + ((BeanDefinitionResource) other).beanDefinition.equals(this.beanDefinition))); } /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index 3c8fce37e0d..552ab5a8501 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -1521,8 +1521,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto isAutowireCandidate(beanName, mbd, descriptor, getAutowireCandidateResolver())) { // Probably a proxy interfering with target type match -> throw meaningful exception. Object beanInstance = getSingleton(beanName, false); - Class beanType = (beanInstance != null && beanInstance.getClass() != NullBean.class) ? - beanInstance.getClass() : predictBeanType(beanName, mbd); + Class beanType = (beanInstance != null && beanInstance.getClass() != NullBean.class ? + beanInstance.getClass() : predictBeanType(beanName, mbd)); if (beanType != null && !type.isAssignableFrom(beanType)) { throw new BeanNotOfRequiredTypeException(beanName, type, beanType); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java index e862eb8c3f8..3dc012d5a70 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java @@ -900,9 +900,9 @@ public class BeanDefinitionParserDelegate { */ @Nullable public Object parsePropertyValue(Element ele, BeanDefinition bd, @Nullable String propertyName) { - String elementName = (propertyName != null) ? - " element for property '" + propertyName + "'" : - " element"; + String elementName = (propertyName != null ? + " element for property '" + propertyName + "'" : + " element"); // Should only have one child element: ref, value, list, etc. NodeList nl = ele.getChildNodes(); diff --git a/spring-context-indexer/src/main/java/org/springframework/context/index/CandidateComponentsIndexer.java b/spring-context-indexer/src/main/java/org/springframework/context/index/CandidateComponentsIndexer.java index 86b75027c5f..6a7e1e0ddca 100644 --- a/spring-context-indexer/src/main/java/org/springframework/context/index/CandidateComponentsIndexer.java +++ b/spring-context-indexer/src/main/java/org/springframework/context/index/CandidateComponentsIndexer.java @@ -46,8 +46,7 @@ import javax.lang.model.element.TypeElement; public class CandidateComponentsIndexer implements Processor { private static final Set TYPE_KINDS = - Collections.unmodifiableSet(EnumSet.of(ElementKind.CLASS, - ElementKind.INTERFACE)); + Collections.unmodifiableSet(EnumSet.of(ElementKind.CLASS, ElementKind.INTERFACE)); private MetadataStore metadataStore; @@ -135,10 +134,9 @@ public class CandidateComponentsIndexer implements Processor { private static List staticTypesIn(Iterable elements) { List list = new ArrayList<>(); - for (Element e : elements) { - if (TYPE_KINDS.contains(e.getKind()) - && e.getModifiers().contains(Modifier.STATIC)) { - list.add(TypeElement.class.cast(e)); + for (Element element : elements) { + if (TYPE_KINDS.contains(element.getKind()) && element.getModifiers().contains(Modifier.STATIC)) { + list.add(TypeElement.class.cast(element)); } } return list; diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java index 87260a66c38..a9b186a0705 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java @@ -19,6 +19,7 @@ package org.springframework.cache.jcache.interceptor; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; @@ -32,8 +33,6 @@ import org.springframework.cache.interceptor.CacheResolver; import org.springframework.util.Assert; import org.springframework.util.ExceptionTypeFilter; -import static java.util.Arrays.asList; - /** * A base {@link JCacheOperation} implementation. * @@ -56,8 +55,8 @@ abstract class AbstractJCacheOperation implements JCacheOp * @param cacheResolver the cache resolver to resolve regular caches */ protected AbstractJCacheOperation(CacheMethodDetails methodDetails, CacheResolver cacheResolver) { - Assert.notNull(methodDetails, "method details must not be null."); - Assert.notNull(cacheResolver, "cache resolver must not be null."); + Assert.notNull(methodDetails, "CacheMethodDetails must not be null"); + Assert.notNull(cacheResolver, "CacheResolver must not be null"); this.methodDetails = methodDetails; this.cacheResolver = cacheResolver; this.allParameterDetails = initializeAllParameterDetails(methodDetails.getMethod()); @@ -117,7 +116,7 @@ abstract class AbstractJCacheOperation implements JCacheOp protected ExceptionTypeFilter createExceptionTypeFilter( Class[] includes, Class[] excludes) { - return new ExceptionTypeFilter(asList(includes), asList(excludes), true); + return new ExceptionTypeFilter(Arrays.asList(includes), Arrays.asList(excludes), true); } @Override diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheMethodDetails.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheMethodDetails.java index 1327e2de9f6..719825785e1 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheMethodDetails.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheMethodDetails.java @@ -18,13 +18,12 @@ package org.springframework.cache.jcache.interceptor; import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; import javax.cache.annotation.CacheMethodDetails; -import static java.util.Arrays.asList; - /** * The default {@link CacheMethodDetails} implementation. * @@ -46,7 +45,7 @@ class DefaultCacheMethodDetails implements CacheMethodDeta public DefaultCacheMethodDetails(Method method, A cacheAnnotation, String cacheName) { this.method = method; this.annotations = Collections.unmodifiableSet( - new LinkedHashSet<>(asList(method.getAnnotations()))); + new LinkedHashSet<>(Arrays.asList(method.getAnnotations()))); this.cacheAnnotation = cacheAnnotation; this.cacheName = cacheName; } diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerTaskScheduler.java b/spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerTaskScheduler.java index b77a5073fba..fab42b61f9b 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerTaskScheduler.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerTaskScheduler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -151,7 +151,7 @@ public class TimerManagerTaskScheduler extends TimerManagerAccessor implements T return 0; } long diff = getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS); - return (diff == 0 ? 0 : ((diff < 0)? -1 : 1)); + return (diff == 0 ? 0 : ((diff < 0) ? -1 : 1)); } } diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java index 4e86574e1d5..6ae6bff1210 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java @@ -759,7 +759,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe @Override public Class getObjectType() { - return (this.scheduler != null) ? this.scheduler.getClass() : Scheduler.class; + return (this.scheduler != null ? this.scheduler.getClass() : Scheduler.class); } @Override diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java index febe9d8ee2d..43bff763ebd 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java @@ -32,12 +32,12 @@ import org.springframework.util.StringUtils; @SuppressWarnings("serial") public class SimpleKey implements Serializable { - /** - * An empty key. - */ + /** An empty key. */ public static final SimpleKey EMPTY = new SimpleKey(); + private final Object[] params; + private final int hashCode; @@ -52,10 +52,11 @@ public class SimpleKey implements Serializable { this.hashCode = Arrays.deepHashCode(this.params); } + @Override - public boolean equals(Object obj) { - return (this == obj || (obj instanceof SimpleKey - && Arrays.deepEquals(this.params, ((SimpleKey) obj).params))); + public boolean equals(Object other) { + return (this == other || + (other instanceof SimpleKey && Arrays.deepEquals(this.params, ((SimpleKey) other).params))); } @Override diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index f095ae4c17b..0b19463d399 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -553,7 +553,7 @@ class ConfigurationClassParser { for (DeferredImportSelectorHolder deferredImport : deferredImports) { Class group = deferredImport.getImportSelector().getImportGroup(); DeferredImportSelectorGrouping grouping = groupings.computeIfAbsent( - (group == null ? deferredImport : group), + (group != null ? group : deferredImport), key -> new DeferredImportSelectorGrouping(createGroup(group))); grouping.add(deferredImport); configurationClasses.put(deferredImport.getConfigurationClass().getMetadata(), @@ -561,8 +561,7 @@ class ConfigurationClassParser { } for (DeferredImportSelectorGrouping grouping : groupings.values()) { grouping.getImports().forEach(entry -> { - ConfigurationClass configurationClass = configurationClasses.get( - entry.getMetadata()); + ConfigurationClass configurationClass = configurationClasses.get(entry.getMetadata()); try { processImports(configurationClass, asSourceClass(configurationClass), asSourceClasses(entry.getImportClassName()), false); @@ -573,15 +572,14 @@ class ConfigurationClassParser { catch (Throwable ex) { throw new BeanDefinitionStoreException( "Failed to process import candidates for configuration class [" + - configurationClass.getMetadata().getClassName() + "]", ex); + configurationClass.getMetadata().getClassName() + "]", ex); } }); } } private Group createGroup(@Nullable Class type) { - Class effectiveType = (type != null ? type - : DefaultDeferredImportSelectorGroup.class); + Class effectiveType = (type != null ? type : DefaultDeferredImportSelectorGroup.class); Group group = BeanUtils.instantiateClass(effectiveType); ParserStrategyUtils.invokeAwareMethods(group, ConfigurationClassParser.this.environment, diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index e12ca02a89f..14fc3c20e77 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java @@ -1252,8 +1252,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader */ @Nullable protected BeanFactory getInternalParentBeanFactory() { - return (getParent() instanceof ConfigurableApplicationContext) ? - ((ConfigurableApplicationContext) getParent()).getBeanFactory() : getParent(); + return (getParent() instanceof ConfigurableApplicationContext ? + ((ConfigurableApplicationContext) getParent()).getBeanFactory() : getParent()); } @@ -1295,8 +1295,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader */ @Nullable protected MessageSource getInternalParentMessageSource() { - return (getParent() instanceof AbstractApplicationContext) ? - ((AbstractApplicationContext) getParent()).messageSource : getParent(); + return (getParent() instanceof AbstractApplicationContext ? + ((AbstractApplicationContext) getParent()).messageSource : getParent()); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java b/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java index d270473d903..3bdd429d8b1 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java @@ -144,16 +144,16 @@ public class PeriodicTrigger implements Trigger { @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (!(obj instanceof PeriodicTrigger)) { + if (!(other instanceof PeriodicTrigger)) { return false; } - PeriodicTrigger other = (PeriodicTrigger) obj; - return (this.fixedRate == other.fixedRate && this.initialDelay == other.initialDelay && - this.period == other.period); + PeriodicTrigger otherTrigger = (PeriodicTrigger) other; + return (this.fixedRate == otherTrigger.fixedRate && this.initialDelay == otherTrigger.initialDelay && + this.period == otherTrigger.period); } @Override diff --git a/spring-context/src/main/java/org/springframework/validation/DataBinder.java b/spring-context/src/main/java/org/springframework/validation/DataBinder.java index 32633c0ef69..4f01b64d7de 100644 --- a/spring-context/src/main/java/org/springframework/validation/DataBinder.java +++ b/spring-context/src/main/java/org/springframework/validation/DataBinder.java @@ -715,8 +715,8 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * @see #doBind(org.springframework.beans.MutablePropertyValues) */ public void bind(PropertyValues pvs) { - MutablePropertyValues mpvs = (pvs instanceof MutablePropertyValues) ? - (MutablePropertyValues) pvs : new MutablePropertyValues(pvs); + MutablePropertyValues mpvs = (pvs instanceof MutablePropertyValues ? + (MutablePropertyValues) pvs : new MutablePropertyValues(pvs)); doBind(mpvs); } diff --git a/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java b/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java index 8b35b0b4aa2..5f4f515e23f 100644 --- a/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java +++ b/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java @@ -93,14 +93,8 @@ public abstract class AttributeAccessorSupport implements AttributeAccessor, Ser @Override public boolean equals(Object other) { - if (this == other) { - return true; - } - if (!(other instanceof AttributeAccessorSupport)) { - return false; - } - AttributeAccessorSupport that = (AttributeAccessorSupport) other; - return this.attributes.equals(that.attributes); + return (this == other || (other instanceof AttributeAccessorSupport && + this.attributes.equals(((AttributeAccessorSupport) other).attributes))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java b/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java index 3f1e9d658eb..c4eef21facd 100644 --- a/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java +++ b/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java @@ -66,9 +66,9 @@ public abstract class ParameterizedTypeReference { } @Override - public boolean equals(Object obj) { - return (this == obj || (obj instanceof ParameterizedTypeReference && - this.type.equals(((ParameterizedTypeReference) obj).type))); + public boolean equals(Object other) { + return (this == other || (other instanceof ParameterizedTypeReference && + this.type.equals(((ParameterizedTypeReference) other).type))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java index f268fe9a3c5..bdb0d4b5c22 100644 --- a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java +++ b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java @@ -164,12 +164,10 @@ public class ReactiveAdapterRegistry { /** * Return a shared default {@code ReactiveAdapterRegistry} instance, lazily * building it once needed. - * *

NOTE: We highly recommend passing a long-lived, pre-configured * {@code ReactiveAdapterRegistry} instance for customization purposes. * This accessor is only meant as a fallback for code paths that want to * fall back on a default instance if one isn't provided. - * * @return the shared {@code ReactiveAdapterRegistry} instance (never {@code null}) * @since 5.0.2 */ @@ -191,7 +189,6 @@ public class ReactiveAdapterRegistry { private static class ReactorRegistrar { void registerAdapters(ReactiveAdapterRegistry registry) { - // Register Flux and Mono before Publisher... registry.registerReactiveType( @@ -280,7 +277,6 @@ public class ReactiveAdapterRegistry { private static class ReactorJdkFlowAdapterRegistrar { void registerAdapter(ReactiveAdapterRegistry registry) throws Exception { - // TODO: remove reflection when build requires JDK 9+ String publisherName = "java.util.concurrent.Flow.Publisher"; diff --git a/spring-core/src/main/java/org/springframework/core/env/ProfilesParser.java b/spring-core/src/main/java/org/springframework/core/env/ProfilesParser.java index 7a751885cc1..3b06a942281 100644 --- a/spring-core/src/main/java/org/springframework/core/env/ProfilesParser.java +++ b/spring-core/src/main/java/org/springframework/core/env/ProfilesParser.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.StringTokenizer; import java.util.function.Predicate; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -31,10 +32,7 @@ import org.springframework.util.StringUtils; * @author Phillip Webb * @since 5.1 */ -final class ProfilesParser { - - private ProfilesParser() { - } +abstract class ProfilesParser { static Profiles parse(String... expressions) { Assert.notEmpty(expressions, "Must specify at least one profile"); @@ -46,8 +44,7 @@ final class ProfilesParser { } private static Profiles parseExpression(String expression) { - Assert.hasText(expression, () -> - "Invalid profile expression [" + expression + "]: must contain text"); + Assert.hasText(expression, () -> "Invalid profile expression [" + expression + "]: must contain text"); StringTokenizer tokens = new StringTokenizer(expression, "()&|!", true); return parseTokens(expression, tokens); } @@ -88,8 +85,7 @@ final class ProfilesParser { return merge(expression, elements, operator); } - private static Profiles merge(String expression, List elements, - Operator operator) { + private static Profiles merge(String expression, List elements, @Nullable Operator operator) { assertWellFormed(expression, !elements.isEmpty()); if (elements.size() == 1) { return elements.get(0); @@ -99,18 +95,15 @@ final class ProfilesParser { } private static void assertWellFormed(String expression, boolean wellFormed) { - Assert.isTrue(wellFormed, - () -> "Malformed profile expression [" + expression + "]"); + Assert.isTrue(wellFormed, () -> "Malformed profile expression [" + expression + "]"); } private static Profiles or(Profiles... profiles) { - return activeProfile -> Arrays.stream(profiles).anyMatch( - isMatch(activeProfile)); + return activeProfile -> Arrays.stream(profiles).anyMatch(isMatch(activeProfile)); } private static Profiles and(Profiles... profiles) { - return activeProfile -> Arrays.stream(profiles).allMatch( - isMatch(activeProfile)); + return activeProfile -> Arrays.stream(profiles).allMatch(isMatch(activeProfile)); } private static Profiles not(Profiles profiles) { @@ -125,10 +118,9 @@ final class ProfilesParser { return profiles -> profiles.matches(activeProfile); } - private enum Operator { - AND, - OR - } + + private enum Operator {AND, OR} + private static class ParsedProfiles implements Profiles { @@ -155,7 +147,6 @@ final class ProfilesParser { public String toString() { return StringUtils.arrayToDelimitedString(this.expressions, " or "); } - } } diff --git a/spring-core/src/main/java/org/springframework/core/env/PropertySource.java b/spring-core/src/main/java/org/springframework/core/env/PropertySource.java index d485a70de5e..6d2bc292faa 100644 --- a/spring-core/src/main/java/org/springframework/core/env/PropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/PropertySource.java @@ -132,9 +132,9 @@ public abstract class PropertySource { *

No properties other than {@code name} are evaluated. */ @Override - public boolean equals(Object obj) { - return (this == obj || (obj instanceof PropertySource && - ObjectUtils.nullSafeEquals(this.name, ((PropertySource) obj).name))); + public boolean equals(Object other) { + return (this == other || (other instanceof PropertySource && + ObjectUtils.nullSafeEquals(this.name, ((PropertySource) other).name))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java index 8bc3a05bbfc..2bb8175cce2 100644 --- a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java @@ -210,31 +210,31 @@ public abstract class AbstractResource implements Resource { /** - * This implementation returns the description of this resource. + * This implementation compares description strings. * @see #getDescription() */ @Override - public String toString() { - return getDescription(); + public boolean equals(Object other) { + return (this == other || (other instanceof Resource && + ((Resource) other).getDescription().equals(getDescription()))); } /** - * This implementation compares description strings. + * This implementation returns the description's hash code. * @see #getDescription() */ @Override - public boolean equals(Object obj) { - return (obj == this || - (obj instanceof Resource && ((Resource) obj).getDescription().equals(getDescription()))); + public int hashCode() { + return getDescription().hashCode(); } /** - * This implementation returns the description's hash code. + * This implementation returns the description of this resource. * @see #getDescription() */ @Override - public int hashCode() { - return getDescription().hashCode(); + public String toString() { + return getDescription(); } } diff --git a/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java b/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java index 79415fa42c0..034c9e4b5df 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -115,9 +115,9 @@ public class ByteArrayResource extends AbstractResource { * @see java.util.Arrays#equals(byte[], byte[]) */ @Override - public boolean equals(Object obj) { - return (obj == this || - (obj instanceof ByteArrayResource && Arrays.equals(((ByteArrayResource) obj).byteArray, this.byteArray))); + public boolean equals(Object other) { + return (this == other || (other instanceof ByteArrayResource && + Arrays.equals(((ByteArrayResource) other).byteArray, this.byteArray))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java index bb9ac53a10f..1ebbd4f6312 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java @@ -244,17 +244,17 @@ public class ClassPathResource extends AbstractFileResolvingResource { * This implementation compares the underlying class path locations. */ @Override - public boolean equals(Object obj) { - if (obj == this) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (obj instanceof ClassPathResource) { - ClassPathResource otherRes = (ClassPathResource) obj; - return (this.path.equals(otherRes.path) && - ObjectUtils.nullSafeEquals(this.classLoader, otherRes.classLoader) && - ObjectUtils.nullSafeEquals(this.clazz, otherRes.clazz)); + if (!(other instanceof ClassPathResource)) { + return false; } - return false; + ClassPathResource otherRes = (ClassPathResource) other; + return (this.path.equals(otherRes.path) && + ObjectUtils.nullSafeEquals(this.classLoader, otherRes.classLoader) && + ObjectUtils.nullSafeEquals(this.clazz, otherRes.clazz)); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java b/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java index 127db9f767a..e42457365f2 100644 --- a/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -72,9 +72,9 @@ public class DescriptiveResource extends AbstractResource { * This implementation compares the underlying description String. */ @Override - public boolean equals(Object obj) { - return (obj == this || - (obj instanceof DescriptiveResource && ((DescriptiveResource) obj).description.equals(this.description))); + public boolean equals(Object other) { + return (this == other || (other instanceof DescriptiveResource && + ((DescriptiveResource) other).description.equals(this.description))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java index 092755aec7d..0a59eaba459 100644 --- a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java @@ -282,9 +282,9 @@ public class FileSystemResource extends AbstractResource implements WritableReso * This implementation compares the underlying File references. */ @Override - public boolean equals(Object obj) { - return (obj == this || - (obj instanceof FileSystemResource && this.path.equals(((FileSystemResource) obj).path))); + public boolean equals(Object other) { + return (this == other || (other instanceof FileSystemResource && + this.path.equals(((FileSystemResource) other).path))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java b/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java index b6470b5a8d2..37ea6b6ee60 100644 --- a/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -115,9 +115,9 @@ public class InputStreamResource extends AbstractResource { * This implementation compares the underlying InputStream. */ @Override - public boolean equals(Object obj) { - return (obj == this || - (obj instanceof InputStreamResource && ((InputStreamResource) obj).inputStream.equals(this.inputStream))); + public boolean equals(Object other) { + return (this == other || (other instanceof InputStreamResource && + ((InputStreamResource) other).inputStream.equals(this.inputStream))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/PathResource.java b/spring-core/src/main/java/org/springframework/core/io/PathResource.java index da9c942c426..2bedadec6b8 100644 --- a/spring-core/src/main/java/org/springframework/core/io/PathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/PathResource.java @@ -274,9 +274,9 @@ public class PathResource extends AbstractResource implements WritableResource { * This implementation compares the underlying Path references. */ @Override - public boolean equals(Object obj) { - return (this == obj || - (obj instanceof PathResource && this.path.equals(((PathResource) obj).path))); + public boolean equals(Object other) { + return (this == other || (other instanceof PathResource && + this.path.equals(((PathResource) other).path))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java index 37373a22d71..72945507b49 100644 --- a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -261,9 +261,9 @@ public class UrlResource extends AbstractFileResolvingResource { * This implementation compares the underlying URL references. */ @Override - public boolean equals(Object obj) { - return (obj == this || - (obj instanceof UrlResource && this.cleanedUrl.equals(((UrlResource) obj).cleanedUrl))); + public boolean equals(Object other) { + return (this == other || (other instanceof UrlResource && + this.cleanedUrl.equals(((UrlResource) other).cleanedUrl))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/VfsResource.java b/spring-core/src/main/java/org/springframework/core/io/VfsResource.java index 296e8423655..267a906db9f 100644 --- a/spring-core/src/main/java/org/springframework/core/io/VfsResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/VfsResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -125,8 +125,9 @@ public class VfsResource extends AbstractResource { } @Override - public boolean equals(Object obj) { - return (obj == this || (obj instanceof VfsResource && this.resource.equals(((VfsResource) obj).resource))); + public boolean equals(Object other) { + return (this == other || (other instanceof VfsResource && + this.resource.equals(((VfsResource) other).resource))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBuffer.java index 072e24a7337..c78102e108c 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBuffer.java @@ -57,22 +57,22 @@ public interface DataBuffer { DataBufferFactory factory(); /** - * Return the index of the first byte in this buffer that matches the given - * predicate. + * Return the index of the first byte in this buffer that matches + * the given predicate. * @param predicate the predicate to match * @param fromIndex the index to start the search from - * @return the index of the first byte that matches {@code predicate}; or {@code -1} - * if none match + * @return the index of the first byte that matches {@code predicate}; + * or {@code -1} if none match */ int indexOf(IntPredicate predicate, int fromIndex); /** - * Return the index of the last byte in this buffer that matches the given - * predicate. + * Return the index of the last byte in this buffer that matches + * the given predicate. * @param predicate the predicate to match * @param fromIndex the index to start the search from - * @return the index of the last byte that matches {@code predicate}; or {@code -1} - * if none match + * @return the index of the last byte that matches {@code predicate}; + * or {@code -1} if none match */ int lastIndexOf(IntPredicate predicate, int fromIndex); @@ -97,9 +97,10 @@ public interface DataBuffer { int capacity(); /** - * Sets the number of bytes that this buffer can contain. If the new capacity is lower than - * the current capacity, the contents of this buffer will be truncated. If the new capacity - * is higher than the current capacity, it will be expanded. + * Set the number of bytes that this buffer can contain. + *

If the new capacity is lower than the current capacity, the contents + * of this buffer will be truncated. If the new capacity is higher than + * the current capacity, it will be expanded. * @param capacity the new capacity * @return this buffer */ @@ -116,8 +117,8 @@ public interface DataBuffer { * Set the position from which this buffer will read. * @param readPosition the new read position * @return this buffer - * @throws IndexOutOfBoundsException if {@code readPosition} is smaller than 0 or greater than - * {@link #writePosition()} + * @throws IndexOutOfBoundsException if {@code readPosition} is smaller than 0 + * or greater than {@link #writePosition()} * @since 5.0.1 */ DataBuffer readPosition(int readPosition); diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java index c2a4afaf179..ba4bc447246 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java @@ -27,14 +27,13 @@ import java.util.function.IntPredicate; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; - /** * Default implementation of the {@link DataBuffer} interface that uses a * {@link ByteBuffer} internally. with separate read and write positions. * Constructed using the {@link DefaultDataBufferFactory}. * - *

Inspired by Netty's {@code ByteBuf}. Introduced so that non-Netty runtimes (i.e. Servlet) - * do not require Netty on the classpath. + *

Inspired by Netty's {@code ByteBuf}. Introduced so that non-Netty runtimes + * (i.e. Servlet) do not require Netty on the classpath. * * @author Arjen Poutsma * @author Juergen Hoeller @@ -52,32 +51,29 @@ public class DefaultDataBuffer implements DataBuffer { private ByteBuffer byteBuffer; + private int capacity; + private int readPosition; private int writePosition; - private int capacity; private DefaultDataBuffer(DefaultDataBufferFactory dataBufferFactory, ByteBuffer byteBuffer) { - Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); - Assert.notNull(byteBuffer, "'byteBuffer' must not be null"); - + Assert.notNull(dataBufferFactory, "DefaultDataBufferFactory must not be null"); + Assert.notNull(byteBuffer, "ByteBuffer must not be null"); this.dataBufferFactory = dataBufferFactory; ByteBuffer slice = byteBuffer.slice(); this.byteBuffer = slice; this.capacity = slice.remaining(); } - static DefaultDataBuffer fromFilledByteBuffer(DefaultDataBufferFactory dataBufferFactory, - ByteBuffer byteBuffer) { - + static DefaultDataBuffer fromFilledByteBuffer(DefaultDataBufferFactory dataBufferFactory, ByteBuffer byteBuffer) { DefaultDataBuffer dataBuffer = new DefaultDataBuffer(dataBufferFactory, byteBuffer); dataBuffer.writePosition(byteBuffer.remaining()); return dataBuffer; } - static DefaultDataBuffer fromEmptyByteBuffer(DefaultDataBufferFactory dataBufferFactory, - ByteBuffer byteBuffer) { + static DefaultDataBuffer fromEmptyByteBuffer(DefaultDataBufferFactory dataBufferFactory, ByteBuffer byteBuffer) { return new DefaultDataBuffer(dataBufferFactory, byteBuffer); } @@ -95,6 +91,7 @@ public class DefaultDataBuffer implements DataBuffer { this.capacity = byteBuffer.remaining(); } + @Override public DefaultDataBufferFactory factory() { return this.dataBufferFactory; @@ -414,17 +411,17 @@ public class DefaultDataBuffer implements DataBuffer { @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (!(obj instanceof DefaultDataBuffer)) { + if (!(other instanceof DefaultDataBuffer)) { return false; } - DefaultDataBuffer other = (DefaultDataBuffer) obj; - return (this.readPosition == other.readPosition && - this.writePosition == other.writePosition && - this.byteBuffer.equals(other.byteBuffer)); + DefaultDataBuffer otherBuffer = (DefaultDataBuffer) other; + return (this.readPosition == otherBuffer.readPosition && + this.writePosition == otherBuffer.writePosition && + this.byteBuffer.equals(otherBuffer.byteBuffer)); } @Override @@ -434,10 +431,11 @@ public class DefaultDataBuffer implements DataBuffer { @Override public String toString() { - return String.format("DefaultDataBuffer (r: %d, w %d, c %d)", this.readPosition, - this.writePosition, this.capacity); + return String.format("DefaultDataBuffer (r: %d, w %d, c %d)", + this.readPosition, this.writePosition, this.capacity); } + private void checkIndex(int index, int length) { assertIndex(index >= 0, "index %d must be >= 0", index); assertIndex(length >= 0, "length %d must be >= 0", index); @@ -452,6 +450,7 @@ public class DefaultDataBuffer implements DataBuffer { } } + private class DefaultDataBufferInputStream extends InputStream { @Override @@ -479,7 +478,6 @@ public class DefaultDataBuffer implements DataBuffer { } - private class DefaultDataBufferOutputStream extends OutputStream { @Override @@ -496,16 +494,14 @@ public class DefaultDataBuffer implements DataBuffer { private static class SlicedDefaultDataBuffer extends DefaultDataBuffer { - SlicedDefaultDataBuffer(ByteBuffer byteBuffer, DefaultDataBufferFactory dataBufferFactory, - int length) { + SlicedDefaultDataBuffer(ByteBuffer byteBuffer, DefaultDataBufferFactory dataBufferFactory, int length) { super(dataBufferFactory, byteBuffer); writePosition(length); } @Override public DefaultDataBuffer capacity(int newCapacity) { - throw new UnsupportedOperationException( - "Changing the capacity of a sliced buffer is not supported"); + throw new UnsupportedOperationException("Changing the capacity of a sliced buffer is not supported"); } } diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java index cd8b90ad55f..9cbe8c78263 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java @@ -37,19 +37,18 @@ import org.springframework.util.Assert; */ public class NettyDataBuffer implements PooledDataBuffer { - private final NettyDataBufferFactory dataBufferFactory; - private final ByteBuf byteBuf; + private final NettyDataBufferFactory dataBufferFactory; + /** * Creates a new {@code NettyDataBuffer} based on the given {@code ByteBuff}. * @param byteBuf the buffer to base this buffer on */ NettyDataBuffer(ByteBuf byteBuf, NettyDataBufferFactory dataBufferFactory) { - Assert.notNull(byteBuf, "'byteBuf' must not be null"); - Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); - + Assert.notNull(byteBuf, "ByteBuf must not be null"); + Assert.notNull(dataBufferFactory, "NettyDataBufferFactory must not be null"); this.byteBuf = byteBuf; this.dataBufferFactory = dataBufferFactory; } @@ -272,15 +271,9 @@ public class NettyDataBuffer implements PooledDataBuffer { @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof NettyDataBuffer)) { - return false; - } - NettyDataBuffer other = (NettyDataBuffer) obj; - return this.byteBuf.equals(other.byteBuf); + public boolean equals(Object other) { + return (this == other || (other instanceof NettyDataBuffer && + this.byteBuf.equals(((NettyDataBuffer) other).byteBuf))); } @Override diff --git a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java index 7b908ffdcfb..5ca0be0fc27 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java @@ -839,12 +839,12 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen @Override public boolean contains(@Nullable Object o) { - if (o != null && o instanceof Map.Entry) { + if (o instanceof Map.Entry) { Map.Entry entry = (java.util.Map.Entry) o; Reference reference = ConcurrentReferenceHashMap.this.getReference(entry.getKey(), Restructure.NEVER); - Entry other = (reference != null ? reference.get() : null); - if (other != null) { - return ObjectUtils.nullSafeEquals(entry.getValue(), other.getValue()); + Entry otherEntry = (reference != null ? reference.get() : null); + if (otherEntry != null) { + return ObjectUtils.nullSafeEquals(otherEntry.getValue(), otherEntry.getValue()); } } return false; diff --git a/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java b/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java index b54297b4bd0..4ae9c970fee 100644 --- a/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java +++ b/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -67,9 +67,9 @@ public class BooleanComparator implements Comparator, Serializable { @Override - public boolean equals(Object obj) { - return (this == obj || - (obj instanceof BooleanComparator && (this.trueLow == ((BooleanComparator) obj).trueLow))); + public boolean equals(Object other) { + return (this == other || (other instanceof BooleanComparator && + this.trueLow == ((BooleanComparator) other).trueLow)); } @Override diff --git a/spring-core/src/main/java/org/springframework/util/comparator/CompoundComparator.java b/spring-core/src/main/java/org/springframework/util/comparator/CompoundComparator.java index f205d97db39..f242e6ba55e 100644 --- a/spring-core/src/main/java/org/springframework/util/comparator/CompoundComparator.java +++ b/spring-core/src/main/java/org/springframework/util/comparator/CompoundComparator.java @@ -187,15 +187,9 @@ public class CompoundComparator implements Comparator, Serializable { @Override @SuppressWarnings("unchecked") - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof CompoundComparator)) { - return false; - } - CompoundComparator other = (CompoundComparator) obj; - return this.comparators.equals(other.comparators); + public boolean equals(Object other) { + return (this == other || (other instanceof CompoundComparator && + this.comparators.equals(((CompoundComparator) other).comparators))); } @Override diff --git a/spring-core/src/main/java/org/springframework/util/comparator/InvertibleComparator.java b/spring-core/src/main/java/org/springframework/util/comparator/InvertibleComparator.java index 2dda8c4315c..f0bcce53da3 100644 --- a/spring-core/src/main/java/org/springframework/util/comparator/InvertibleComparator.java +++ b/spring-core/src/main/java/org/springframework/util/comparator/InvertibleComparator.java @@ -108,15 +108,15 @@ public class InvertibleComparator implements Comparator, Serializable { @Override @SuppressWarnings("unchecked") - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (!(obj instanceof InvertibleComparator)) { + if (!(other instanceof InvertibleComparator)) { return false; } - InvertibleComparator other = (InvertibleComparator) obj; - return (this.comparator.equals(other.comparator) && this.ascending == other.ascending); + InvertibleComparator otherComp = (InvertibleComparator) other; + return (this.comparator.equals(otherComp.comparator) && this.ascending == otherComp.ascending); } @Override diff --git a/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java b/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java index bdf90fdc360..b88ecade7c8 100644 --- a/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java +++ b/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java @@ -108,15 +108,15 @@ public class NullSafeComparator implements Comparator { @Override @SuppressWarnings("unchecked") - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (!(obj instanceof NullSafeComparator)) { + if (!(other instanceof NullSafeComparator)) { return false; } - NullSafeComparator other = (NullSafeComparator) obj; - return (this.nonNullComparator.equals(other.nonNullComparator) && this.nullsLow == other.nullsLow); + NullSafeComparator otherComp = (NullSafeComparator) other; + return (this.nonNullComparator.equals(otherComp.nonNullComparator) && this.nullsLow == otherComp.nullsLow); } @Override diff --git a/spring-core/src/test/java/org/springframework/core/env/DummyEnvironment.java b/spring-core/src/test/java/org/springframework/core/env/DummyEnvironment.java index e37212f88f8..ca9e8fad07e 100644 --- a/spring-core/src/test/java/org/springframework/core/env/DummyEnvironment.java +++ b/spring-core/src/test/java/org/springframework/core/env/DummyEnvironment.java @@ -73,6 +73,7 @@ public class DummyEnvironment implements Environment { return null; } + @Deprecated @Override public boolean acceptsProfiles(String... profiles) { return false; diff --git a/spring-jms/src/main/java/org/springframework/jms/support/converter/MessagingMessageConverter.java b/spring-jms/src/main/java/org/springframework/jms/support/converter/MessagingMessageConverter.java index bc8e09841d5..9f537995cb5 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/converter/MessagingMessageConverter.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/converter/MessagingMessageConverter.java @@ -117,9 +117,9 @@ public class MessagingMessageConverter implements MessageConverter, Initializing public Object fromMessage(javax.jms.Message message) throws JMSException, MessageConversionException { Map mappedHeaders = extractHeaders(message); Object convertedObject = extractPayload(message); - MessageBuilder builder = (convertedObject instanceof org.springframework.messaging.Message) ? + MessageBuilder builder = (convertedObject instanceof org.springframework.messaging.Message ? MessageBuilder.fromMessage((org.springframework.messaging.Message) convertedObject) : - MessageBuilder.withPayload(convertedObject); + MessageBuilder.withPayload(convertedObject)); return builder.copyHeadersIfAbsent(mappedHeaders).build(); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/AbstractMessageCondition.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/AbstractMessageCondition.java index c55ead414af..f6eb49d9fec 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/AbstractMessageCondition.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/AbstractMessageCondition.java @@ -31,33 +31,17 @@ import org.springframework.lang.Nullable; * @since 4.0 * @param the kind of condition that this condition can be combined with or compared to */ -public abstract class AbstractMessageCondition> - implements MessageCondition { - - - /** - * Return the collection of objects the message condition is composed of - * (e.g. destination patterns), never {@code null}. - */ - protected abstract Collection getContent(); - - /** - * The notation to use when printing discrete items of content. - * For example " || " for URL patterns or " && " for param expressions. - */ - protected abstract String getToStringInfix(); - +public abstract class AbstractMessageCondition> implements MessageCondition { @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { + public boolean equals(@Nullable Object other) { + if (this == other) { return true; } - if (obj != null && getClass() == obj.getClass()) { - AbstractMessageCondition other = (AbstractMessageCondition) obj; - return getContent().equals(other.getContent()); + if (other == null || getClass() != other.getClass()) { + return false; } - return false; + return getContent().equals(((AbstractMessageCondition) other).getContent()); } @Override @@ -79,4 +63,17 @@ public abstract class AbstractMessageCondition getContent(); + + /** + * The notation to use when printing discrete items of content. + * For example " || " for URL patterns or " && " for param expressions. + */ + protected abstract String getToStringInfix(); + } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageMappingInfo.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageMappingInfo.java index c28c4dcb182..317c24919b3 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageMappingInfo.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageMappingInfo.java @@ -94,16 +94,16 @@ public class SimpMessageMappingInfo implements MessageCondition other = (HttpEntity) part; - partBody = other.getBody(); - partHeaders.addAll(other.getHeaders()); + HttpEntity httpEntity = (HttpEntity) part; + partBody = httpEntity.getBody(); + partHeaders.addAll(httpEntity.getHeaders()); } else { partBody = part; diff --git a/spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java index 1953cb0fe77..908cf4f4eb4 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java @@ -18,6 +18,7 @@ package org.springframework.http.codec; import java.io.File; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -50,8 +51,6 @@ import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.lang.Nullable; import org.springframework.util.MimeTypeUtils; -import static java.util.Collections.emptyMap; - /** * {@code HttpMessageWriter} that can write a {@link Resource}. * @@ -244,7 +243,7 @@ public class ResourceHttpMessageWriter implements HttpMessageWriter { .orElseGet(() -> { Publisher input = Mono.just(region); MediaType mediaType = message.getHeaders().getContentType(); - return encodeAndWriteRegions(input, mediaType, message, emptyMap()); + return encodeAndWriteRegions(input, mediaType, message, Collections.emptyMap()); }); } diff --git a/spring-web/src/main/java/org/springframework/http/server/DefaultRequestPath.java b/spring-web/src/main/java/org/springframework/http/server/DefaultRequestPath.java index a8bd993e6b5..ff09f3e41fb 100644 --- a/spring-web/src/main/java/org/springframework/http/server/DefaultRequestPath.java +++ b/spring-web/src/main/java/org/springframework/http/server/DefaultRequestPath.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -132,10 +132,10 @@ class DefaultRequestPath implements RequestPath { if (other == null || getClass() != other.getClass()) { return false; } - DefaultRequestPath that = (DefaultRequestPath) other; - return (this.fullPath.equals(that.fullPath) && - this.contextPath.equals(that.contextPath) && - this.pathWithinApplication.equals(that.pathWithinApplication)); + DefaultRequestPath otherPath= (DefaultRequestPath) other; + return (this.fullPath.equals(otherPath.fullPath) && + this.contextPath.equals(otherPath.contextPath) && + this.pathWithinApplication.equals(otherPath.pathWithinApplication)); } @Override diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java index 086feac466d..fddfac9d023 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java @@ -236,15 +236,15 @@ public class ServletContextResource extends AbstractFileResolvingResource implem * This implementation compares the underlying ServletContext resource locations. */ @Override - public boolean equals(Object obj) { - if (obj == this) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (obj instanceof ServletContextResource) { - ServletContextResource otherRes = (ServletContextResource) obj; - return (this.servletContext.equals(otherRes.servletContext) && this.path.equals(otherRes.path)); + if (!(other instanceof ServletContextResource)) { + return false; } - return false; + ServletContextResource otherRes = (ServletContextResource) other; + return (this.servletContext.equals(otherRes.servletContext) && this.path.equals(otherRes.path)); } /** diff --git a/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java b/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java index 73e0e021a44..54fff9f5bab 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java @@ -86,9 +86,9 @@ class MultipartFileResource extends AbstractResource { @Override - public boolean equals(Object obj) { - return (obj == this || (obj instanceof MultipartFileResource && - ((MultipartFileResource) obj).multipartFile.equals(this.multipartFile))); + public boolean equals(Object other) { + return (this == other || (other instanceof MultipartFileResource && + ((MultipartFileResource) other).multipartFile.equals(this.multipartFile))); } @Override diff --git a/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java b/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java index 49322aac801..da945bacb1a 100644 --- a/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java +++ b/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java @@ -53,6 +53,7 @@ final class HierarchicalUriComponents extends UriComponents { private static final String PATH_DELIMITER_STRING = "/"; + /** * Represents an empty path. */ @@ -87,8 +88,8 @@ final class HierarchicalUriComponents extends UriComponents { } @Override - public boolean equals(Object obj) { - return (this == obj); + public boolean equals(Object other) { + return (this == other); } @Override @@ -506,21 +507,21 @@ final class HierarchicalUriComponents extends UriComponents { @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (!(obj instanceof HierarchicalUriComponents)) { + if (!(other instanceof HierarchicalUriComponents)) { return false; } - HierarchicalUriComponents other = (HierarchicalUriComponents) obj; - return ObjectUtils.nullSafeEquals(getScheme(), other.getScheme()) && - ObjectUtils.nullSafeEquals(getUserInfo(), other.getUserInfo()) && - ObjectUtils.nullSafeEquals(getHost(), other.getHost()) && - getPort() == other.getPort() && - this.path.equals(other.path) && - this.queryParams.equals(other.queryParams) && - ObjectUtils.nullSafeEquals(getFragment(), other.getFragment()); + HierarchicalUriComponents otherComp = (HierarchicalUriComponents) other; + return (ObjectUtils.nullSafeEquals(getScheme(), otherComp.getScheme()) && + ObjectUtils.nullSafeEquals(getUserInfo(), otherComp.getUserInfo()) && + ObjectUtils.nullSafeEquals(getHost(), otherComp.getHost()) && + getPort() == otherComp.getPort() && + this.path.equals(otherComp.path) && + this.queryParams.equals(otherComp.queryParams) && + ObjectUtils.nullSafeEquals(getFragment(), otherComp.getFragment())); } @Override @@ -752,9 +753,9 @@ final class HierarchicalUriComponents extends UriComponents { } @Override - public boolean equals(Object obj) { - return (this == obj || (obj instanceof FullPathComponent && - getPath().equals(((FullPathComponent) obj).getPath()))); + public boolean equals(Object other) { + return (this == other || (other instanceof FullPathComponent && + getPath().equals(((FullPathComponent) other).getPath()))); } @Override @@ -830,9 +831,9 @@ final class HierarchicalUriComponents extends UriComponents { } @Override - public boolean equals(Object obj) { - return (this == obj || (obj instanceof PathSegmentComponent && - getPathSegments().equals(((PathSegmentComponent) obj).getPathSegments()))); + public boolean equals(Object other) { + return (this == other || (other instanceof PathSegmentComponent && + getPathSegments().equals(((PathSegmentComponent) other).getPathSegments()))); } @Override diff --git a/spring-web/src/main/java/org/springframework/web/util/OpaqueUriComponents.java b/spring-web/src/main/java/org/springframework/web/util/OpaqueUriComponents.java index ed7cd128592..22f4e1e8e16 100644 --- a/spring-web/src/main/java/org/springframework/web/util/OpaqueUriComponents.java +++ b/spring-web/src/main/java/org/springframework/web/util/OpaqueUriComponents.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -157,19 +157,17 @@ final class OpaqueUriComponents extends UriComponents { @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (!(obj instanceof OpaqueUriComponents)) { + if (!(other instanceof OpaqueUriComponents)) { return false; } - - OpaqueUriComponents other = (OpaqueUriComponents) obj; - return ObjectUtils.nullSafeEquals(getScheme(), other.getScheme()) && - ObjectUtils.nullSafeEquals(this.ssp, other.ssp) && - ObjectUtils.nullSafeEquals(getFragment(), other.getFragment()); - + OpaqueUriComponents otherComp = (OpaqueUriComponents) other; + return (ObjectUtils.nullSafeEquals(getScheme(), otherComp.getScheme()) && + ObjectUtils.nullSafeEquals(this.ssp, otherComp.ssp) && + ObjectUtils.nullSafeEquals(getFragment(), otherComp.getFragment())); } @Override diff --git a/spring-web/src/test/java/org/springframework/web/method/ResolvableMethod.java b/spring-web/src/test/java/org/springframework/web/method/ResolvableMethod.java index 31f28eb15db..c0daebb69c2 100644 --- a/spring-web/src/test/java/org/springframework/web/method/ResolvableMethod.java +++ b/spring-web/src/test/java/org/springframework/web/method/ResolvableMethod.java @@ -209,17 +209,17 @@ public class ResolvableMethod { } private String formatMethod() { - return this.method().getName() + + return (this.method().getName() + Arrays.stream(this.method.getParameters()) .map(this::formatParameter) - .collect(joining(",\n\t", "(\n\t", "\n)")); + .collect(joining(",\n\t", "(\n\t", "\n)"))); } private String formatParameter(Parameter param) { - Annotation[] annot = param.getAnnotations(); - return annot.length > 0 ? - Arrays.stream(annot).map(this::formatAnnotation).collect(joining(",", "[", "]")) + " " + param : - param.toString(); + Annotation[] anns = param.getAnnotations(); + return (anns.length > 0 ? + Arrays.stream(anns).map(this::formatAnnotation).collect(joining(",", "[", "]")) + " " + param : + param.toString()); } private String formatAnnotation(Annotation annotation) { @@ -536,9 +536,9 @@ public class ResolvableMethod { @SafeVarargs public final ArgResolver annotNotPresent(Class... annotationTypes) { this.filters.add(param -> - (annotationTypes.length != 0) ? + (annotationTypes.length > 0 ? Arrays.stream(annotationTypes).noneMatch(param::hasParameterAnnotation) : - param.getParameterAnnotations().length == 0); + param.getParameterAnnotations().length == 0)); return this; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/HeaderContentTypeResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/HeaderContentTypeResolver.java index 25ea29048af..46dec583b3d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/HeaderContentTypeResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/HeaderContentTypeResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.accept; import java.util.List; @@ -36,7 +37,7 @@ public class HeaderContentTypeResolver implements RequestedContentTypeResolver { try { List mediaTypes = exchange.getRequest().getHeaders().getAccept(); MediaType.sortBySpecificityAndQuality(mediaTypes); - return !CollectionUtils.isEmpty(mediaTypes) ? mediaTypes : MEDIA_TYPE_ALL_LIST; + return (!CollectionUtils.isEmpty(mediaTypes) ? mediaTypes : MEDIA_TYPE_ALL_LIST); } catch (InvalidMediaTypeException ex) { String value = exchange.getRequest().getHeaders().getFirst("Accept"); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolverBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolverBuilder.java index aa27e928a44..643da0e9182 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolverBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolverBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -87,11 +87,9 @@ public class RequestedContentTypeResolverBuilder { * of resolvers configured through this builder. */ public RequestedContentTypeResolver build() { - - List resolvers = - this.candidates.isEmpty() ? - Collections.singletonList(new HeaderContentTypeResolver()) : - this.candidates.stream().map(Supplier::get).collect(Collectors.toList()); + List resolvers = (!this.candidates.isEmpty() ? + this.candidates.stream().map(Supplier::get).collect(Collectors.toList()) : + Collections.singletonList(new HeaderContentTypeResolver())); return exchange -> { for (RequestedContentTypeResolver resolver : resolvers) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java index bec706d1c6d..309db46628b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java @@ -74,7 +74,9 @@ public class PathMatchConfigurer { * @since 5.1 */ public PathMatchConfigurer addPathPrefix(String prefix, Predicate> predicate) { - this.pathPrefixes = this.pathPrefixes == null ? new LinkedHashMap<>() : this.pathPrefixes; + if (this.pathPrefixes == null) { + this.pathPrefixes = new LinkedHashMap<>(); + } this.pathPrefixes.put(prefix, predicate); return this; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java index 482f52e2324..213e7e52afc 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java @@ -163,7 +163,6 @@ class DefaultWebClient implements WebClient { private final Map attributes = new LinkedHashMap<>(4); - DefaultRequestBodyUriSpec(HttpMethod httpMethod) { this.httpMethod = httpMethod; } @@ -318,7 +317,7 @@ class DefaultWebClient implements WebClient { } private ClientRequest.Builder initRequestBuilder() { - URI uri = this.uri != null ? this.uri : uriBuilderFactory.expand(""); + URI uri = (this.uri != null ? this.uri : uriBuilderFactory.expand("")); return ClientRequest.create(this.httpMethod, uri) .headers(headers -> headers.addAll(initHeaders())) .cookies(cookies -> cookies.addAll(initCookies())) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java index 465c143ca61..23207a38541 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java @@ -228,9 +228,8 @@ final class DefaultWebClientBuilder implements WebClient.Builder { if (this.uriBuilderFactory != null) { return this.uriBuilderFactory; } - DefaultUriBuilderFactory factory = this.baseUrl != null ? - new DefaultUriBuilderFactory(this.baseUrl) : new DefaultUriBuilderFactory(); - + DefaultUriBuilderFactory factory = (this.baseUrl != null ? + new DefaultUriBuilderFactory(this.baseUrl) : new DefaultUriBuilderFactory()); factory.setDefaultUriVariables(this.defaultUriVariables); return factory; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java index 81af001081a..4bb4fb57149 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java @@ -92,10 +92,8 @@ public abstract class ExchangeFilterFunctions { } private static void checkIllegalCharacters(String username, String password) { - // Basic authentication only supports ISO 8859-1, see // https://stackoverflow.com/questions/702629/utf-8-characters-mangled-in-http-basic-auth-username#703341 - CharsetEncoder encoder = StandardCharsets.ISO_8859_1.newEncoder(); if (!encoder.canEncode(username) || !encoder.canEncode(password)) { throw new IllegalArgumentException( @@ -113,7 +111,6 @@ public abstract class ExchangeFilterFunctions { }).build(); } - /** * Return a filter that generates an error signal when the given * {@link HttpStatus} predicate matches. @@ -128,10 +125,8 @@ public abstract class ExchangeFilterFunctions { Assert.notNull(exceptionFunction, "Function must not be null"); return ExchangeFilterFunction.ofResponseProcessor( - response -> statusPredicate.test(response.statusCode()) ? - Mono.error(exceptionFunction.apply(response)) : - Mono.just(response) - ); + response -> (statusPredicate.test(response.statusCode()) ? + Mono.error(exceptionFunction.apply(response)) : Mono.just(response))); } @@ -146,7 +141,6 @@ public abstract class ExchangeFilterFunctions { private final String password; - /** * Create a new {@code Credentials} instance with the given username and password. * @param username the username @@ -159,7 +153,6 @@ public abstract class ExchangeFilterFunctions { this.password = password; } - /** * Return a {@literal Consumer} that stores the given user and password * as a request attribute of type {@code Credentials} that is in turn @@ -174,21 +167,19 @@ public abstract class ExchangeFilterFunctions { public static Consumer> basicAuthenticationCredentials(String user, String password) { Credentials credentials = new Credentials(user, password); checkIllegalCharacters(user, password); - return map -> map.put(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE, credentials); + return (map -> map.put(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE, credentials)); } - @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (o instanceof Credentials) { - Credentials other = (Credentials) o; - return this.username.equals(other.username) && - this.password.equals(other.password); + if (!(other instanceof Credentials)) { + return false; } - return false; + Credentials otherCred = (Credentials) other; + return (this.username.equals(otherCred.username) && this.password.equals(otherCred.password)); } @Override diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFunctions.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFunctions.java index 856ea06f33b..9e3d87e52ab 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFunctions.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFunctions.java @@ -93,7 +93,6 @@ public abstract class ExchangeFunctions { @Override public Mono exchange(ClientRequest request) { Assert.notNull(request, "ClientRequest must not be null"); - HttpMethod httpMethod = request.method(); URI url = request.url(); @@ -112,7 +111,7 @@ public abstract class ExchangeFunctions { String formatted = request.url().toString(); if (this.disableLoggingRequestDetails) { int index = formatted.indexOf("?"); - formatted = index != -1 ? formatted.substring(0, index) : formatted; + formatted = (index != -1 ? formatted.substring(0, index) : formatted); } logger.debug("HTTP " + request.method() + " " + formatted); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequestBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequestBuilder.java index 32df803f190..4a15d0f3988 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequestBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequestBuilder.java @@ -233,7 +233,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { value = UriUtils.decode(value, StandardCharsets.UTF_8); } else { - value = StringUtils.hasLength(eq) ? "" : null; + value = (StringUtils.hasLength(eq) ? "" : null); } queryParams.add(name, value); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java index dfcf05bc00c..54774f78315 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java @@ -36,8 +36,8 @@ import org.springframework.web.server.ServerWebExchange; /** * {@code HandlerMapping} implementation that supports {@link RouterFunction RouterFunctions}. *

If no {@link RouterFunction} is provided at - * {@linkplain #RouterFunctionMapping(RouterFunction) construction time}, this mapping will detect - * all router functions in the application context, and consult them in + * {@linkplain #RouterFunctionMapping(RouterFunction) construction time}, this mapping + * will detect all router functions in the application context, and consult them in * {@linkplain org.springframework.core.annotation.Order order}. * * @author Arjen Poutsma @@ -114,7 +114,7 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini SortedRouterFunctionsContainer container = new SortedRouterFunctionsContainer(); obtainApplicationContext().getAutowireCapableBeanFactory().autowireBean(container); List> functions = container.routerFunctions; - return CollectionUtils.isEmpty(functions) ? Collections.emptyList() : functions; + return (!CollectionUtils.isEmpty(functions) ? functions : Collections.emptyList()); } private void logRouterFunctions(List> routerFunctions) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractPrefixVersionStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractPrefixVersionStrategy.java index 75d7e541a9e..7a85f020d6e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractPrefixVersionStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractPrefixVersionStrategy.java @@ -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. @@ -38,14 +38,14 @@ public abstract class AbstractPrefixVersionStrategy implements VersionStrategy { protected AbstractPrefixVersionStrategy(String version) { - Assert.hasText(version, "'version' must not be empty"); + Assert.hasText(version, "Version must not be empty"); this.prefix = version; } @Override public String extractVersion(String requestPath) { - return requestPath.startsWith(this.prefix) ? this.prefix : null; + return (requestPath.startsWith(this.prefix) ? this.prefix : null); } @Override diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CachingResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CachingResourceResolver.java index 01c4e31e116..31a7bdb2a70 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CachingResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CachingResourceResolver.java @@ -82,18 +82,15 @@ public class CachingResourceResolver extends AbstractResourceResolver { /** * Configure the supported content codings from the * {@literal "Accept-Encoding"} header for which to cache resource variations. - * *

The codings configured here are generally expected to match those * configured on {@link EncodedResourceResolver#setContentCodings(List)}. - * *

By default this property is set to {@literal ["br", "gzip"]} based on * the value of {@link EncodedResourceResolver#DEFAULT_CODINGS}. - * * @param codings one or more supported content codings * @since 5.1 */ public void setContentCodings(List codings) { - Assert.notEmpty(codings, "At least one content coding expected."); + Assert.notEmpty(codings, "At least one content coding expected"); this.contentCodings.clear(); this.contentCodings.addAll(codings); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java index 102753341fd..da7136ae1df 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java @@ -36,7 +36,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; import org.springframework.util.StringUtils; import org.springframework.web.server.ServerWebExchange; @@ -281,19 +280,19 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport { @Override public int compareTo(ContentChunkInfo other) { - return (this.start < other.start ? -1 : (this.start == other.start ? 0 : 1)); + return Integer.compare(this.start, other.start); } @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (obj != null && obj instanceof ContentChunkInfo) { - ContentChunkInfo other = (ContentChunkInfo) obj; - return (this.start == other.start && this.end == other.end); + if (!(other instanceof ContentChunkInfo)) { + return false; } - return false; + ContentChunkInfo otherCci = (ContentChunkInfo) other; + return (this.start == otherCci.start && this.end == otherCci.end); } @Override diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/EncodedResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/EncodedResourceResolver.java index bdbaa6c56e1..6bcc8822a35 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/EncodedResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/EncodedResourceResolver.java @@ -78,27 +78,22 @@ public class EncodedResourceResolver extends AbstractResourceResolver { * coding that is present in the {@literal "Accept-Encoding"} header for a * given request, and that has a file present with the associated extension, * is used. - * *

Note: Each coding must be associated with a file * extension via {@link #registerExtension} or {@link #setExtensions}. Also * customizations to the list of codings here should be matched by * customizations to the same list in {@link CachingResourceResolver} to * ensure encoded variants of a resource are cached under separate keys. - * *

By default this property is set to {@literal ["br", "gzip"]}. - * * @param codings one or more supported content codings - * @since 5.1 */ public void setContentCodings(List codings) { - Assert.notEmpty(codings, "At least one content coding expected."); + Assert.notEmpty(codings, "At least one content coding expected"); this.contentCodings.clear(); this.contentCodings.addAll(codings); } /** * Return a read-only list with the supported content codings. - * @since 5.1 */ public List getContentCodings() { return Collections.unmodifiableList(this.contentCodings); @@ -110,7 +105,6 @@ public class EncodedResourceResolver extends AbstractResourceResolver { *

By default this is configured with {@literal ["br" -> ".br"]} and * {@literal ["gzip" -> ".gz"]}. * @param extensions the extensions to use. - * @since 5.1 * @see #registerExtension(String, String) */ public void setExtensions(Map extensions) { @@ -118,21 +112,19 @@ public class EncodedResourceResolver extends AbstractResourceResolver { } /** - * Java config friendly alternative to {@link #setExtensions(Map)}. - * @param coding the content coding - * @param extension the associated file extension - * @since 5.1 + * Return a read-only map with coding-to-extension mappings. */ - public void registerExtension(String coding, String extension) { - this.extensions.put(coding, extension.startsWith(".") ? extension : "." + extension); + public Map getExtensions() { + return Collections.unmodifiableMap(this.extensions); } /** - * Return a read-only map with coding-to-extension mappings. - * @since 5.1 + * Java config friendly alternative to {@link #setExtensions(Map)}. + * @param coding the content coding + * @param extension the associated file extension */ - public Map getExtensions() { - return Collections.unmodifiableMap(this.extensions); + public void registerExtension(String coding, String extension) { + this.extensions.put(coding, (extension.startsWith(".") ? extension : "." + extension)); } @@ -174,12 +166,12 @@ public class EncodedResourceResolver extends AbstractResourceResolver { private String getAcceptEncoding(ServerWebExchange exchange) { ServerHttpRequest request = exchange.getRequest(); String header = request.getHeaders().getFirst(HttpHeaders.ACCEPT_ENCODING); - return header != null ? header.toLowerCase() : null; + return (header != null ? header.toLowerCase() : null); } private String getExtension(String coding) { String extension = this.extensions.get(coding); - Assert.notNull(extension, "No file extension associated with content coding " + coding); + Assert.state(extension != null, () -> "No file extension associated with content coding " + coding); return extension; } @@ -202,7 +194,6 @@ public class EncodedResourceResolver extends AbstractResourceResolver { private final Resource encoded; - EncodedResource(Resource original, String coding, String extension) throws IOException { this.original = original; this.coding = coding; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java index ec3315943eb..ec5379bfa62 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java @@ -388,8 +388,8 @@ public class ResourceWebHandler implements WebHandler, InitializingBean { return Mono.empty(); } - Assert.notNull(this.resolverChain, "ResourceResolverChain not initialized."); - Assert.notNull(this.transformerChain, "ResourceTransformerChain not initialized."); + Assert.state(this.resolverChain != null, "ResourceResolverChain not initialized"); + Assert.state(this.transformerChain != null, "ResourceTransformerChain not initialized"); return this.resolverChain.resolveResource(exchange, path, getLocations()) .flatMap(resource -> this.transformerChain.transform(exchange, resource)); @@ -419,7 +419,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean { for (int i = 0; i < path.length(); i++) { char curr = path.charAt(i); try { - if ((curr == '/') && (prev == '/')) { + if (curr == '/' && prev == '/') { if (sb == null) { sb = new StringBuilder(path.substring(0, i)); } @@ -433,7 +433,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean { prev = curr; } } - return sb != null ? sb.toString() : path; + return (sb != null ? sb.toString() : path); } private String cleanLeadingSlash(String path) { @@ -446,7 +446,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean { if (i == 0 || (i == 1 && slash)) { return path; } - return slash ? "/" + path.substring(i) : path.substring(i); + return (slash ? "/" + path.substring(i) : path.substring(i)); } } return (slash ? "/" : ""); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java index 8402dfe1851..9e41cddceb0 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java @@ -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. @@ -20,6 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.server.NotAcceptableStatusException; import org.springframework.web.server.ServerWebExchange; @@ -89,15 +90,15 @@ abstract class AbstractMediaTypeExpression implements Comparable implements NameValueExpression @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(@Nullable Object other) { + if (this == other) { return true; } - if (obj != null && obj instanceof AbstractNameValueExpression) { - AbstractNameValueExpression other = (AbstractNameValueExpression) obj; - String thisName = isCaseSensitiveName() ? this.name : this.name.toLowerCase(); - String otherName = isCaseSensitiveName() ? other.name : other.name.toLowerCase(); - return ((thisName.equalsIgnoreCase(otherName)) && - (this.value != null ? this.value.equals(other.value) : other.value == null) && - this.isNegated == other.isNegated); + if (other == null || getClass() != other.getClass()) { + return false; } - return false; + AbstractNameValueExpression that = (AbstractNameValueExpression) other; + return ((isCaseSensitiveName() ? this.name.equals(that.name) : this.name.equalsIgnoreCase(that.name)) && + ObjectUtils.nullSafeEquals(this.value, that.value) && this.isNegated == that.isNegated); } @Override @@ -134,4 +131,5 @@ abstract class AbstractNameValueExpression implements NameValueExpression } return builder.toString(); } + } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractRequestCondition.java index 54e37b9c652..657a4e7779d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractRequestCondition.java @@ -19,6 +19,8 @@ package org.springframework.web.reactive.result.condition; import java.util.Collection; import java.util.Iterator; +import org.springframework.lang.Nullable; + /** * A base class for {@link RequestCondition} types providing implementations of * {@link #equals(Object)}, {@link #hashCode()}, and {@link #toString()}. @@ -28,19 +30,17 @@ import java.util.Iterator; * @param the type of objects that this RequestCondition can be combined * with and compared to */ -public abstract class AbstractRequestCondition> - implements RequestCondition { +public abstract class AbstractRequestCondition> implements RequestCondition { @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(@Nullable Object other) { + if (this == other) { return true; } - if (obj != null && getClass() == obj.getClass()) { - AbstractRequestCondition other = (AbstractRequestCondition) obj; - return getContent().equals(other.getContent()); + if (other == null || getClass() != other.getClass()) { + return false; } - return false; + return getContent().equals(((AbstractRequestCondition) other).getContent()); } @Override diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java index 1c4d0aec9a3..5fbaf12f5e5 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java @@ -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. @@ -91,7 +91,7 @@ public class CompositeRequestCondition extends AbstractRequestCondition getContent() { - return (isEmpty()) ? Collections.emptyList() : getConditions(); + return (!isEmpty() ? getConditions() : Collections.emptyList()); } @Override diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java index f9133ae57de..f41bad10245 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java @@ -145,7 +145,7 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition result = new LinkedHashSet<>(this.expressions); result.removeIf(expression -> !expression.match(exchange)); - return (result.isEmpty()) ? null : new ConsumesRequestCondition(result); + return (!result.isEmpty() ? new ConsumesRequestCondition(result) : null); } /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/PatternsRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/PatternsRequestCondition.java index 3bbf3591cf7..a8dbfe93b3f 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/PatternsRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/PatternsRequestCondition.java @@ -56,14 +56,9 @@ public final class PatternsRequestCondition extends AbstractRequestCondition patterns) { - this(toSortedSet(patterns)); + this(new TreeSet<>(patterns)); } - private static SortedSet toSortedSet(Collection patterns) { - TreeSet sorted = new TreeSet<>(); - sorted.addAll(patterns); - return sorted; - } private PatternsRequestCondition(SortedSet patterns) { this.patterns = patterns; @@ -127,8 +122,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition matches = getMatchingPatterns(exchange); - return matches.isEmpty() ? null : - new PatternsRequestCondition(matches); + return (!matches.isEmpty() ? new PatternsRequestCondition(matches) : null); } /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java index c7ab6056143..ac3ee39833d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java @@ -192,7 +192,7 @@ public final class ProducesRequestCondition extends AbstractRequestCondition result = new LinkedHashSet<>(this.expressions); result.removeIf(expression -> !expression.match(exchange)); - return (result.isEmpty()) ? null : new ProducesRequestCondition(result, this.contentTypeResolver); + return (!result.isEmpty() ? new ProducesRequestCondition(result, this.contentTypeResolver) : null); } /** @@ -273,7 +273,7 @@ public final class ProducesRequestCondition extends AbstractRequestCondition invoke(ServerWebExchange exchange, BindingContext bindingContext, - Object... providedArgs) { + public Mono invoke( + ServerWebExchange exchange, BindingContext bindingContext, Object... providedArgs) { return resolveArguments(exchange, bindingContext, providedArgs).flatMap(args -> { Object value; @@ -161,7 +161,7 @@ public class InvocableHandlerMethod extends HandlerMethod { ReactiveAdapter adapter = this.reactiveAdapterRegistry.getAdapter(returnType.getParameterType()); boolean asyncVoid = isAsyncVoidReturnType(returnType, adapter); if ((value == null || asyncVoid) && isResponseHandled(args, exchange)) { - return asyncVoid ? Mono.from(adapter.toPublisher(value)) : Mono.empty(); + return (asyncVoid ? Mono.from(adapter.toPublisher(value)) : Mono.empty()); } HandlerResult result = new HandlerResult(this, value, returnType, bindingContext); @@ -169,8 +169,8 @@ public class InvocableHandlerMethod extends HandlerMethod { }); } - private Mono resolveArguments(ServerWebExchange exchange, BindingContext bindingContext, - Object... providedArgs) { + private Mono resolveArguments( + ServerWebExchange exchange, BindingContext bindingContext, Object... providedArgs) { if (ObjectUtils.isEmpty(getMethodParameters())) { return EMPTY_ARGS; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java index b8b8166e80d..809e62f836f 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java @@ -487,8 +487,8 @@ public final class RequestMappingInfo implements RequestCondition> messageReaders, - ReactiveAdapterRegistry adapterRegistry) { + protected AbstractMessageReaderArgumentResolver( + List> messageReaders, ReactiveAdapterRegistry adapterRegistry) { super(adapterRegistry); Assert.notEmpty(messageReaders, "At least one HttpMessageReader is required"); @@ -121,6 +121,7 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho */ protected Mono readBody(MethodParameter bodyParameter, boolean isBodyRequired, BindingContext bindingContext, ServerWebExchange exchange) { + return this.readBody(bodyParameter, null, isBodyRequired, bindingContext, exchange); } @@ -139,7 +140,7 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho boolean isBodyRequired, BindingContext bindingContext, ServerWebExchange exchange) { ResolvableType bodyType = ResolvableType.forMethodParameter(bodyParam); - ResolvableType actualType = actualParam == null ? bodyType : ResolvableType.forMethodParameter(actualParam); + ResolvableType actualType = (actualParam != null ? ResolvableType.forMethodParameter(actualParam) : bodyType); Class resolvedType = bodyType.resolve(); ReactiveAdapter adapter = (resolvedType != null ? getAdapterRegistry().getAdapter(resolvedType) : null); ResolvableType elementType = (adapter != null ? bodyType.getGeneric() : bodyType); @@ -190,7 +191,7 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho mono = mono.doOnNext(target -> validate(target, hints, bodyParam, bindingContext, exchange)); } - return adapter != null ? Mono.just(adapter.fromPublisher(mono)) : Mono.from(mono); + return (adapter != null ? Mono.just(adapter.fromPublisher(mono)) : Mono.from(mono)); } } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java index 60aa61d5cbd..788c6a8c318 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java @@ -103,8 +103,8 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa * Write a given body to the response with {@link HttpMessageWriter}. * @param body the object to write * @param bodyParameter the {@link MethodParameter} of the body to write - * @param actualParameter the actual return type of the method that returned the - * value; could be different from {@code bodyParameter} when processing {@code HttpEntity} + * @param actualParam the actual return type of the method that returned the value; + * could be different from {@code bodyParameter} when processing {@code HttpEntity} * for example * @param exchange the current exchange * @return indicates completion or error @@ -112,11 +112,10 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa */ @SuppressWarnings({ "unchecked", "rawtypes" }) protected Mono writeBody(@Nullable Object body, MethodParameter bodyParameter, - @Nullable MethodParameter actualParameter, ServerWebExchange exchange) { + @Nullable MethodParameter actualParam, ServerWebExchange exchange) { ResolvableType bodyType = ResolvableType.forMethodParameter(bodyParameter); - ResolvableType actualType = (actualParameter == null ? - bodyType : ResolvableType.forMethodParameter(actualParameter)); + ResolvableType actualType = (actualParam != null ? ResolvableType.forMethodParameter(actualParam) : bodyType); Class bodyClass = bodyType.resolve(); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(bodyClass, body); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/HttpEntityArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/HttpEntityArgumentResolver.java index 6e53a85d2fa..6e558c496ee 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/HttpEntityArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/HttpEntityArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -40,9 +40,7 @@ import org.springframework.web.server.ServerWebExchange; */ public class HttpEntityArgumentResolver extends AbstractMessageReaderArgumentResolver { - public HttpEntityArgumentResolver(List> readers, - ReactiveAdapterRegistry registry) { - + public HttpEntityArgumentResolver(List> readers, ReactiveAdapterRegistry registry) { super(readers, registry); } @@ -64,9 +62,9 @@ public class HttpEntityArgumentResolver extends AbstractMessageReaderArgumentRes } private Object createEntity(@Nullable Object body, Class entityType, ServerHttpRequest request) { - return RequestEntity.class.equals(entityType) ? + return (RequestEntity.class.equals(entityType) ? new RequestEntity<>(body, request.getHeaders(), request.getMethod(), request.getURI()) : - new HttpEntity<>(body, request.getHeaders()); + new HttpEntity<>(body, request.getHeaders())); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PrincipalArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PrincipalArgumentResolver.java index df94490a5e7..60ad36741d3 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PrincipalArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PrincipalArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -36,7 +36,6 @@ import org.springframework.web.server.ServerWebExchange; */ public class PrincipalArgumentResolver extends HandlerMethodArgumentResolverSupport { - public PrincipalArgumentResolver(ReactiveAdapterRegistry adapterRegistry) { super(adapterRegistry); } @@ -48,12 +47,12 @@ public class PrincipalArgumentResolver extends HandlerMethodArgumentResolverSupp } @Override - public Mono resolveArgument(MethodParameter parameter, BindingContext context, - ServerWebExchange exchange) { + public Mono resolveArgument( + MethodParameter parameter, BindingContext context, ServerWebExchange exchange) { Mono principal = exchange.getPrincipal(); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(parameter.getParameterType()); - return adapter != null ? Mono.just(adapter.fromPublisher(principal)) : Mono.from(principal); + return (adapter != null ? Mono.just(adapter.fromPublisher(principal)) : Mono.from(principal)); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolver.java index 640cfbbb793..96ecdda7620 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolver.java @@ -51,7 +51,6 @@ import org.springframework.web.server.ServerWebInputException; */ public class RequestPartMethodArgumentResolver extends AbstractMessageReaderArgumentResolver { - public RequestPartMethodArgumentResolver(List> readers, ReactiveAdapterRegistry registry) { @@ -78,9 +77,7 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageReaderArgu .flatMapMany(map -> { List list = map.get(name); if (CollectionUtils.isEmpty(list)) { - return isRequired ? - Flux.error(getMissingPartException(name, parameter)) : - Flux.empty(); + return (isRequired ? Flux.error(getMissingPartException(name, parameter)) : Flux.empty()); } return Flux.fromIterable(list); }); @@ -105,7 +102,7 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageReaderArgu // Mono or Flux MethodParameter elementType = parameter.nested(); if (Part.class.isAssignableFrom(elementType.getNestedParameterType())) { - parts = adapter.isMultiValue() ? parts : parts.take(1); + parts = (adapter.isMultiValue() ? parts : parts.take(1)); return Mono.just(adapter.fromPublisher(parts)); } // We have to decode the content for each part, one at a time diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolver.java index 6470f34e240..7804d4c3f25 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolver.java @@ -102,12 +102,12 @@ public class ServerWebExchangeArgumentResolver extends HandlerMethodArgumentReso else if (TimeZone.class == paramType) { LocaleContext localeContext = exchange.getLocaleContext(); TimeZone timeZone = getTimeZone(localeContext); - return timeZone != null ? timeZone : TimeZone.getDefault(); + return (timeZone != null ? timeZone : TimeZone.getDefault()); } else if (ZoneId.class == paramType) { LocaleContext localeContext = exchange.getLocaleContext(); TimeZone timeZone = getTimeZone(localeContext); - return timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault(); + return (timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault()); } else if (UriBuilder.class == paramType || UriComponentsBuilder.class == paramType) { URI uri = exchange.getRequest().getURI(); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/WebSessionArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/WebSessionArgumentResolver.java index 0df698f0da9..5356e51d865 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/WebSessionArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/WebSessionArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -55,7 +55,7 @@ public class WebSessionArgumentResolver extends HandlerMethodArgumentResolverSup Mono session = exchange.getSession(); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(parameter.getParameterType()); - return adapter != null ? Mono.just(adapter.fromPublisher(session)) : Mono.from(session); + return (adapter != null ? Mono.just(adapter.fromPublisher(session)) : Mono.from(session)); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/HttpMessageWriterView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/HttpMessageWriterView.java index c182e3f561f..4b181e551d4 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/HttpMessageWriterView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/HttpMessageWriterView.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -23,8 +23,6 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -45,9 +43,6 @@ import org.springframework.web.server.ServerWebExchange; */ public class HttpMessageWriterView implements View { - private static final Log logger = LogFactory.getLog(HttpMessageWriter.class); - - private final HttpMessageWriter writer; private final Set modelKeys = new HashSet<>(4); @@ -66,7 +61,7 @@ public class HttpMessageWriterView implements View { * Constructor with a fully initialized {@link HttpMessageWriter}. */ public HttpMessageWriterView(HttpMessageWriter writer) { - Assert.notNull(writer, "'writer' is required."); + Assert.notNull(writer, "HttpMessageWriter is required"); this.writer = writer; this.canWriteMap = writer.canWrite(ResolvableType.forClass(Map.class), null); } @@ -118,12 +113,11 @@ public class HttpMessageWriterView implements View { @Override @SuppressWarnings("unchecked") - public Mono render(@Nullable Map model, @Nullable MediaType contentType, - ServerWebExchange exchange) { + public Mono render( + @Nullable Map model, @Nullable MediaType contentType, ServerWebExchange exchange) { Object value = getObjectToRender(model); - return (value != null) ? - write(value, contentType, exchange) : exchange.getResponse().setComplete(); + return (value != null ? write(value, contentType, exchange) : exchange.getResponse().setComplete()); } @Nullable diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java index 7665a9607cc..7651b4e4fcf 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateView.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -196,7 +196,7 @@ public class ScriptTemplateView extends AbstractUrlBasedView { } if (this.resourceLoaderPaths == null) { String resourceLoaderPath = viewConfig.getResourceLoaderPath(); - setResourceLoaderPath(resourceLoaderPath == null ? DEFAULT_RESOURCE_LOADER_PATH : resourceLoaderPath); + setResourceLoaderPath(resourceLoaderPath != null ? resourceLoaderPath : DEFAULT_RESOURCE_LOADER_PATH); } if (this.sharedEngine == null && viewConfig.isSharedEngine() != null) { this.sharedEngine = viewConfig.isSharedEngine(); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/AbstractListenerWebSocketSession.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/AbstractListenerWebSocketSession.java index ab74f60a2ee..b0d4752aefa 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/AbstractListenerWebSocketSession.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/AbstractListenerWebSocketSession.java @@ -80,8 +80,8 @@ public abstract class AbstractListenerWebSocketSession extends AbstractWebSoc * @param handshakeInfo the handshake info * @param bufferFactory the DataBuffer factor for the current connection */ - public AbstractListenerWebSocketSession(T delegate, String id, HandshakeInfo handshakeInfo, - DataBufferFactory bufferFactory) { + public AbstractListenerWebSocketSession( + T delegate, String id, HandshakeInfo handshakeInfo, DataBufferFactory bufferFactory) { this(delegate, id, handshakeInfo, bufferFactory, null); } @@ -106,9 +106,8 @@ public abstract class AbstractListenerWebSocketSession extends AbstractWebSoc @Override public Flux receive() { - return canSuspendReceiving() ? - Flux.from(this.receivePublisher) : - Flux.from(this.receivePublisher).onBackpressureBuffer(RECEIVE_BUFFER_SIZE); + return (canSuspendReceiving() ? Flux.from(this.receivePublisher) : + Flux.from(this.receivePublisher).onBackpressureBuffer(RECEIVE_BUFFER_SIZE)); } @Override diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java index c14761bf2b3..37d3911897e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java @@ -42,7 +42,6 @@ import org.springframework.web.reactive.socket.adapter.JettyWebSocketSession; import org.springframework.web.reactive.socket.server.RequestUpgradeStrategy; import org.springframework.web.server.ServerWebExchange; - /** * A {@link RequestUpgradeStrategy} for use with Jetty. * @@ -95,9 +94,9 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Life if (!isRunning() && servletContext != null) { this.running = true; try { - this.factory = this.webSocketPolicy != null ? + this.factory = (this.webSocketPolicy != null ? new WebSocketServerFactory(servletContext, this.webSocketPolicy) : - new WebSocketServerFactory(servletContext); + new WebSocketServerFactory(servletContext)); this.factory.setCreator((request, response) -> { WebSocketHandlerContainer container = adapterHolder.get(); String protocol = container.getProtocol(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/HeadersRequestConditionTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/HeadersRequestConditionTests.java index af865c2edea..b2889fc9b4d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/HeadersRequestConditionTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/HeadersRequestConditionTests.java @@ -37,7 +37,7 @@ public class HeadersRequestConditionTests { public void headerEquals() { assertEquals(new HeadersRequestCondition("foo"), new HeadersRequestCondition("foo")); assertEquals(new HeadersRequestCondition("foo"), new HeadersRequestCondition("FOO")); - assertFalse(new HeadersRequestCondition("foo").equals(new HeadersRequestCondition("bar"))); + assertNotEquals(new HeadersRequestCondition("foo"), new HeadersRequestCondition("bar")); assertEquals(new HeadersRequestCondition("foo=bar"), new HeadersRequestCondition("foo=bar")); assertEquals(new HeadersRequestCondition("foo=bar"), new HeadersRequestCondition("FOO=bar")); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java index 160032880d6..39bd0dee646 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -129,7 +129,9 @@ public class PathMatchConfigurer { * @since 5.1 */ public PathMatchConfigurer addPathPrefix(String prefix, Predicate> predicate) { - this.pathPrefixes = this.pathPrefixes == null ? new LinkedHashMap<>() : this.pathPrefixes; + if (this.pathPrefixes == null) { + this.pathPrefixes = new LinkedHashMap<>(); + } this.pathPrefixes.put(prefix, predicate); return this; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java index 067d3002071..a0b829bc85c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -74,15 +74,15 @@ abstract class AbstractMediaTypeExpression implements MediaTypeExpression, Compa } @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { + public boolean equals(@Nullable Object other) { + if (this == other) { return true; } - if (obj != null && getClass() == obj.getClass()) { - AbstractMediaTypeExpression other = (AbstractMediaTypeExpression) obj; - return (this.mediaType.equals(other.mediaType) && this.isNegated == other.isNegated); + if (other == null || getClass() != other.getClass()) { + return false; } - return false; + AbstractMediaTypeExpression otherExpr = (AbstractMediaTypeExpression) other; + return (this.mediaType.equals(otherExpr.mediaType) && this.isNegated == otherExpr.isNegated); } @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java index 252b99fcd60..1cf003c04ed 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet.mvc.condition; import javax.servlet.http.HttpServletRequest; import org.springframework.lang.Nullable; +import org.springframework.util.ObjectUtils; /** * Supports "name=value" style expressions as described in: @@ -93,19 +94,16 @@ abstract class AbstractNameValueExpression implements NameValueExpression @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(@Nullable Object other) { + if (this == other) { return true; } - if (obj instanceof AbstractNameValueExpression) { - AbstractNameValueExpression other = (AbstractNameValueExpression) obj; - String thisName = (isCaseSensitiveName() ? this.name : this.name.toLowerCase()); - String otherName = (isCaseSensitiveName() ? other.name : other.name.toLowerCase()); - return (thisName.equalsIgnoreCase(otherName) && - (this.value != null ? this.value.equals(other.value) : other.value == null) && - this.isNegated == other.isNegated); + if (other == null || getClass() != other.getClass()) { + return false; } - return false; + AbstractNameValueExpression that = (AbstractNameValueExpression) other; + return ((isCaseSensitiveName() ? this.name.equals(that.name) : this.name.equalsIgnoreCase(that.name)) && + ObjectUtils.nullSafeEquals(this.value, that.value) && this.isNegated == that.isNegated); } @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractRequestCondition.java index b28b6912c4e..50a99f04a18 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractRequestCondition.java @@ -57,15 +57,14 @@ public abstract class AbstractRequestCondition other = (AbstractRequestCondition) obj; - return getContent().equals(other.getContent()); + if (other == null || getClass() != other.getClass()) { + return false; } - return false; + return getContent().equals(((AbstractRequestCondition) other).getContent()); } @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java index c464d7e5489..eb2c5651068 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java @@ -92,7 +92,7 @@ public class CompositeRequestCondition extends AbstractRequestCondition getContent() { - return (isEmpty()) ? Collections.emptyList() : getConditions(); + return (!isEmpty() ? getConditions() : Collections.emptyList()); } @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java index 0274dc5e1be..8f76d603b12 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java @@ -146,7 +146,7 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition matches = getMatchingPatterns(lookupPath); - - return matches.isEmpty() ? null : - new PatternsRequestCondition(matches, this.pathHelper, this.pathMatcher, this.useSuffixPatternMatch, - this.useTrailingSlashMatch, this.fileExtensions); + return (!matches.isEmpty() ? + new PatternsRequestCondition(matches, this.pathHelper, this.pathMatcher, + this.useSuffixPatternMatch, this.useTrailingSlashMatch, this.fileExtensions) : null); } /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractVersionStrategy.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractVersionStrategy.java index eda8d17b5e2..f53eabe672b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractVersionStrategy.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractVersionStrategy.java @@ -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. @@ -86,7 +86,7 @@ public abstract class AbstractVersionStrategy implements VersionStrategy { private final String prefix; public PrefixVersionPathStrategy(String version) { - Assert.hasText(version, "'version' must not be empty"); + Assert.hasText(version, "Version must not be empty"); this.prefix = version; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CachingResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CachingResourceResolver.java index f9eb10ba5bb..51459e2dd26 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CachingResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CachingResourceResolver.java @@ -82,18 +82,15 @@ public class CachingResourceResolver extends AbstractResourceResolver { /** * Configure the supported content codings from the * {@literal "Accept-Encoding"} header for which to cache resource variations. - * *

The codings configured here are generally expected to match those * configured on {@link EncodedResourceResolver#setContentCodings(List)}. - * *

By default this property is set to {@literal ["br", "gzip"]} based on * the value of {@link EncodedResourceResolver#DEFAULT_CODINGS}. - * * @param codings one or more supported content codings * @since 5.1 */ public void setContentCodings(List codings) { - Assert.notEmpty(codings, "At least one content coding expected."); + Assert.notEmpty(codings, "At least one content coding expected"); this.contentCodings.clear(); this.contentCodings.addAll(codings); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CssLinkResourceTransformer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CssLinkResourceTransformer.java index 141b221de5d..e90754b7e5b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CssLinkResourceTransformer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CssLinkResourceTransformer.java @@ -229,19 +229,19 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport { @Override public int compareTo(ContentChunkInfo other) { - return (this.start < other.start ? -1 : (this.start == other.start ? 0 : 1)); + return Integer.compare(this.start, other.start); } @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (obj instanceof ContentChunkInfo) { - ContentChunkInfo other = (ContentChunkInfo) obj; - return (this.start == other.start && this.end == other.end); + if (!(other instanceof ContentChunkInfo)) { + return false; } - return false; + ContentChunkInfo otherCci = (ContentChunkInfo) other; + return (this.start == otherCci.start && this.end == otherCci.end); } @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/EncodedResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/EncodedResourceResolver.java index 2fb63d170c9..c33b461cf47 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/EncodedResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/EncodedResourceResolver.java @@ -75,27 +75,22 @@ public class EncodedResourceResolver extends AbstractResourceResolver { * coding that is present in the {@literal "Accept-Encoding"} header for a * given request, and that has a file present with the associated extension, * is used. - * *

Note: Each coding must be associated with a file * extension via {@link #registerExtension} or {@link #setExtensions}. Also * customizations to the list of codings here should be matched by * customizations to the same list in {@link CachingResourceResolver} to * ensure encoded variants of a resource are cached under separate keys. - * *

By default this property is set to {@literal ["br", "gzip"]}. - * * @param codings one or more supported content codings - * @since 5.1 */ public void setContentCodings(List codings) { - Assert.notEmpty(codings, "At least one content coding expected."); + Assert.notEmpty(codings, "At least one content coding expected"); this.contentCodings.clear(); this.contentCodings.addAll(codings); } /** * Return a read-only list with the supported content codings. - * @since 5.1 */ public List getContentCodings() { return Collections.unmodifiableList(this.contentCodings); @@ -107,7 +102,6 @@ public class EncodedResourceResolver extends AbstractResourceResolver { *

By default this is configured with {@literal ["br" -> ".br"]} and * {@literal ["gzip" -> ".gz"]}. * @param extensions the extensions to use. - * @since 5.1 * @see #registerExtension(String, String) */ public void setExtensions(Map extensions) { @@ -115,21 +109,19 @@ public class EncodedResourceResolver extends AbstractResourceResolver { } /** - * Java config friendly alternative to {@link #setExtensions(Map)}. - * @param coding the content coding - * @param extension the associated file extension - * @since 5.1 + * Return a read-only map with coding-to-extension mappings. */ - public void registerExtension(String coding, String extension) { - this.extensions.put(coding, extension.startsWith(".") ? extension : "." + extension); + public Map getExtensions() { + return Collections.unmodifiableMap(this.extensions); } /** - * Return a read-only map with coding-to-extension mappings. - * @since 5.1 + * Java config friendly alternative to {@link #setExtensions(Map)}. + * @param coding the content coding + * @param extension the associated file extension */ - public Map getExtensions() { - return Collections.unmodifiableMap(this.extensions); + public void registerExtension(String coding, String extension) { + this.extensions.put(coding, (extension.startsWith(".") ? extension : "." + extension)); } @@ -168,12 +160,12 @@ public class EncodedResourceResolver extends AbstractResourceResolver { @Nullable private String getAcceptEncoding(HttpServletRequest request) { String header = request.getHeader(HttpHeaders.ACCEPT_ENCODING); - return header != null ? header.toLowerCase() : null; + return (header != null ? header.toLowerCase() : null); } private String getExtension(String coding) { String extension = this.extensions.get(coding); - Assert.notNull(extension, "No file extension associated with content coding " + coding); + Assert.state(extension != null, () -> "No file extension associated with content coding " + coding); return extension; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java index ba32b7faa79..787e4c3b4e8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java @@ -225,7 +225,7 @@ public class ScriptTemplateView extends AbstractUrlBasedView { } if (this.resourceLoaderPaths == null) { String resourceLoaderPath = viewConfig.getResourceLoaderPath(); - setResourceLoaderPath(resourceLoaderPath == null ? DEFAULT_RESOURCE_LOADER_PATH : resourceLoaderPath); + setResourceLoaderPath(resourceLoaderPath != null ? resourceLoaderPath : DEFAULT_RESOURCE_LOADER_PATH); } if (this.sharedEngine == null && viewConfig.isSharedEngine() != null) { this.sharedEngine = viewConfig.isSharedEngine(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/HeadersRequestConditionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/HeadersRequestConditionTests.java index 9a69a62c9be..2a301c0d063 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/HeadersRequestConditionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/HeadersRequestConditionTests.java @@ -34,7 +34,7 @@ public class HeadersRequestConditionTests { public void headerEquals() { assertEquals(new HeadersRequestCondition("foo"), new HeadersRequestCondition("foo")); assertEquals(new HeadersRequestCondition("foo"), new HeadersRequestCondition("FOO")); - assertFalse(new HeadersRequestCondition("foo").equals(new HeadersRequestCondition("bar"))); + assertNotEquals(new HeadersRequestCondition("foo"), new HeadersRequestCondition("bar")); assertEquals(new HeadersRequestCondition("foo=bar"), new HeadersRequestCondition("foo=bar")); assertEquals(new HeadersRequestCondition("foo=bar"), new HeadersRequestCondition("FOO=bar")); }