Skip to content

Commit dc265c1

Browse files
ngocnhan-tran1996mp911de
authored andcommitted
Polishing.
Add missing Override annotations. Use instanceof pattern variables, use diamond operator where possible. Closes #3162
1 parent b84d603 commit dc265c1

File tree

96 files changed

+228
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+228
-62
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DefaultAotContext implements AotContext {
3939
private final ConfigurableListableBeanFactory factory;
4040

4141
public DefaultAotContext(BeanFactory beanFactory) {
42-
factory = beanFactory instanceof ConfigurableListableBeanFactory ? (ConfigurableListableBeanFactory) beanFactory
42+
factory = beanFactory instanceof ConfigurableListableBeanFactory cbf ? cbf
4343
: new DefaultListableBeanFactory(beanFactory);
4444
}
4545

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

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public ConfigurableTypeInformationMapper(Map<? extends Class<?>, String> sourceT
6666
}
6767
}
6868

69+
@Override
6970
public Alias createAliasFor(TypeInformation<?> type) {
7071
return typeToAlias.getOrDefault(type, Alias.NONE);
7172
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public MappingContextTypeInformationMapper(MappingContext<? extends PersistentEn
5858
}
5959
}
6060

61+
@Override
6162
public Alias createAliasFor(TypeInformation<?> type) {
6263

6364
return typeMap.computeIfAbsent(type.getRawTypeInformation(), key -> {

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

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public int size() {
7979
return converterRegistrationMap.size();
8080
}
8181

82+
@Override
8283
public boolean isEmpty() {
8384
return converterRegistrationMap.isEmpty();
8485
}

src/main/java/org/springframework/data/crossstore/HashMapChangeSet.java

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public HashMapChangeSet() {
4141
this(new HashMap<>());
4242
}
4343

44+
@Override
4445
public void set(String key, Object o) {
4546
values.put(key, o);
4647
}
@@ -49,15 +50,18 @@ public String toString() {
4950
return "HashMapChangeSet: values=[" + values + "]";
5051
}
5152

53+
@Override
5254
public Map<String, Object> getValues() {
5355
return Collections.unmodifiableMap(values);
5456
}
5557

58+
@Override
5659
@Nullable
5760
public Object removeProperty(String k) {
5861
return this.values.remove(k);
5962
}
6063

64+
@Override
6165
@Nullable
6266
public <T> T get(String key, Class<T> requiredClass, ConversionService conversionService) {
6367

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

+10
Original file line numberDiff line numberDiff line change
@@ -54,42 +54,52 @@ public Chunk(List<T> content, Pageable pageable) {
5454
this.pageable = pageable;
5555
}
5656

57+
@Override
5758
public int getNumber() {
5859
return pageable.isPaged() ? pageable.getPageNumber() : 0;
5960
}
6061

62+
@Override
6163
public int getSize() {
6264
return pageable.isPaged() ? pageable.getPageSize() : content.size();
6365
}
6466

67+
@Override
6568
public int getNumberOfElements() {
6669
return content.size();
6770
}
6871

72+
@Override
6973
public boolean hasPrevious() {
7074
return getNumber() > 0;
7175
}
7276

77+
@Override
7378
public boolean isFirst() {
7479
return !hasPrevious();
7580
}
7681

82+
@Override
7783
public boolean isLast() {
7884
return !hasNext();
7985
}
8086

87+
@Override
8188
public Pageable nextPageable() {
8289
return hasNext() ? pageable.next() : Pageable.unpaged();
8390
}
8491

92+
@Override
8593
public Pageable previousPageable() {
8694
return hasPrevious() ? pageable.previousOrFirst() : Pageable.unpaged();
8795
}
8896

97+
@Override
8998
public boolean hasContent() {
9099
return !content.isEmpty();
91100
}
92101

102+
@Override
93103
public List<T> getContent() {
94104
return Collections.unmodifiableList(content);
95105
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,6 @@ static <T> Page<T> empty(Pageable pageable) {
6969
* @return a new {@link Page} with the content of the current one mapped by the given {@link Function}.
7070
* @since 1.10
7171
*/
72+
@Override
7273
<U> Page<U> map(Function<? super T, ? extends U> converter);
7374
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public static PageRequest ofSize(int pageSize) {
9797
return PageRequest.of(0, pageSize);
9898
}
9999

100+
@Override
100101
public Sort getSort() {
101102
return sort;
102103
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ default Pageable getPageable() {
136136
* @return a new {@link Slice} with the content of the current one mapped by the given {@link Converter}.
137137
* @since 1.10
138138
*/
139+
@Override
139140
<U> Slice<U> map(Function<? super T, ? extends U> converter);
140141

141142
/**

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.domain;
1717

18+
import java.io.Serial;
1819
import java.util.List;
1920
import java.util.function.Function;
2021

@@ -29,6 +30,7 @@
2930
*/
3031
public class SliceImpl<T> extends Chunk<T> {
3132

33+
@Serial
3234
private static final long serialVersionUID = 867755909294344406L;
3335

3436
private final boolean hasNext;
@@ -59,6 +61,7 @@ public SliceImpl(List<T> content) {
5961
this(content, Pageable.unpaged(), false);
6062
}
6163

64+
@Override
6265
public boolean hasNext() {
6366
return hasNext;
6467
}
@@ -74,7 +77,7 @@ public String toString() {
7477
String contentType = "UNKNOWN";
7578
List<T> content = getContent();
7679

77-
if (content.size() > 0) {
80+
if (!content.isEmpty()) {
7881
contentType = content.get(0).getClass().getName();
7982
}
8083

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public Sort and(Sort sort) {
204204

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

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

209209
for (Order order : sort) {
210210
these.add(order);

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

+2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ class TypedExample<T> implements Example<T> {
3838
this.matcher = matcher;
3939
}
4040

41+
@Override
4142
public T getProbe() {
4243
return this.probe;
4344
}
4445

46+
@Override
4547
public ExampleMatcher getMatcher() {
4648
return this.matcher;
4749
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static <T> Window<T> from(List<T> items, IntFunction<? extends ScrollPosition> p
7272
*
7373
* @return {@code true} if this window contains no elements
7474
*/
75+
@Override
7576
boolean isEmpty();
7677

7778
/**
@@ -149,6 +150,7 @@ default ScrollPosition positionAt(T object) {
149150
* @param converter must not be {@literal null}.
150151
* @return a new {@link Window} with the content of the current one mapped by the given {@code converter}.
151152
*/
153+
@Override
152154
<U> Window<U> map(Function<? super T, ? extends U> converter);
153155

154156
}

src/main/java/org/springframework/data/geo/CustomMetric.java

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public CustomMetric(double multiplier, String abbreviation) {
5555
this.abbreviation = abbreviation;
5656
}
5757

58+
@Override
5859
public double getMultiplier() {
5960
return multiplier;
6061
}

src/main/java/org/springframework/data/geo/Metrics.java

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private Metrics(double multiplier, String abbreviation) {
4141
this.abbreviation = abbreviation;
4242
}
4343

44+
@Override
4445
public double getMultiplier() {
4546
return multiplier;
4647
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,22 @@ public AnnotationRevisionMetadata(Object entity, Class<? extends Annotation> rev
8484
this.revisionType = revisionType;
8585
}
8686

87+
@Override
8788
public Optional<N> getRevisionNumber() {
8889
return revisionNumber.get();
8990
}
9091

92+
@Override
9193
public Optional<Instant> getRevisionInstant() {
9294
return revisionDate.get().map(AnnotationRevisionMetadata::convertToInstant);
9395
}
9496

97+
@Override
9598
public RevisionType getRevisionType() {
9699
return revisionType;
97100
}
98101

102+
@Override
99103
@SuppressWarnings("unchecked")
100104
public <T> T getDelegate() {
101105
return (T) entity;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public <T> GetOptions registerHandler(PersistentProperty<?> property, Class<T> t
186186
Assert.isTrue(type.isAssignableFrom(property.getType()), () -> String
187187
.format("Cannot register a property handler for %s on a property of type %s", type, property.getType()));
188188

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

191191
return registerHandler(property, caster.andThen(handler));
192192
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Executable getExecutable() {
6767
*
6868
* @return
6969
*/
70+
@Override
7071
public List<Parameter<Object, P>> getParameters() {
7172
return parameters;
7273
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public PropertyPath nested(String path) {
246246
@Override
247247
public Iterator<PropertyPath> iterator() {
248248

249-
return new Iterator<PropertyPath>() {
249+
return new Iterator<>() {
250250

251251
private @Nullable PropertyPath current = PropertyPath.this;
252252

@@ -365,7 +365,7 @@ public static PropertyPath from(String source, TypeInformation<?> type) {
365365
Iterator<String> parts = iteratorSource.iterator();
366366

367367
PropertyPath result = null;
368-
Stack<PropertyPath> current = new Stack<PropertyPath>();
368+
Stack<PropertyPath> current = new Stack<>();
369369

370370
while (parts.hasNext()) {
371371
if (result == null) {

src/main/java/org/springframework/data/mapping/callback/EntityCallbackDiscoverer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void discoverEntityCallbacks(BeanFactory beanFactory) {
311311

312312
for (var beanName : bf.getBeanNamesForType(EntityCallback.class)) {
313313

314-
EntityCallback<?> bean = EntityCallback.class.cast(bf.getBean(beanName));
314+
EntityCallback<?> bean = (EntityCallback) bf.getBean(beanName);
315315

316316
ResolvableType type = ResolvableType.forClass(EntityCallback.class, bean.getClass());
317317
ResolvableType entityType = type.getGeneric(0);

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ public String toPath(String delimiter, Converter<? super P, String> converter) {
135135
@Override
136136
public P getLeafProperty() {
137137

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

140140
return properties.get(properties.size() - 1);
141141
}
142142

143143
@Override
144144
public P getBaseProperty() {
145145

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

148148
return properties.get(0);
149149
}
@@ -208,10 +208,17 @@ public Iterator<P> iterator() {
208208
*/
209209
public boolean containsPropertyOfType(@Nullable TypeInformation<?> type) {
210210

211-
return type == null //
212-
? false //
213-
: properties.stream() //
214-
.anyMatch(property -> type.equals(property.getTypeInformation().getActualType()));
211+
if (type == null) {
212+
return false;
213+
}
214+
215+
for (P property : properties) {
216+
if (type.equals(property.getTypeInformation().getActualType())) {
217+
return true;
218+
}
219+
}
220+
221+
return false;
215222
}
216223

217224
@Override

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public Iterator<P> iterator() {
406406

407407
Iterator<P> iterator = properties.iterator();
408408

409-
return new Iterator<P>() {
409+
return new Iterator<>() {
410410

411411
@Override
412412
public boolean hasNext() {

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

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ protected BeanWrapper(T bean) {
5757
this.bean = bean;
5858
}
5959

60+
@Override
6061
@SuppressWarnings("unchecked")
6162
public void setProperty(PersistentProperty<?> property, @Nullable Object value) {
6263

@@ -104,6 +105,7 @@ public void setProperty(PersistentProperty<?> property, @Nullable Object value)
104105
}
105106
}
106107

108+
@Override
107109
@Nullable
108110
public Object getProperty(PersistentProperty<?> property) {
109111
return getProperty(property, property.getType());
@@ -144,6 +146,7 @@ public <S> Object getProperty(PersistentProperty<?> property, Class<? extends S>
144146
}
145147
}
146148

149+
@Override
147150
public T getBean() {
148151
return bean;
149152
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public DefaultSpELExpressionEvaluator(Object source, SpELContext factory) {
4343
this.factory = factory;
4444
}
4545

46+
@Override
4647
@Nullable
4748
@SuppressWarnings("unchecked")
4849
public <T> T evaluate(String expression) {

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

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public IdPropertyIdentifierAccessor(PersistentEntity<?, ?> entity, Object target
5454
this.accessor = entity.getPropertyAccessor(target);
5555
}
5656

57+
@Override
5758
@Nullable
5859
public Object getIdentifier() {
5960
return accessor.getProperty(idProperty);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public String toString() {
435435
ValueBoxing hierarchy = this;
436436
while (hierarchy != null) {
437437

438-
if (sb.length() != 0) {
438+
if (!sb.isEmpty()) {
439439
sb.append(" -> ");
440440
}
441441

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public boolean isNew(Object entity) {
100100
return false;
101101
}
102102

103-
if (value instanceof Number) {
104-
return ((Number) value).longValue() == 0;
103+
if (value instanceof Number n) {
104+
return n.longValue() == 0;
105105
}
106106

107107
throw new IllegalArgumentException(

0 commit comments

Comments
 (0)