Skip to content

Polishing #3162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
* Default {@link AotContext} implementation.
*
* @author Mark Paluch
* @author Ngoc Nhan
* @since 3.0
*/
class DefaultAotContext implements AotContext {

private final ConfigurableListableBeanFactory factory;

public DefaultAotContext(BeanFactory beanFactory) {
factory = beanFactory instanceof ConfigurableListableBeanFactory ? (ConfigurableListableBeanFactory) beanFactory
factory = beanFactory instanceof ConfigurableListableBeanFactory configurableListableBeanFactory ? configurableListableBeanFactory
: new DefaultListableBeanFactory(beanFactory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* @author Oliver Gierke
* @author Mark Paluch
* @author Johannes Englmeier
* @author Ngoc Nhan
* @since 2.0
* @see ConverterBuilder#writing(Class, Class, Function)
* @see ConverterBuilder#reading(Class, Class, Function)
Expand Down Expand Up @@ -93,12 +94,12 @@ private ConvertiblePair invertedPair() {

DefaultConverterBuilder<S, T> withWriting(Optional<Function<? super S, ? extends T>> writing) {
return this.writing == writing ? this
: new DefaultConverterBuilder<S, T>(this.convertiblePair, writing, this.reading);
: new DefaultConverterBuilder<>(this.convertiblePair, writing, this.reading);
}

DefaultConverterBuilder<S, T> withReading(Optional<Function<? super T, ? extends S>> reading) {
return this.reading == reading ? this
: new DefaultConverterBuilder<S, T>(this.convertiblePair, this.writing, reading);
: new DefaultConverterBuilder<>(this.convertiblePair, this.writing, reading);
}

private static class ConfigurableGenericConverter<S, T> implements GenericConverter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @author Thomas Darimont
* @author Christoph Strobl
* @author Mark Paluch
* @author Ngoc Nhan
*/
public class DefaultTypeMapper<S> implements TypeMapper<S>, BeanClassLoaderAware {

Expand Down Expand Up @@ -199,8 +200,8 @@ public void writeType(TypeInformation<?> info, S sink) {
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
for (TypeInformationMapper mapper : mappers) {
if (mapper instanceof BeanClassLoaderAware) {
((BeanClassLoaderAware) mapper).setBeanClassLoader(classLoader);
if (mapper instanceof BeanClassLoaderAware beanClassLoaderAware) {
beanClassLoaderAware.setBeanClassLoader(classLoader);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/springframework/data/domain/SliceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*
* @author Oliver Gierke
* @author Keegan Witt
* @author Ngoc Nhan
* @since 1.8
*/
public class SliceImpl<T> extends Chunk<T> {
Expand Down Expand Up @@ -74,7 +75,7 @@ public String toString() {
String contentType = "UNKNOWN";
List<T> content = getContent();

if (content.size() > 0) {
if (!content.isEmpty()) {
contentType = content.get(0).getClass().getName();
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/springframework/data/domain/Sort.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* @author Mark Paluch
* @author Johannes Englmeier
* @author Jan Kurella
* @author Ngoc Nhan
*/
public class Sort implements Streamable<org.springframework.data.domain.Sort.Order>, Serializable {

Expand Down Expand Up @@ -204,7 +205,7 @@ public Sort and(Sort sort) {

Assert.notNull(sort, "Sort must not be null");

List<Order> these = new ArrayList<Order>(this.toList());
List<Order> these = new ArrayList<>(this.toList());

for (Order order : sort) {
these.add(order);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @author Jens Schauder
* @author Mark Paluch
* @author Johannes Englmeier
* @author Ngoc Nhan
*/
public class AnnotationRevisionMetadata<N extends Number & Comparable<N>> implements RevisionMetadata<N> {

Expand Down Expand Up @@ -120,20 +121,20 @@ private static <T> Lazy<Optional<T>> detectAnnotation(Object entity, Class<? ext

private static Instant convertToInstant(Object timestamp) {

if (timestamp instanceof Instant) {
return (Instant) timestamp;
if (timestamp instanceof Instant instant) {
return instant;
}

if (timestamp instanceof LocalDateTime) {
return ((LocalDateTime) timestamp).atZone(ZoneOffset.systemDefault()).toInstant();
if (timestamp instanceof LocalDateTime localDateTime) {
return localDateTime.atZone(ZoneOffset.systemDefault()).toInstant();
}

if (timestamp instanceof Long) {
return Instant.ofEpochMilli((Long) timestamp);
if (timestamp instanceof Long milli) {
return Instant.ofEpochMilli(milli);
}

if (timestamp instanceof Date) {
return ((Date) timestamp).toInstant();
if (timestamp instanceof Date date) {
return date.toInstant();
}

throw new IllegalArgumentException(String.format("Can't convert %s to Instant", timestamp));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* propagation settings for how to handle intermediate collection and map values when setting values.
*
* @author Oliver Drotbohm
* @author Ngoc Nhan
* @since 2.3
*/
public class AccessOptions {
Expand Down Expand Up @@ -186,7 +187,7 @@ public <T> GetOptions registerHandler(PersistentProperty<?> property, Class<T> t
Assert.isTrue(type.isAssignableFrom(property.getType()), () -> String
.format("Cannot register a property handler for %s on a property of type %s", type, property.getType()));

Function<Object, T> caster = (Function<Object, T>) it -> type.cast(it);
Function<Object, T> caster = type::cast;

return registerHandler(property, caster.andThen(handler));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* @author Mark Paluch
* @author Mariusz Mączkowski
* @author Johannes Englmeier
* @author Ngoc Nhan
*/
public class PropertyPath implements Streamable<PropertyPath> {

Expand Down Expand Up @@ -377,7 +378,7 @@ public static PropertyPath from(String source, TypeInformation<?> type) {
Iterator<String> parts = iteratorSource.iterator();

PropertyPath result = null;
Stack<PropertyPath> current = new Stack<PropertyPath>();
Stack<PropertyPath> current = new Stack<>();

while (parts.hasNext()) {
if (result == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*
* @author Oliver Gierke
* @author Christoph Strobl
* @author Ngoc Nhan
*/
class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements PersistentPropertyPath<P> {

Expand Down Expand Up @@ -135,15 +136,15 @@ public String toPath(String delimiter, Converter<? super P, String> converter) {
@Override
public P getLeafProperty() {

Assert.state(properties.size() > 0, "Empty PersistentPropertyPath should not exist");
Assert.state(!properties.isEmpty(), "Empty PersistentPropertyPath should not exist");

return properties.get(properties.size() - 1);
}

@Override
public P getBaseProperty() {

Assert.state(properties.size() > 0, "Empty PersistentPropertyPath should not exist");
Assert.state(!properties.isEmpty(), "Empty PersistentPropertyPath should not exist");

return properties.get(0);
}
Expand Down Expand Up @@ -208,9 +209,8 @@ public Iterator<P> iterator() {
*/
public boolean containsPropertyOfType(@Nullable TypeInformation<?> type) {

return type == null //
? false //
: properties.stream() //
return type != null //
&& properties.stream() //
.anyMatch(property -> type.equals(property.getTypeInformation().getActualType()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @author Oliver Gierke
* @author Mark Paluch
* @author Johannes Englmeier
* @author Ngoc Nhan
* @soundtrack Scary Pockets - Crash Into Me (Dave Matthews Band Cover feat. Julia Nunes) -
* https://www.youtube.com/watch?v=syGlBNVGEqU
*/
Expand Down Expand Up @@ -100,8 +101,8 @@ public boolean isNew(Object entity) {
return false;
}

if (value instanceof Number) {
return ((Number) value).longValue() == 0;
if (value instanceof Number number) {
return number.longValue() == 0;
}

throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @author Oliver Gierke
* @author Christoph Strobl
* @author Mark Paluch
* @author Ngoc Nhan
*/
public class Property {

Expand Down Expand Up @@ -264,7 +265,7 @@ private <T> T withFieldOrDescriptor(Function<? super Field, T> field,

private static Optional<Method> findWither(TypeInformation<?> owner, String propertyName, Class<?> rawType) {

AtomicReference<Method> resultHolder = new AtomicReference<Method>();
AtomicReference<Method> resultHolder = new AtomicReference<>();
String methodName = String.format("with%s", StringUtils.capitalize(propertyName));

ReflectionUtils.doWithMethods(owner.getType(), it -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
*
* @author Oliver Gierke
* @author Johannes Englmeier
* @author Ngoc Nhan
* @since 2.3
* @soundtrack Ron Spielman - Nineth Song (Tip of My Tongue)
*/
Expand Down Expand Up @@ -167,7 +168,7 @@ public void setProperty(PersistentPropertyPath<? extends PersistentProperty<?>>
.map(it -> setValue(it, leafProperty, value)) //
.collect(Collectors.toCollection(() -> CollectionFactory.createApproximateCollection(source, source.size())));

} else if (Map.class.isInstance(parent)) {
} else if (parent instanceof Map) {

Map<Object, Object> source = getTypedProperty(parentProperty, Map.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* @author Christoph Strobl
* @author Mark Paluch
* @author Jens Schauder
* @author Ngoc Nhan
* @see SpelAwareProxyProjectionFactory
* @since 1.10
*/
Expand Down Expand Up @@ -261,7 +262,7 @@ public MethodInterceptor createMethodInterceptor(Object source, Class<?> targetT

@Override
public boolean supports(Object source, Class<?> targetType) {
return Map.class.isInstance(source);
return source instanceof Map;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* @author Thomas Darimont
* @author Mark Paluch
* @author Jens Schauder
* @author Ngoc Nhan
* @since 1.10
*/
public class SpelAwareProxyProjectionFactory extends ProxyProjectionFactory implements BeanFactoryAware {
Expand Down Expand Up @@ -108,7 +109,7 @@ private static boolean hasMethodWithValueAnnotation(Class<?> type) {

Assert.notNull(type, "Type must not be null");

AnnotationDetectionMethodCallback<Value> callback = new AnnotationDetectionMethodCallback<Value>(Value.class);
AnnotationDetectionMethodCallback<Value> callback = new AnnotationDetectionMethodCallback<>(Value.class);
ReflectionUtils.doWithMethods(type, callback);

return callback.hasFoundAnnotation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* @author Oliver Gierke
* @author Colin Gao
* @author Johannes Englmeier
* @author Ngoc Nhan
* @since 1.11
*/
class QuerydslDefaultBinding implements MultiValueBinding<Path<? extends Object>, Object> {
Expand All @@ -54,7 +55,7 @@ public Optional<Predicate> bind(Path<?> path, Collection<? extends Object> value
return Optional.empty();
}

if (path instanceof CollectionPathBase) {
if (path instanceof CollectionPathBase collectionPathBase) {

BooleanBuilder builder = new BooleanBuilder();

Expand All @@ -63,10 +64,10 @@ public Optional<Predicate> bind(Path<?> path, Collection<? extends Object> value
if (element instanceof Collection<?> nestedCollection) {

for (Object nested : nestedCollection) {
builder.and(((CollectionPathBase) path).contains(nested));
builder.and(collectionPathBase.contains(nested));
}
} else {
builder.and(((CollectionPathBase) path).contains(element));
builder.and(collectionPathBase.contains(element));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @author Jens Schauder
* @author Mark Paluch
* @author Johannes Englmeier
* @author Ngoc Nhan
*/
class RepositoryBeanNameGenerator {

Expand Down Expand Up @@ -70,8 +71,8 @@ public RepositoryBeanNameGenerator(ClassLoader beanClassLoader, BeanNameGenerato
*/
public String generateBeanName(BeanDefinition definition) {

AnnotatedBeanDefinition beanDefinition = definition instanceof AnnotatedBeanDefinition //
? (AnnotatedBeanDefinition) definition //
AnnotatedBeanDefinition beanDefinition = definition instanceof AnnotatedBeanDefinition annotatedBeanDefinition //
? annotatedBeanDefinition //
: new AnnotatedGenericBeanDefinition(getRepositoryInterfaceFrom(definition));

return generator.generateBeanName(beanDefinition, registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public Set<BeanDefinition> findCandidateComponents(String basePackage) {
Set<BeanDefinition> candidates = super.findCandidateComponents(basePackage);

for (BeanDefinition candidate : candidates) {
if (candidate instanceof AnnotatedBeanDefinition) {
AnnotationConfigUtils.processCommonDefinitionAnnotations((AnnotatedBeanDefinition) candidate);
if (candidate instanceof AnnotatedBeanDefinition annotatedBeanDefinition) {
AnnotationConfigUtils.processCommonDefinitionAnnotations(annotatedBeanDefinition);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static Environment defaultEnvironment(@Nullable Environment environment,
return environment;
}

return resourceLoader instanceof EnvironmentCapable ? ((EnvironmentCapable) resourceLoader).getEnvironment()
return resourceLoader instanceof EnvironmentCapable environmentCapable ? environmentCapable.getEnvironment()
: new StandardEnvironment();
}

Expand Down Expand Up @@ -248,11 +248,10 @@ private void registerAotComponents(BeanDefinitionRegistry registry, RepositoryCo
private static void potentiallyLazifyRepositories(Map<String, RepositoryConfiguration<?>> configurations,
BeanDefinitionRegistry registry, BootstrapMode mode) {

if (!DefaultListableBeanFactory.class.isInstance(registry) || BootstrapMode.DEFAULT.equals(mode)) {
if (!(registry instanceof DefaultListableBeanFactory beanFactory) || BootstrapMode.DEFAULT.equals(mode)) {
return;
}

DefaultListableBeanFactory beanFactory = DefaultListableBeanFactory.class.cast(registry);
AutowireCandidateResolver resolver = beanFactory.getAutowireCandidateResolver();

if (!Arrays.asList(ContextAnnotationAutowireCandidateResolver.class, LazyRepositoryInjectionPointResolver.class)
Expand All @@ -263,8 +262,8 @@ private static void potentiallyLazifyRepositories(Map<String, RepositoryConfigur
return;
}

AutowireCandidateResolver newResolver = LazyRepositoryInjectionPointResolver.class.isInstance(resolver) //
? LazyRepositoryInjectionPointResolver.class.cast(resolver).withAdditionalConfigurations(configurations) //
AutowireCandidateResolver newResolver = resolver instanceof LazyRepositoryInjectionPointResolver lazyRepositoryInjectionPointResolver //
? lazyRepositoryInjectionPointResolver.withAdditionalConfigurations(configurations) //
: new LazyRepositoryInjectionPointResolver(configurations);

beanFactory.setAutowireCandidateResolver(newResolver);
Expand Down Expand Up @@ -300,12 +299,12 @@ private boolean multipleStoresDetected() {

private static ApplicationStartup getStartup(BeanDefinitionRegistry registry) {

if (registry instanceof ConfigurableBeanFactory) {
return ((ConfigurableBeanFactory) registry).getApplicationStartup();
if (registry instanceof ConfigurableBeanFactory configurableBeanFactory) {
return configurableBeanFactory.getApplicationStartup();
}

if (registry instanceof GenericApplicationContext) {
return ((GenericApplicationContext) registry).getDefaultListableBeanFactory().getApplicationStartup();
if (registry instanceof GenericApplicationContext genericApplicationContext) {
return genericApplicationContext.getDefaultListableBeanFactory().getApplicationStartup();
}

return ApplicationStartup.DEFAULT;
Expand Down
Loading