Skip to content

Commit f13a4bb

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 e411831 commit f13a4bb

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
@@ -2754,31 +2754,26 @@ interface DocumentCallback<T> {
27542754
* @author Oliver Gierke
27552755
* @author Christoph Strobl
27562756
*/
2757+
@RequiredArgsConstructor
27572758
private class ReadDocumentCallback<T> implements DocumentCallback<T> {
27582759

2759-
private final EntityReader<? super T, Bson> reader;
2760-
private final Class<T> type;
2760+
private final @NonNull EntityReader<? super T, Bson> reader;
2761+
private final @NonNull Class<T> type;
27612762
private final String collectionName;
27622763

2763-
public ReadDocumentCallback(EntityReader<? super T, Bson> reader, Class<T> type, String collectionName) {
2764-
2765-
Assert.notNull(reader, "EntityReader must not be null!");
2766-
Assert.notNull(type, "Entity type must not be null!");
2767-
2768-
this.reader = reader;
2769-
this.type = type;
2770-
this.collectionName = collectionName;
2771-
}
2772-
27732764
@Nullable
2774-
public T doWith(Document object) {
2765+
public T doWith(@Nullable Document object) {
2766+
27752767
if (null != object) {
27762768
maybeEmitEvent(new AfterLoadEvent<T>(object, type, collectionName));
27772769
}
2770+
27782771
T source = reader.read(type, object);
2772+
27792773
if (null != source) {
27802774
maybeEmitEvent(new AfterConvertEvent<T>(object, source, collectionName));
27812775
}
2776+
27822777
return source;
27832778
}
27842779
}
@@ -2821,7 +2816,7 @@ public T doWith(@Nullable Document object) {
28212816
Object source = reader.read(typeToRead, object);
28222817
Object result = targetType.isInterface() ? projectionFactory.createProjection(targetType, source) : source;
28232818

2824-
if (result != null) {
2819+
if (null != result) {
28252820
maybeEmitEvent(new AfterConvertEvent<>(object, result, collectionName));
28262821
}
28272822

@@ -2974,7 +2969,7 @@ public GeoResult<T> doWith(@Nullable Document object) {
29742969

29752970
T doWith = delegate.doWith(content);
29762971

2977-
return new GeoResult<T>(doWith, new Distance(distance, metric));
2972+
return new GeoResult<>(doWith, new Distance(distance, metric));
29782973
}
29792974
}
29802975

0 commit comments

Comments
 (0)