Skip to content

Commit 3bed23d

Browse files
committed
Replace PropertyMapper.CachingSupplier with use of SingletonSupplier
Closes gh-27635
1 parent d888eb6 commit 3bed23d

File tree

1 file changed

+3
-28
lines changed
  • spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties

1 file changed

+3
-28
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/PropertyMapper.java

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
2525

2626
import org.springframework.util.Assert;
2727
import org.springframework.util.StringUtils;
28+
import org.springframework.util.function.SingletonSupplier;
2829

2930
/**
3031
* Utility that can be used to map values from a supplied source to a destination.
@@ -125,7 +126,7 @@ private <T> Source<T> getSource(Supplier<T> supplier) {
125126
if (this.parent != null) {
126127
return this.parent.from(supplier);
127128
}
128-
return new Source<>(new CachingSupplier<>(supplier), (Predicate<T>) ALWAYS);
129+
return new Source<>(SingletonSupplier.of(supplier), (Predicate<T>) ALWAYS);
129130
}
130131

131132
/**
@@ -136,32 +137,6 @@ public static PropertyMapper get() {
136137
return INSTANCE;
137138
}
138139

139-
/**
140-
* Supplier that caches the value to prevent multiple calls.
141-
*/
142-
private static class CachingSupplier<T> implements Supplier<T> {
143-
144-
private final Supplier<T> supplier;
145-
146-
private boolean hasResult;
147-
148-
private T result;
149-
150-
CachingSupplier(Supplier<T> supplier) {
151-
this.supplier = supplier;
152-
}
153-
154-
@Override
155-
public T get() {
156-
if (!this.hasResult) {
157-
this.result = this.supplier.get();
158-
this.hasResult = true;
159-
}
160-
return this.result;
161-
}
162-
163-
}
164-
165140
/**
166141
* An operation that can be applied to a {@link Source}.
167142
*/

0 commit comments

Comments
 (0)