Skip to content

Commit 374bddb

Browse files
polish
1 parent f305308 commit 374bddb

39 files changed

+131
-98
lines changed

src/main/java/org/springframework/data/aot/DefaultAotContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
* Default {@link AotContext} implementation.
3333
*
3434
* @author Mark Paluch
35+
* @author Ngoc Nhan
3536
* @since 3.0
3637
*/
3738
class DefaultAotContext implements AotContext {
3839

3940
private final ConfigurableListableBeanFactory factory;
4041

4142
public DefaultAotContext(BeanFactory beanFactory) {
42-
factory = beanFactory instanceof ConfigurableListableBeanFactory ? (ConfigurableListableBeanFactory) beanFactory
43+
factory = beanFactory instanceof ConfigurableListableBeanFactory configurableListableBeanFactory ? configurableListableBeanFactory
4344
: new DefaultListableBeanFactory(beanFactory);
4445
}
4546

src/main/java/org/springframework/data/convert/DefaultConverterBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* @author Oliver Gierke
4040
* @author Mark Paluch
4141
* @author Johannes Englmeier
42+
* @author Ngoc Nhan
4243
* @since 2.0
4344
* @see ConverterBuilder#writing(Class, Class, Function)
4445
* @see ConverterBuilder#reading(Class, Class, Function)
@@ -93,12 +94,12 @@ private ConvertiblePair invertedPair() {
9394

9495
DefaultConverterBuilder<S, T> withWriting(Optional<Function<? super S, ? extends T>> writing) {
9596
return this.writing == writing ? this
96-
: new DefaultConverterBuilder<S, T>(this.convertiblePair, writing, this.reading);
97+
: new DefaultConverterBuilder<>(this.convertiblePair, writing, this.reading);
9798
}
9899

99100
DefaultConverterBuilder<S, T> withReading(Optional<Function<? super T, ? extends S>> reading) {
100101
return this.reading == reading ? this
101-
: new DefaultConverterBuilder<S, T>(this.convertiblePair, this.writing, reading);
102+
: new DefaultConverterBuilder<>(this.convertiblePair, this.writing, reading);
102103
}
103104

104105
private static class ConfigurableGenericConverter<S, T> implements GenericConverter {

src/main/java/org/springframework/data/convert/DefaultTypeMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @author Thomas Darimont
3939
* @author Christoph Strobl
4040
* @author Mark Paluch
41+
* @author Ngoc Nhan
4142
*/
4243
public class DefaultTypeMapper<S> implements TypeMapper<S>, BeanClassLoaderAware {
4344

@@ -199,8 +200,8 @@ public void writeType(TypeInformation<?> info, S sink) {
199200
@Override
200201
public void setBeanClassLoader(ClassLoader classLoader) {
201202
for (TypeInformationMapper mapper : mappers) {
202-
if (mapper instanceof BeanClassLoaderAware) {
203-
((BeanClassLoaderAware) mapper).setBeanClassLoader(classLoader);
203+
if (mapper instanceof BeanClassLoaderAware beanClassLoaderAware) {
204+
beanClassLoaderAware.setBeanClassLoader(classLoader);
204205
}
205206
}
206207
}

src/main/java/org/springframework/data/domain/SliceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*
2626
* @author Oliver Gierke
2727
* @author Keegan Witt
28+
* @author Ngoc Nhan
2829
* @since 1.8
2930
*/
3031
public class SliceImpl<T> extends Chunk<T> {
@@ -74,7 +75,7 @@ public String toString() {
7475
String contentType = "UNKNOWN";
7576
List<T> content = getContent();
7677

77-
if (content.size() > 0) {
78+
if (!content.isEmpty()) {
7879
contentType = content.get(0).getClass().getName();
7980
}
8081

src/main/java/org/springframework/data/domain/Sort.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* @author Mark Paluch
4545
* @author Johannes Englmeier
4646
* @author Jan Kurella
47+
* @author Ngoc Nhan
4748
*/
4849
public class Sort implements Streamable<org.springframework.data.domain.Sort.Order>, Serializable {
4950

@@ -204,7 +205,7 @@ public Sort and(Sort sort) {
204205

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

207-
List<Order> these = new ArrayList<Order>(this.toList());
208+
List<Order> these = new ArrayList<>(this.toList());
208209

209210
for (Order order : sort) {
210211
these.add(order);

src/main/java/org/springframework/data/history/AnnotationRevisionMetadata.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* @author Jens Schauder
3838
* @author Mark Paluch
3939
* @author Johannes Englmeier
40+
* @author Ngoc Nhan
4041
*/
4142
public class AnnotationRevisionMetadata<N extends Number & Comparable<N>> implements RevisionMetadata<N> {
4243

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

121122
private static Instant convertToInstant(Object timestamp) {
122123

123-
if (timestamp instanceof Instant) {
124-
return (Instant) timestamp;
124+
if (timestamp instanceof Instant instant) {
125+
return instant;
125126
}
126127

127-
if (timestamp instanceof LocalDateTime) {
128-
return ((LocalDateTime) timestamp).atZone(ZoneOffset.systemDefault()).toInstant();
128+
if (timestamp instanceof LocalDateTime localDateTime) {
129+
return localDateTime.atZone(ZoneOffset.systemDefault()).toInstant();
129130
}
130131

131-
if (timestamp instanceof Long) {
132-
return Instant.ofEpochMilli((Long) timestamp);
132+
if (timestamp instanceof Long milli) {
133+
return Instant.ofEpochMilli(milli);
133134
}
134135

135-
if (timestamp instanceof Date) {
136-
return ((Date) timestamp).toInstant();
136+
if (timestamp instanceof Date date) {
137+
return date.toInstant();
137138
}
138139

139140
throw new IllegalArgumentException(String.format("Can't convert %s to Instant", timestamp));

src/main/java/org/springframework/data/mapping/AccessOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* propagation settings for how to handle intermediate collection and map values when setting values.
3333
*
3434
* @author Oliver Drotbohm
35+
* @author Ngoc Nhan
3536
* @since 2.3
3637
*/
3738
public class AccessOptions {
@@ -186,7 +187,7 @@ public <T> GetOptions registerHandler(PersistentProperty<?> property, Class<T> t
186187
Assert.isTrue(type.isAssignableFrom(property.getType()), () -> String
187188
.format("Cannot register a property handler for %s on a property of type %s", type, property.getType()));
188189

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

191192
return registerHandler(property, caster.andThen(handler));
192193
}

src/main/java/org/springframework/data/mapping/PropertyPath.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* @author Mark Paluch
4242
* @author Mariusz Mączkowski
4343
* @author Johannes Englmeier
44+
* @author Ngoc Nhan
4445
*/
4546
public class PropertyPath implements Streamable<PropertyPath> {
4647

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

379380
PropertyPath result = null;
380-
Stack<PropertyPath> current = new Stack<PropertyPath>();
381+
Stack<PropertyPath> current = new Stack<>();
381382

382383
while (parts.hasNext()) {
383384
if (result == null) {

src/main/java/org/springframework/data/mapping/context/DefaultPersistentPropertyPath.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*
3434
* @author Oliver Gierke
3535
* @author Christoph Strobl
36+
* @author Ngoc Nhan
3637
*/
3738
class DefaultPersistentPropertyPath<P extends PersistentProperty<P>> implements PersistentPropertyPath<P> {
3839

@@ -135,15 +136,15 @@ public String toPath(String delimiter, Converter<? super P, String> converter) {
135136
@Override
136137
public P getLeafProperty() {
137138

138-
Assert.state(properties.size() > 0, "Empty PersistentPropertyPath should not exist");
139+
Assert.state(!properties.isEmpty(), "Empty PersistentPropertyPath should not exist");
139140

140141
return properties.get(properties.size() - 1);
141142
}
142143

143144
@Override
144145
public P getBaseProperty() {
145146

146-
Assert.state(properties.size() > 0, "Empty PersistentPropertyPath should not exist");
147+
Assert.state(!properties.isEmpty(), "Empty PersistentPropertyPath should not exist");
147148

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

211-
return type == null //
212-
? false //
213-
: properties.stream() //
212+
return type != null //
213+
&& properties.stream() //
214214
.anyMatch(property -> type.equals(property.getTypeInformation().getActualType()));
215215
}
216216

src/main/java/org/springframework/data/mapping/model/PersistentEntityIsNewStrategy.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* @author Oliver Gierke
3030
* @author Mark Paluch
3131
* @author Johannes Englmeier
32+
* @author Ngoc Nhan
3233
* @soundtrack Scary Pockets - Crash Into Me (Dave Matthews Band Cover feat. Julia Nunes) -
3334
* https://www.youtube.com/watch?v=syGlBNVGEqU
3435
*/
@@ -100,8 +101,8 @@ public boolean isNew(Object entity) {
100101
return false;
101102
}
102103

103-
if (value instanceof Number) {
104-
return ((Number) value).longValue() == 0;
104+
if (value instanceof Number number) {
105+
return number.longValue() == 0;
105106
}
106107

107108
throw new IllegalArgumentException(

0 commit comments

Comments
 (0)