Browse Source

Polishing.

Reduce Stream usage.

Original Pull Request: #3442
pull/3471/head
Mark Paluch 2 months ago committed by Christoph Strobl
parent
commit
2a5a92edfd
No known key found for this signature in database
GPG Key ID: E6054036D0C37A4B
  1. 23
      src/main/java/org/springframework/data/mapping/context/PersistentEntities.java

23
src/main/java/org/springframework/data/mapping/context/PersistentEntities.java

@ -136,7 +136,7 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte @@ -136,7 +136,7 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
* @return result of the {@link BiFunction}.
*/
public <T> Optional<T> mapOnContext(Class<?> type,
BiFunction<MappingContext<?, ? extends PersistentProperty<?>>, PersistentEntity<?, ?>, T> combiner) {
BiFunction<MappingContext<?, ? extends PersistentProperty<?>>, PersistentEntity<?, ?>, @Nullable T> combiner) {
Assert.notNull(type, "Type must not be null");
Assert.notNull(combiner, "Combining BiFunction must not be null");
@ -144,16 +144,21 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte @@ -144,16 +144,21 @@ public class PersistentEntities implements Streamable<PersistentEntity<?, ? exte
Collection<? extends MappingContext<?, ? extends PersistentProperty<?>>> mappingContexts = getMappingContexts();
if (mappingContexts.size() == 1) {
return mappingContexts.stream() //
.filter(it -> it.getPersistentEntity(type) != null) //
.map(it -> combiner.apply(it, it.getRequiredPersistentEntity(type))) //
.findFirst();
for (MappingContext<?, ? extends PersistentProperty<?>> it : mappingContexts) {
if (it.getPersistentEntity(type) != null) {
return Optional.ofNullable(combiner.apply(it, it.getRequiredPersistentEntity(type)));
}
}
return Optional.empty();
}
for (MappingContext<?, ? extends PersistentProperty<?>> it : mappingContexts) {
if (it.hasPersistentEntityFor(type)) {
return Optional.ofNullable(combiner.apply(it, it.getRequiredPersistentEntity(type)));
}
}
return mappingContexts.stream() //
.filter(it -> it.hasPersistentEntityFor(type)) //
.map(it -> combiner.apply(it, it.getRequiredPersistentEntity(type))) //
.findFirst();
return Optional.empty();
}
/**

Loading…
Cancel
Save