Polishing.

Pattern matching usage.
Diamond operator usage.
Remove unused import.
isEmpty usage.

Original pull request #1912
This commit is contained in:
Tran Ngoc Nhan
2024-10-12 02:05:10 +07:00
committed by Jens Schauder
parent a8463e0ca6
commit f2d62ad7e7
17 changed files with 17 additions and 36 deletions

View File

@@ -41,12 +41,12 @@ class IterableOfEntryToMapConverter implements ConditionalConverter, Converter<I
source.forEach(element -> {
if (!(element instanceof Entry)) {
throw new IllegalArgumentException(String.format("Cannot convert %s to Map.Entry", element.getClass()));
if (element instanceof Entry entry) {
result.put(entry.getKey(), entry.getValue());
return;
}
Entry entry = (Entry) element;
result.put(entry.getKey(), entry.getValue());
throw new IllegalArgumentException(String.format("Cannot convert %s to Map.Entry", element.getClass()));
});
return result;

View File

@@ -20,7 +20,6 @@ import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

View File

@@ -16,7 +16,6 @@
package org.springframework.data.jdbc.core.convert;
import org.springframework.data.relational.core.mapping.AggregatePath;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**

View File

@@ -296,7 +296,7 @@ public class QueryMapper {
&& metadataBackedField.property != null //
&& (criteria.getValue() == null || !criteria.getValue().getClass().isArray())) {
RelationalPersistentProperty property = ((MetadataBackedField) propertyField).property;
RelationalPersistentProperty property = metadataBackedField.property;
JdbcValue jdbcValue = convertToJdbcValue(property, criteria.getValue());
mappedValue = jdbcValue.getValue();
sqlType = jdbcValue.getJdbcType() != null ? jdbcValue.getJdbcType() : propertyField.getSqlType();

View File

@@ -20,7 +20,6 @@ import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.relational.core.mapping.BasicRelationalPersistentProperty;
import org.springframework.data.relational.core.mapping.NamingStrategy;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
/**

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.jdbc.core.mapping;
import org.springframework.data.mapping.InstanceCreatorMetadata;
import org.springframework.data.mapping.Parameter;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.SimpleTypeHolder;
@@ -25,8 +23,6 @@ import org.springframework.data.relational.core.mapping.RelationalMappingContext
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* {@link MappingContext} implementation for JDBC.

View File

@@ -31,7 +31,6 @@ import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.FluentQuery;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.data.util.Streamable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

View File

@@ -172,8 +172,7 @@ class DefaultStatementMapper implements StatementMapper {
for (Assignment assignment : boundAssignments.getAssignments()) {
if (assignment instanceof AssignValue) {
AssignValue assignValue = (AssignValue) assignment;
if (assignment instanceof AssignValue assignValue) {
insertBuilder.column(assignValue.getColumn());
withBuild = insertBuilder.value(assignValue.getValue());

View File

@@ -54,7 +54,7 @@ class NamedParameterExpander {
/**
* Cache of original SQL String to ParsedSql representation.
*/
@SuppressWarnings("serial") private final Map<String, ParsedSql> parsedSqlCache = new LinkedHashMap<String, ParsedSql>(
@SuppressWarnings("serial") private final Map<String, ParsedSql> parsedSqlCache = new LinkedHashMap<>(
DEFAULT_CACHE_LIMIT, 0.75f, true) {
@Override
protected boolean removeEldestEntry(Map.Entry<String, ParsedSql> eldest) {

View File

@@ -384,11 +384,11 @@ abstract class NamedParameterUtils {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (!(o instanceof ParameterHolder))
return false;
ParameterHolder that = (ParameterHolder) o;
return this.startIndex == that.startIndex && this.endIndex == that.endIndex
if (o instanceof ParameterHolder that) {
return this.startIndex == that.startIndex && this.endIndex == that.endIndex
&& Objects.equals(this.parameterName, that.parameterName);
}
return false;
}
@Override

View File

@@ -209,7 +209,7 @@ public interface DbAction<T> {
* Note that deletes for contained entities that reference the root are to be represented by separate
* {@link DbAction}s.
* </p>
*
*
* @param <T> type of the entity for which this represents a database interaction.
*/
final class DeleteRoot<T> implements DbAction<T> {
@@ -274,7 +274,7 @@ public interface DbAction<T> {
* Note that deletes for contained entities that reference the root are to be represented by separate
* {@link DbAction}s.
* </p>
*
*
* @param <T> type of the entity for which this represents a database interaction.
*/
final class DeleteAllRoot<T> implements DbAction<T> {
@@ -467,7 +467,7 @@ public interface DbAction<T> {
* <p>
* Values come from parent entities but one might also add values manually.
* </p>
*
*
* @return guaranteed to be not {@code null}.
*/
Map<PersistentPropertyPath<RelationalPersistentProperty>, Object> getQualifiers();
@@ -479,7 +479,7 @@ public interface DbAction<T> {
default Pair<PersistentPropertyPath<RelationalPersistentProperty>, Object> getQualifier() {
Map<PersistentPropertyPath<RelationalPersistentProperty>, Object> qualifiers = getQualifiers();
if (qualifiers.size() == 0)
if (qualifiers.isEmpty())
return null;
if (qualifiers.size() > 1) {

View File

@@ -17,7 +17,6 @@ package org.springframework.data.relational.core.dialect;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.springframework.data.relational.core.sql.IdentifierProcessing;

View File

@@ -23,9 +23,6 @@ package org.springframework.data.relational.core.mapping;
*/
record EmbeddedContext(RelationalPersistentProperty ownerProperty) {
EmbeddedContext {
}
public String getEmbeddedPrefix() {
return ownerProperty.getEmbeddedPrefix();
}

View File

@@ -17,7 +17,6 @@ package org.springframework.data.relational.core.mapping;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.relational.core.mapping.event;
import org.springframework.data.relational.core.conversion.AggregateChange;
import java.io.Serial;
/**
@@ -37,7 +35,7 @@ import java.io.Serial;
* <li>SQL statements get applied to the database.</li>
* <li>{@link AfterSaveCallback} and {@link AfterSaveEvent} get published.</li>
* </ol>
*
*
* @since 1.1
* @author Jens Schauder
* @author Mark Paluch

View File

@@ -101,9 +101,7 @@ class SelectStatementVisitor extends DelegatingVisitor implements PartRenderer {
@Override
public Delegation doLeave(Visitable segment) {
if (segment instanceof Select) {
Select select = (Select) segment;
if (segment instanceof Select select) {
builder.append("SELECT ");

View File

@@ -23,7 +23,6 @@ import org.springframework.data.relational.core.query.Criteria;
import org.springframework.data.relational.core.sql.Expression;
import org.springframework.data.repository.query.parser.Part;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
/**