Polishing

(cherry picked from commit 40efcc9)
This commit is contained in:
Juergen Hoeller
2018-06-28 14:51:31 +02:00
parent 3e64388b20
commit a631af80c1
113 changed files with 648 additions and 693 deletions

View File

@@ -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

View File

@@ -64,9 +64,9 @@ public abstract class ParameterizedTypeReference<T> {
}
@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

View File

@@ -164,12 +164,10 @@ public class ReactiveAdapterRegistry {
/**
* Return a shared default {@code ReactiveAdapterRegistry} instance, lazily
* building it once needed.
*
* <p><b>NOTE:</b> 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";

View File

@@ -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.
@@ -62,14 +62,12 @@ abstract class ConversionUtils {
// yes
return true;
}
else if (sourceElementType.getType().isAssignableFrom(targetElementType.getType())) {
if (sourceElementType.getType().isAssignableFrom(targetElementType.getType())) {
// maybe
return true;
}
else {
// no
return false;
}
// no
return false;
}
public static Class<?> getEnumType(Class<?> targetType) {

View File

@@ -131,9 +131,9 @@ public abstract class PropertySource<T> {
* <p>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)));
}
/**

View File

@@ -209,23 +209,14 @@ public abstract class AbstractResource implements Resource {
}
/**
* This implementation returns the description of this resource.
* @see #getDescription()
*/
@Override
public String toString() {
return getDescription();
}
/**
* This implementation compares description strings.
* @see #getDescription()
*/
@Override
public boolean equals(Object obj) {
return (obj == this ||
(obj instanceof Resource && ((Resource) obj).getDescription().equals(getDescription())));
public boolean equals(Object other) {
return (this == other || (other instanceof Resource &&
((Resource) other).getDescription().equals(getDescription())));
}
/**
@@ -237,4 +228,13 @@ public abstract class AbstractResource implements Resource {
return getDescription().hashCode();
}
/**
* This implementation returns the description of this resource.
* @see #getDescription()
*/
@Override
public String toString() {
return getDescription();
}
}

View File

@@ -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)));
}
/**

View File

@@ -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));
}
/**

View File

@@ -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)));
}
/**

View File

@@ -250,9 +250,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)));
}
/**

View File

@@ -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)));
}
/**

View File

@@ -268,9 +268,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)));
}
/**

View File

@@ -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)));
}
/**

View File

@@ -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

View File

@@ -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.
* <p>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);

View File

@@ -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}.
*
* <p>Inspired by Netty's {@code ByteBuf}. Introduced so that non-Netty runtimes (i.e. Servlet)
* do not require Netty on the classpath.
* <p>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;
@@ -413,17 +410,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
@@ -433,10 +430,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);
@@ -451,6 +449,7 @@ public class DefaultDataBuffer implements DataBuffer {
}
}
private class DefaultDataBufferInputStream extends InputStream {
@Override
@@ -478,7 +477,6 @@ public class DefaultDataBuffer implements DataBuffer {
}
private class DefaultDataBufferOutputStream extends OutputStream {
@Override
@@ -495,16 +493,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");
}
}

View File

@@ -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

View File

@@ -833,12 +833,12 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> 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<K, V> reference = ConcurrentReferenceHashMap.this.getReference(entry.getKey(), Restructure.NEVER);
Entry<K, V> other = (reference != null ? reference.get() : null);
if (other != null) {
return ObjectUtils.nullSafeEquals(entry.getValue(), other.getValue());
Entry<K, V> otherEntry = (reference != null ? reference.get() : null);
if (otherEntry != null) {
return ObjectUtils.nullSafeEquals(otherEntry.getValue(), otherEntry.getValue());
}
}
return false;

View File

@@ -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<Boolean>, 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

View File

@@ -186,15 +186,9 @@ public class CompoundComparator<T> implements Comparator<T>, Serializable {
@Override
@SuppressWarnings("unchecked")
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof CompoundComparator)) {
return false;
}
CompoundComparator<T> other = (CompoundComparator<T>) obj;
return this.comparators.equals(other.comparators);
public boolean equals(Object other) {
return (this == other || (other instanceof CompoundComparator &&
this.comparators.equals(((CompoundComparator<T>) other).comparators)));
}
@Override

View File

@@ -107,15 +107,15 @@ public class InvertibleComparator<T> implements Comparator<T>, 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<T> other = (InvertibleComparator<T>) obj;
return (this.comparator.equals(other.comparator) && this.ascending == other.ascending);
InvertibleComparator<T> otherComp = (InvertibleComparator<T>) other;
return (this.comparator.equals(otherComp.comparator) && this.ascending == otherComp.ascending);
}
@Override

View File

@@ -107,15 +107,15 @@ public class NullSafeComparator<T> implements Comparator<T> {
@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<T> other = (NullSafeComparator<T>) obj;
return (this.nonNullComparator.equals(other.nonNullComparator) && this.nullsLow == other.nullsLow);
NullSafeComparator<T> otherComp = (NullSafeComparator<T>) other;
return (this.nonNullComparator.equals(otherComp.nonNullComparator) && this.nullsLow == otherComp.nullsLow);
}
@Override