Package com.helger.base.wrapper
Class Wrapper<DATATYPE>
java.lang.Object
com.helger.base.wrapper.Wrapper<DATATYPE>
- Type Parameters:
DATATYPE- The type of object to be wrapped.
- All Implemented Interfaces:
ICloneable<Wrapper<DATATYPE>>,IMutableWrapper<DATATYPE>,IWrapper<DATATYPE>,Supplier<DATATYPE>
@NotThreadSafe
public class Wrapper<DATATYPE>
extends Object
implements IMutableWrapper<DATATYPE>, ICloneable<Wrapper<DATATYPE>>
This is a stupid wrapper around any object. Its original purpose was the encapsulation of return
values from within an anonymous class.
- Author:
- Philip Helger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @NonNull Wrapper<T> empty()Create a new Wrapper object that contains anullvalue.boolean@Nullable DATATYPEget()booleanget(@NonNull IToBooleanFunction<DATATYPE> aProvider, boolean bDefault) Deprecated, for removal: This API element is subject to removal in a future version.Use the version with Predicate instead<T> @Nullable TApply the provided function on the value contained in this wrapper, but only if the value is notnull.booleanApply the provided function on the value contained in this wrapper, but only if the value is notnull.doubleget(@NonNull ToDoubleFunction<DATATYPE> aProvider, double dDefault) Apply the provided function on the value contained in this wrapper, but only if the value is notnull.intget(@NonNull ToIntFunction<DATATYPE> aProvider, int nDefault) Apply the provided function on the value contained in this wrapper, but only if the value is notnull.longget(@NonNull ToLongFunction<DATATYPE> aProvider, long nDefault) Apply the provided function on the value contained in this wrapper, but only if the value is notnull.getClone()inthashCode()static <T> @NonNull Wrapper<T> of(@Nullable T aValue) Create a new Wrapper object that contains the provided value.static <T> @NonNull Wrapper<T> Create a new Wrapper object that contains the value of the providedWrapper.@NonNull EChangeChange the wrapped object.toString()
-
Constructor Details
-
Wrapper
public Wrapper()Default constructor. Wraps anullvalues. -
Wrapper
Constructor with an existing object.- Parameters:
aObj- The existing object. May benull.
-
Wrapper
Copy constructor. Only takes wrappers of the same type.- Parameters:
aRhs- The other wrapper to use. May not benull.
-
-
Method Details
-
get
-
get
Apply the provided function on the value contained in this wrapper, but only if the value is notnull.- Type Parameters:
T- The data type to be returned.- Parameters:
aProvider- The function to be applied on the wrapped value.- Returns:
nullif the wrapped value isnullor if the function returnednull.- Since:
- 12.1.2
-
get
Apply the provided function on the value contained in this wrapper, but only if the value is notnull.- Parameters:
aProvider- The function to be applied on the wrapped value.nDefault- the value to be returned if the wrapped value isnull.- Returns:
- The extracted value.
- Since:
- 12.1.2
-
get
Apply the provided function on the value contained in this wrapper, but only if the value is notnull.- Parameters:
aProvider- The function to be applied on the wrapped value.nDefault- the value to be returned if the wrapped value isnull.- Returns:
- The extracted value.
- Since:
- 12.1.2
-
get
Apply the provided function on the value contained in this wrapper, but only if the value is notnull.- Parameters:
aProvider- The function to be applied on the wrapped value.dDefault- the value to be returned if the wrapped value isnull.- Returns:
- The extracted value.
- Since:
- 12.1.2
-
get
@Deprecated(forRemoval=true, since="12.1.5") public boolean get(@NonNull IToBooleanFunction<DATATYPE> aProvider, boolean bDefault) Deprecated, for removal: This API element is subject to removal in a future version.Use the version with Predicate insteadApply the provided function on the value contained in this wrapper, but only if the value is notnull.- Parameters:
aProvider- The function to be applied on the wrapped value.bDefault- the value to be returned if the wrapped value isnull.- Returns:
- The extracted value.
- Since:
- 12.1.2
-
get
Apply the provided function on the value contained in this wrapper, but only if the value is notnull.- Parameters:
aProvider- The function to be applied on the wrapped value.bDefault- the value to be returned if the wrapped value isnull.- Returns:
- The extracted value.
- Since:
- 12.1.5
-
set
Change the wrapped object.- Specified by:
setin interfaceIMutableWrapper<DATATYPE>- Parameters:
aObj- The new object to be wrapped. May benull.- Returns:
EChange
-
getClone
- Specified by:
getClonein interfaceICloneable<DATATYPE>- Returns:
- A clone of this wrapper containing the same wrapped object. Never
null.
-
equals
-
hashCode
public int hashCode() -
toString
-
empty
Create a new Wrapper object that contains anullvalue.- Type Parameters:
T- The type to be wrapped.- Returns:
- A non-
nullWrapperinstance. - Since:
- 12.1.2
-
of
Create a new Wrapper object that contains the provided value.- Type Parameters:
T- The type to be wrapped.- Parameters:
aValue- The value to be wrapped. May benull.- Returns:
- A non-
nullWrapperinstance. - Since:
- 12.1.2
-
of
Create a new Wrapper object that contains the value of the providedWrapper.- Type Parameters:
T- The type to be wrapped.- Parameters:
aValue- The wrapped value to be wrapped again. May not benull.- Returns:
- A non-
nullWrapperinstance. - Since:
- 12.1.2
-