From 3bed23d9dcfff2ba9e30cc5f2373fe1db0451c99 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 12 Aug 2021 12:03:50 +0100 Subject: [PATCH] Replace PropertyMapper.CachingSupplier with use of SingletonSupplier Closes gh-27635 --- .../context/properties/PropertyMapper.java | 31 ++----------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/PropertyMapper.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/PropertyMapper.java index 72e8cd50ec..7fc758eea4 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/PropertyMapper.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/PropertyMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import java.util.function.Supplier; import org.springframework.util.Assert; import org.springframework.util.StringUtils; +import org.springframework.util.function.SingletonSupplier; /** * Utility that can be used to map values from a supplied source to a destination. @@ -125,7 +126,7 @@ public final class PropertyMapper { if (this.parent != null) { return this.parent.from(supplier); } - return new Source<>(new CachingSupplier<>(supplier), (Predicate) ALWAYS); + return new Source<>(SingletonSupplier.of(supplier), (Predicate) ALWAYS); } /** @@ -136,32 +137,6 @@ public final class PropertyMapper { return INSTANCE; } - /** - * Supplier that caches the value to prevent multiple calls. - */ - private static class CachingSupplier implements Supplier { - - private final Supplier supplier; - - private boolean hasResult; - - private T result; - - CachingSupplier(Supplier supplier) { - this.supplier = supplier; - } - - @Override - public T get() { - if (!this.hasResult) { - this.result = this.supplier.get(); - this.hasResult = true; - } - return this.result; - } - - } - /** * An operation that can be applied to a {@link Source}. */