Skip to content

Commit f2d62ad

Browse files
ngocnhan-tran1996schauder
authored andcommitted
Polishing.
Pattern matching usage. Diamond operator usage. Remove unused import. isEmpty usage. Original pull request #1912
1 parent a8463e0 commit f2d62ad

File tree

17 files changed

+17
-36
lines changed

17 files changed

+17
-36
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/IterableOfEntryToMapConverter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ class IterableOfEntryToMapConverter implements ConditionalConverter, Converter<I
4141

4242
source.forEach(element -> {
4343

44-
if (!(element instanceof Entry)) {
45-
throw new IllegalArgumentException(String.format("Cannot convert %s to Map.Entry", element.getClass()));
44+
if (element instanceof Entry entry) {
45+
result.put(entry.getKey(), entry.getValue());
46+
return;
4647
}
4748

48-
Entry entry = (Entry) element;
49-
result.put(entry.getKey(), entry.getValue());
49+
throw new IllegalArgumentException(String.format("Cannot convert %s to Map.Entry", element.getClass()));
5050
});
5151

5252
return result;

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcColumnTypes.java

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.time.OffsetDateTime;
2121
import java.time.ZonedDateTime;
2222
import java.time.temporal.Temporal;
23-
import java.util.Date;
2423
import java.util.LinkedHashMap;
2524
import java.util.Map;
2625

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcIdentifierBuilder.java

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.jdbc.core.convert;
1717

1818
import org.springframework.data.relational.core.mapping.AggregatePath;
19-
import org.springframework.lang.Nullable;
2019
import org.springframework.util.Assert;
2120

2221
/**

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/QueryMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ private Condition mapCondition(CriteriaDefinition criteria, MapSqlParameterSourc
296296
&& metadataBackedField.property != null //
297297
&& (criteria.getValue() == null || !criteria.getValue().getClass().isArray())) {
298298

299-
RelationalPersistentProperty property = ((MetadataBackedField) propertyField).property;
299+
RelationalPersistentProperty property = metadataBackedField.property;
300300
JdbcValue jdbcValue = convertToJdbcValue(property, criteria.getValue());
301301
mappedValue = jdbcValue.getValue();
302302
sqlType = jdbcValue.getJdbcType() != null ? jdbcValue.getJdbcType() : propertyField.getSqlType();

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/BasicJdbcPersistentProperty.java

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.springframework.data.mapping.model.SimpleTypeHolder;
2121
import org.springframework.data.relational.core.mapping.BasicRelationalPersistentProperty;
2222
import org.springframework.data.relational.core.mapping.NamingStrategy;
23-
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
2423
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
2524

2625
/**

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/JdbcMappingContext.java

-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.data.jdbc.core.mapping;
1717

18-
import org.springframework.data.mapping.InstanceCreatorMetadata;
19-
import org.springframework.data.mapping.Parameter;
2018
import org.springframework.data.mapping.context.MappingContext;
2119
import org.springframework.data.mapping.model.Property;
2220
import org.springframework.data.mapping.model.SimpleTypeHolder;
@@ -25,8 +23,6 @@
2523
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
2624
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
2725
import org.springframework.data.util.TypeInformation;
28-
import org.springframework.util.Assert;
29-
import org.springframework.util.StringUtils;
3026

3127
/**
3228
* {@link MappingContext} implementation for JDBC.

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.springframework.data.repository.PagingAndSortingRepository;
3232
import org.springframework.data.repository.query.FluentQuery;
3333
import org.springframework.data.repository.query.QueryByExampleExecutor;
34-
import org.springframework.data.util.Streamable;
3534
import org.springframework.transaction.annotation.Transactional;
3635
import org.springframework.util.Assert;
3736

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/DefaultStatementMapper.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ private PreparedOperation<Insert> getMappedObject(InsertSpec insertSpec,
172172

173173
for (Assignment assignment : boundAssignments.getAssignments()) {
174174

175-
if (assignment instanceof AssignValue) {
176-
AssignValue assignValue = (AssignValue) assignment;
175+
if (assignment instanceof AssignValue assignValue) {
177176

178177
insertBuilder.column(assignValue.getColumn());
179178
withBuild = insertBuilder.value(assignValue.getValue());

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/NamedParameterExpander.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class NamedParameterExpander {
5454
/**
5555
* Cache of original SQL String to ParsedSql representation.
5656
*/
57-
@SuppressWarnings("serial") private final Map<String, ParsedSql> parsedSqlCache = new LinkedHashMap<String, ParsedSql>(
57+
@SuppressWarnings("serial") private final Map<String, ParsedSql> parsedSqlCache = new LinkedHashMap<>(
5858
DEFAULT_CACHE_LIMIT, 0.75f, true) {
5959
@Override
6060
protected boolean removeEldestEntry(Map.Entry<String, ParsedSql> eldest) {

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/NamedParameterUtils.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@ int getEndIndex() {
384384
public boolean equals(@Nullable Object o) {
385385
if (this == o)
386386
return true;
387-
if (!(o instanceof ParameterHolder))
388-
return false;
389-
ParameterHolder that = (ParameterHolder) o;
390-
return this.startIndex == that.startIndex && this.endIndex == that.endIndex
387+
if (o instanceof ParameterHolder that) {
388+
return this.startIndex == that.startIndex && this.endIndex == that.endIndex
391389
&& Objects.equals(this.parameterName, that.parameterName);
390+
}
391+
return false;
392392
}
393393

394394
@Override

spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/DbAction.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public String toString() {
209209
* Note that deletes for contained entities that reference the root are to be represented by separate
210210
* {@link DbAction}s.
211211
* </p>
212-
*
212+
*
213213
* @param <T> type of the entity for which this represents a database interaction.
214214
*/
215215
final class DeleteRoot<T> implements DbAction<T> {
@@ -274,7 +274,7 @@ public String toString() {
274274
* Note that deletes for contained entities that reference the root are to be represented by separate
275275
* {@link DbAction}s.
276276
* </p>
277-
*
277+
*
278278
* @param <T> type of the entity for which this represents a database interaction.
279279
*/
280280
final class DeleteAllRoot<T> implements DbAction<T> {
@@ -467,7 +467,7 @@ interface WithDependingOn<T> extends WithPropertyPath<T>, WithEntity<T> {
467467
* <p>
468468
* Values come from parent entities but one might also add values manually.
469469
* </p>
470-
*
470+
*
471471
* @return guaranteed to be not {@code null}.
472472
*/
473473
Map<PersistentPropertyPath<RelationalPersistentProperty>, Object> getQualifiers();
@@ -479,7 +479,7 @@ interface WithDependingOn<T> extends WithPropertyPath<T>, WithEntity<T> {
479479
default Pair<PersistentPropertyPath<RelationalPersistentProperty>, Object> getQualifier() {
480480

481481
Map<PersistentPropertyPath<RelationalPersistentProperty>, Object> qualifiers = getQualifiers();
482-
if (qualifiers.size() == 0)
482+
if (qualifiers.isEmpty())
483483
return null;
484484

485485
if (qualifiers.size() > 1) {

spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/MariaDbDialect.java

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.util.Arrays;
1919
import java.util.Collection;
20-
import java.util.Collections;
2120

2221
import org.springframework.data.relational.core.sql.IdentifierProcessing;
2322

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/EmbeddedContext.java

-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
*/
2424
record EmbeddedContext(RelationalPersistentProperty ownerProperty) {
2525

26-
EmbeddedContext {
27-
}
28-
2926
public String getEmbeddedPrefix() {
3027
return ownerProperty.getEmbeddedPrefix();
3128
}

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/InsertOnlyProperty.java

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.lang.annotation.Documented;
1919
import java.lang.annotation.ElementType;
20-
import java.lang.annotation.Inherited;
2120
import java.lang.annotation.Retention;
2221
import java.lang.annotation.RetentionPolicy;
2322
import java.lang.annotation.Target;

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/event/BeforeConvertEvent.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.data.relational.core.mapping.event;
1717

18-
import org.springframework.data.relational.core.conversion.AggregateChange;
19-
2018
import java.io.Serial;
2119

2220
/**
@@ -37,7 +35,7 @@
3735
* <li>SQL statements get applied to the database.</li>
3836
* <li>{@link AfterSaveCallback} and {@link AfterSaveEvent} get published.</li>
3937
* </ol>
40-
*
38+
*
4139
* @since 1.1
4240
* @author Jens Schauder
4341
* @author Mark Paluch

spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/SelectStatementVisitor.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ public Delegation doEnter(Visitable segment) {
101101
@Override
102102
public Delegation doLeave(Visitable segment) {
103103

104-
if (segment instanceof Select) {
105-
106-
Select select = (Select) segment;
104+
if (segment instanceof Select select) {
107105

108106
builder.append("SELECT ");
109107

spring-data-relational/src/main/java/org/springframework/data/relational/repository/query/CriteriaFactory.java

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.springframework.data.relational.core.sql.Expression;
2424
import org.springframework.data.repository.query.parser.Part;
2525
import org.springframework.util.Assert;
26-
import org.springframework.util.CollectionUtils;
2726
import org.springframework.util.ObjectUtils;
2827

2928
/**

0 commit comments

Comments
 (0)