Skip to content

Commit 0dbe331

Browse files
committed
DATAMONGO-1823 - Polishing.
Replace constructor with lombok's RequiredArgsConstructor. Add Nullable annotation. Tiny reformatting. Align license header. Migrate test to AssertJ. Original pull request: spring-projects#517.
1 parent 846ebcd commit 0dbe331

File tree

2 files changed

+134
-161
lines changed

2 files changed

+134
-161
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,31 +2771,26 @@ interface DocumentCallback<T> {
27712771
* @author Oliver Gierke
27722772
* @author Christoph Strobl
27732773
*/
2774+
@RequiredArgsConstructor
27742775
private class ReadDocumentCallback<T> implements DocumentCallback<T> {
27752776

2776-
private final EntityReader<? super T, Bson> reader;
2777-
private final Class<T> type;
2777+
private final @NonNull EntityReader<? super T, Bson> reader;
2778+
private final @NonNull Class<T> type;
27782779
private final String collectionName;
27792780

2780-
public ReadDocumentCallback(EntityReader<? super T, Bson> reader, Class<T> type, String collectionName) {
2781-
2782-
Assert.notNull(reader, "EntityReader must not be null!");
2783-
Assert.notNull(type, "Entity type must not be null!");
2784-
2785-
this.reader = reader;
2786-
this.type = type;
2787-
this.collectionName = collectionName;
2788-
}
2789-
27902781
@Nullable
2791-
public T doWith(Document object) {
2782+
public T doWith(@Nullable Document object) {
2783+
27922784
if (null != object) {
27932785
maybeEmitEvent(new AfterLoadEvent<T>(object, type, collectionName));
27942786
}
2787+
27952788
T source = reader.read(type, object);
2789+
27962790
if (null != source) {
27972791
maybeEmitEvent(new AfterConvertEvent<T>(object, source, collectionName));
27982792
}
2793+
27992794
return source;
28002795
}
28012796
}
@@ -2838,7 +2833,7 @@ public T doWith(@Nullable Document object) {
28382833
Object source = reader.read(typeToRead, object);
28392834
Object result = targetType.isInterface() ? projectionFactory.createProjection(targetType, source) : source;
28402835

2841-
if (result != null) {
2836+
if (null != result) {
28422837
maybeEmitEvent(new AfterConvertEvent<>(object, result, collectionName));
28432838
}
28442839

@@ -2991,7 +2986,7 @@ public GeoResult<T> doWith(@Nullable Document object) {
29912986

29922987
T doWith = delegate.doWith(content);
29932988

2994-
return new GeoResult<T>(doWith, new Distance(distance, metric));
2989+
return new GeoResult<>(doWith, new Distance(distance, metric));
29952990
}
29962991
}
29972992

0 commit comments

Comments
 (0)