|
|
|
@ -75,8 +75,19 @@ public interface InstanceSupplier<T> extends ThrowingSupplier<T> {
@@ -75,8 +75,19 @@ public interface InstanceSupplier<T> extends ThrowingSupplier<T> {
|
|
|
|
|
default <V> InstanceSupplier<V> andThen( |
|
|
|
|
ThrowingBiFunction<RegisteredBean, ? super T, ? extends V> after) { |
|
|
|
|
Assert.notNull(after, "After must not be null"); |
|
|
|
|
return registeredBean -> after.applyWithException(registeredBean, |
|
|
|
|
get(registeredBean)); |
|
|
|
|
return new InstanceSupplier<V>() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public V get(RegisteredBean registeredBean) throws Exception { |
|
|
|
|
return after.applyWithException(registeredBean, InstanceSupplier.this.get(registeredBean)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Method getFactoryMethod() { |
|
|
|
|
return InstanceSupplier.this.getFactoryMethod(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -94,6 +105,35 @@ public interface InstanceSupplier<T> extends ThrowingSupplier<T> {
@@ -94,6 +105,35 @@ public interface InstanceSupplier<T> extends ThrowingSupplier<T> {
|
|
|
|
|
return registeredBean -> supplier.getWithException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Factory method to create an {@link InstanceSupplier} from a |
|
|
|
|
* {@link ThrowingSupplier}. |
|
|
|
|
* @param <T> the type of instance supplied by this supplier |
|
|
|
|
* @param factoryMethod the factory method being used |
|
|
|
|
* @param supplier the source supplier |
|
|
|
|
* @return a new {@link InstanceSupplier} |
|
|
|
|
*/ |
|
|
|
|
static <T> InstanceSupplier<T> using(@Nullable Method factoryMethod, ThrowingSupplier<T> supplier) { |
|
|
|
|
Assert.notNull(supplier, "Supplier must not be null"); |
|
|
|
|
if (supplier instanceof InstanceSupplier<T> instanceSupplier |
|
|
|
|
&& instanceSupplier.getFactoryMethod() == factoryMethod) { |
|
|
|
|
return instanceSupplier; |
|
|
|
|
} |
|
|
|
|
return new InstanceSupplier<T>() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public T get(RegisteredBean registeredBean) throws Exception { |
|
|
|
|
return supplier.getWithException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Method getFactoryMethod() { |
|
|
|
|
return factoryMethod; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Lambda friendly method that can be used to create a |
|
|
|
|
* {@link InstanceSupplier} and add post processors in a single call. For |
|
|
|
|