Class PropertyMapper.Source<T>
java.lang.Object
org.springframework.boot.context.properties.PropertyMapper.Source<T>
- Type Parameters:
T- the source type
- Enclosing class:
PropertyMapper
A source that is in the process of being mapped.
- Since:
- 2.0.0
- Author:
- Phillip Webb, Artsiom Yudovin, Chris Bono, Moritz Halbritter
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAdapter used to adapt a value and possibly return anullresult.static classAllow source mapping to complete using methods that accept nulls. -
Method Summary
Modifier and TypeMethodDescriptionalways()Return a version of this source that can be used to always complete mappings, even if values arenull.<R> PropertyMapper.Source<R> as(PropertyMapper.Source.Adapter<? super T, ? extends R> adapter) Return an adapted version of the source changed through the given adapter function.<R extends Number>
PropertyMapper.Source<Integer> asInt(PropertyMapper.Source.Adapter<? super T, ? extends R> adapter) Return an adapted version of the source withIntegertype.Return a source that will use the given supplier to obtain a fallback value to use in place ofnull.voidComplete the mapping by passing any non-filtered value to the specified consumer.<R> Rto(R instance, BiFunction<R, ? super T, R> mapper) Complete the mapping for any non-filtered value by applying the given function to an existing instance and returning a new one.voidComplete the mapping by calling the specified method when the value has not been filtered.<R> RtoInstance(Function<? super T, R> factory) Complete the mapping by creating a new instance from the non-filtered value.Return a filtered version of the source that won't map values that don't match the given predicate.whenEqualTo(@Nullable Object object) Return a filtered version of the source that will only map values equal to the specifiedobject.Return a filtered version of the source that will only map values that arefalse.Return a filtered version of the source that will only map values that have atoString()containing actual text.<R extends T>
PropertyMapper.Source<R> whenInstanceOf(Class<R> target) Return a filtered version of the source that will only map values that are an instance of the given type.Return a filtered version of the source that won't map values that match the given predicate.whenTrue()Return a filtered version of the source that will only map values that aretrue.
-
Method Details
-
orFrom
Return a source that will use the given supplier to obtain a fallback value to use in place ofnull.- Parameters:
fallback- the fallback supplier- Returns:
- a new
PropertyMapper.Sourceinstance - Since:
- 4.0.0
-
asInt
public <R extends Number> PropertyMapper.Source<Integer> asInt(PropertyMapper.Source.Adapter<? super T, ? extends R> adapter) Return an adapted version of the source withIntegertype.- Type Parameters:
R- the resulting type- Parameters:
adapter- an adapter to convert the current value to a number.- Returns:
- a new adapted source instance
-
as
public <R> PropertyMapper.Source<R> as(PropertyMapper.Source.Adapter<? super T, ? extends R> adapter) Return an adapted version of the source changed through the given adapter function.- Type Parameters:
R- the resulting type- Parameters:
adapter- the adapter to apply- Returns:
- a new adapted source instance
-
whenTrue
Return a filtered version of the source that will only map values that aretrue.- Returns:
- a new filtered source instance
-
whenFalse
Return a filtered version of the source that will only map values that arefalse.- Returns:
- a new filtered source instance
-
whenHasText
Return a filtered version of the source that will only map values that have atoString()containing actual text.- Returns:
- a new filtered source instance
-
whenEqualTo
Return a filtered version of the source that will only map values equal to the specifiedobject.- Parameters:
object- the object to match- Returns:
- a new filtered source instance
-
whenInstanceOf
Return a filtered version of the source that will only map values that are an instance of the given type.- Type Parameters:
R- the target type- Parameters:
target- the target type to match- Returns:
- a new filtered source instance
-
whenNot
Return a filtered version of the source that won't map values that match the given predicate.- Parameters:
predicate- the predicate used to filter values- Returns:
- a new filtered source instance
-
when
Return a filtered version of the source that won't map values that don't match the given predicate.- Parameters:
predicate- the predicate used to filter values- Returns:
- a new filtered source instance
-
to
-
to
Complete the mapping for any non-filtered value by applying the given function to an existing instance and returning a new one. For filtered values, theinstanceparameter is returned unchanged. The method is designed to be used with immutable objects.- Type Parameters:
R- the result type- Parameters:
instance- the current instancemapper- the mapping function- Returns:
- a new mapped instance or the original instance
- Since:
- 3.0.0
-
toInstance
Complete the mapping by creating a new instance from the non-filtered value.- Type Parameters:
R- the resulting type- Parameters:
factory- the factory used to create the instance- Returns:
- the instance
- Throws:
NoSuchElementException- if the value has been filtered
-
toCall
Complete the mapping by calling the specified method when the value has not been filtered.- Parameters:
runnable- the method to call if the value has not been filtered
-
always
Return a version of this source that can be used to always complete mappings, even if values arenull.- Returns:
- a new
PropertyMapper.Source.Alwaysinstance - Since:
- 4.0.0
-