Browse Source

Polishing

pull/25798/head
Juergen Hoeller 5 years ago
parent
commit
3c84863271
  1. 10
      spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java
  2. 7
      spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java
  3. 4
      spring-core/src/main/java/org/springframework/core/convert/support/StringToUUIDConverter.java
  4. 2
      spring-web/src/main/java/org/springframework/http/ContentDisposition.java
  5. 34
      src/docs/asciidoc/core/core-aop-api.adoc
  6. 4
      src/docs/asciidoc/core/core-aop.adoc
  7. 7
      src/docs/asciidoc/core/core-beans.adoc

10
spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java

@ -103,6 +103,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -103,6 +103,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
return this.defaultCharset;
}
@Override
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
return (elementType.resolve() == String.class && super.canDecode(elementType, mimeType));
@ -167,7 +168,6 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -167,7 +168,6 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
/**
* Finds the first match and longest delimiter, {@link EndFrameBuffer} just after it.
*
* @param dataBuffer the buffer to find delimiters in
* @param matcher used to find the first delimiters
* @return a flux of buffers, containing {@link EndFrameBuffer} after each delimiter that was
@ -221,7 +221,6 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -221,7 +221,6 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
}
DataBuffer result = dataBuffers.get(0).factory().join(dataBuffers);
if (stripDelimiter && matchingDelimiter != null) {
result.writePosition(result.writePosition() - matchingDelimiter.length);
}
@ -229,8 +228,6 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -229,8 +228,6 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
}
/**
* Create a {@code StringDecoder} for {@code "text/plain"}.
* @param stripDelimiter this flag is ignored
@ -293,8 +290,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -293,8 +290,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
private static final DataBuffer BUFFER = new DefaultDataBufferFactory().wrap(new byte[0]);
private byte[] delimiter;
private final byte[] delimiter;
public EndFrameBuffer(byte[] delimiter) {
super(BUFFER);
@ -304,7 +300,6 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -304,7 +300,6 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
public byte[] delimiter() {
return this.delimiter;
}
}
@ -313,7 +308,6 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> { @@ -313,7 +308,6 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
private final LimitedDataBufferList list;
LimitChecker(int maxInMemorySize) {
this.list = new LimitedDataBufferList(maxInMemorySize);
}

7
spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2020 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.
@ -30,9 +30,9 @@ import org.springframework.core.convert.converter.Converter; @@ -30,9 +30,9 @@ import org.springframework.core.convert.converter.Converter;
*/
final class StringToBooleanConverter implements Converter<String, Boolean> {
private static final Set<String> trueValues = new HashSet<>(4);
private static final Set<String> trueValues = new HashSet<>(8);
private static final Set<String> falseValues = new HashSet<>(4);
private static final Set<String> falseValues = new HashSet<>(8);
static {
trueValues.add("true");
@ -46,6 +46,7 @@ final class StringToBooleanConverter implements Converter<String, Boolean> { @@ -46,6 +46,7 @@ final class StringToBooleanConverter implements Converter<String, Boolean> {
falseValues.add("0");
}
@Override
public Boolean convert(String source) {
String value = source.trim();

4
spring-core/src/main/java/org/springframework/core/convert/support/StringToUUIDConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@ package org.springframework.core.convert.support; @@ -19,6 +19,7 @@ package org.springframework.core.convert.support;
import java.util.UUID;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@ -31,6 +32,7 @@ import org.springframework.util.StringUtils; @@ -31,6 +32,7 @@ import org.springframework.util.StringUtils;
final class StringToUUIDConverter implements Converter<String, UUID> {
@Override
@Nullable
public UUID convert(String source) {
return (StringUtils.hasText(source) ? UUID.fromString(source.trim()) : null);
}

2
spring-web/src/main/java/org/springframework/http/ContentDisposition.java

@ -556,7 +556,7 @@ public final class ContentDisposition { @@ -556,7 +556,7 @@ public final class ContentDisposition {
private static class BuilderImpl implements Builder {
private String type;
private final String type;
@Nullable
private String name;

34
src/docs/asciidoc/core/core-aop-api.adoc

@ -103,13 +103,13 @@ The `MethodMatcher` interface is normally more important. The complete interface @@ -103,13 +103,13 @@ The `MethodMatcher` interface is normally more important. The complete interface
The `matches(Method, Class)` method is used to test whether this pointcut ever
matches a given method on a target class. This evaluation can be performed when an AOP
proxy is created to avoid the need for a test on every method invocation. If the
two-argument `matches` method returns `true` for a given method, and the `isRuntime()` method
for the MethodMatcher returns `true`, the three-argument matches method is invoked on
every method invocation. This lets a pointcut look at the arguments passed to the
method invocation immediately before the target advice starts.
two-argument `matches` method returns `true` for a given method, and the `isRuntime()`
method for the MethodMatcher returns `true`, the three-argument matches method is
invoked on every method invocation. This lets a pointcut look at the arguments passed
to the method invocation immediately before the target advice starts.
Most `MethodMatcher` implementations are static, meaning that their `isRuntime()` method returns `false`.
In this case, the three-argument `matches` method is never invoked.
Most `MethodMatcher` implementations are static, meaning that their `isRuntime()` method
returns `false`. In this case, the three-argument `matches` method is never invoked.
TIP: If possible, try to make pointcuts static, allowing the AOP framework to cache the
results of pointcut evaluation when an AOP proxy is created.
@ -145,20 +145,20 @@ See the <<aop, previous chapter>> for a discussion of supported AspectJ pointcut @@ -145,20 +145,20 @@ See the <<aop, previous chapter>> for a discussion of supported AspectJ pointcut
[[aop-api-pointcuts-impls]]
=== Convenience Pointcut Implementations
Spring provides several convenient pointcut implementations. You can use some of them directly.
Others are intended to be subclassed in application-specific pointcuts.
Spring provides several convenient pointcut implementations. You can use some of them
directly; others are intended to be subclassed in application-specific pointcuts.
[[aop-api-pointcuts-static]]
==== Static Pointcuts
Static pointcuts are based on the method and the target class and cannot take into account the
method's arguments. Static pointcuts suffice -- and are best -- for most usages.
Spring can evaluate a static pointcut only once, when a method is first
invoked. After that, there is no need to evaluate the pointcut again with each method
invocation.
Static pointcuts are based on the method and the target class and cannot take into account
the method's arguments. Static pointcuts suffice -- and are best -- for most usages.
Spring can evaluate a static pointcut only once, when a method is first invoked.
After that, there is no need to evaluate the pointcut again with each method invocation.
The rest of this section describes some of the static pointcut implementations that are included with Spring.
The rest of this section describes some of the static pointcut implementations that are
included with Spring.
[[aop-api-pointcuts-regex]]
===== Regular Expression Pointcuts
@ -168,9 +168,9 @@ frameworks besides Spring make this possible. @@ -168,9 +168,9 @@ frameworks besides Spring make this possible.
`org.springframework.aop.support.JdkRegexpMethodPointcut` is a generic regular
expression pointcut that uses the regular expression support in the JDK.
With the `JdkRegexpMethodPointcut` class, you can provide a list of pattern strings. If
any of these is a match, the pointcut evaluates to `true`. (So, the result is
effectively the union of these pointcuts.)
With the `JdkRegexpMethodPointcut` class, you can provide a list of pattern strings.
If any of these is a match, the pointcut evaluates to `true`. (As a consequence,
the resulting pointcut is effectively the union of the specified patterns.)
The following example shows how to use `JdkRegexpMethodPointcut`:

4
src/docs/asciidoc/core/core-aop.adoc

@ -1649,7 +1649,7 @@ join point, unless you specify otherwise, the order of execution is undefined. Y @@ -1649,7 +1649,7 @@ join point, unless you specify otherwise, the order of execution is undefined. Y
control the order of execution by specifying precedence. This is done in the normal
Spring way by either implementing the `org.springframework.core.Ordered` interface in
the aspect class or annotating it with the `@Order` annotation. Given two aspects, the
aspect returning the lower value from `Ordered.getValue()` (or the annotation value) has
aspect returning the lower value from `Ordered.getOrder()` (or the annotation value) has
the higher precedence.
[NOTE]
@ -2918,7 +2918,7 @@ an aspect weaving phase to your build script. @@ -2918,7 +2918,7 @@ an aspect weaving phase to your build script.
If you have chosen to use Spring AOP, you have a choice of @AspectJ or XML style.
There are various tradeoffs to consider.
The XML style may most familiar to existing Spring users, and it is backed by genuine
The XML style may be most familiar to existing Spring users, and it is backed by genuine
POJOs. When using AOP as a tool to configure enterprise services, XML can be a good
choice (a good test is whether you consider the pointcut expression to be a part of your
configuration that you might want to change independently). With the XML style, it is

7
src/docs/asciidoc/core/core-beans.adoc

@ -42,7 +42,7 @@ information on using the `BeanFactory` instead of the `ApplicationContext,` see @@ -42,7 +42,7 @@ information on using the `BeanFactory` instead of the `ApplicationContext,` see
In Spring, the objects that form the backbone of your application and that are managed
by the Spring IoC container are called beans. A bean is an object that is
instantiated, assembled, and otherwise managed by a Spring IoC container. Otherwise, a
instantiated, assembled, and managed by a Spring IoC container. Otherwise, a
bean is simply one of many objects in your application. Beans, and the dependencies
among them, are reflected in the configuration metadata used by a container.
@ -2125,7 +2125,7 @@ startup, because it must satisfy the singleton's dependencies. The lazy-initiali @@ -2125,7 +2125,7 @@ startup, because it must satisfy the singleton's dependencies. The lazy-initiali
is injected into a singleton bean elsewhere that is not lazy-initialized.
You can also control lazy-initialization at the container level by using the
`default-lazy-init` attribute on the `<beans/>` element, a the following example shows:
`default-lazy-init` attribute on the `<beans/>` element, as the following example shows:
[source,xml,indent=0,subs="verbatim,quotes"]
----
@ -4429,7 +4429,8 @@ which these `BeanFactoryPostProcessor` instances run by setting the `order` prop @@ -4429,7 +4429,8 @@ which these `BeanFactoryPostProcessor` instances run by setting the `order` prop
However, you can only set this property if the `BeanFactoryPostProcessor` implements the
`Ordered` interface. If you write your own `BeanFactoryPostProcessor`, you should
consider implementing the `Ordered` interface, too. See the javadoc of the
{api-spring-framework}/beans/factory/config/BeanFactoryPostProcessor.html[`BeanFactoryPostProcessor`] and {api-spring-framework}/core/Ordered.html[`Ordered`] interfaces for more details.
{api-spring-framework}/beans/factory/config/BeanFactoryPostProcessor.html[`BeanFactoryPostProcessor`]
and {api-spring-framework}/core/Ordered.html[`Ordered`] interfaces for more details.
[NOTE]
====

Loading…
Cancel
Save