Class WrapperAdapterUtils
java.lang.Object
io.foldright.inspectablewrappers.utils.WrapperAdapterUtils
@DefaultAnnotationForParameters(edu.umd.cs.findbugs.annotations.NonNull.class)
public final class WrapperAdapterUtils
extends Object
Utility class for creating
WrapperAdapter
instances
without writing boilerplate codes of creating new adapter classes.- Author:
- Jerry Lee (oldratlee at gmail dot com)
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
createWrapperAdapter
(Class<? super T> bizInterface, T underlying, T adaptee) Creates aWrapperAdapter
instance of the given biz interface type by the underlying(Wrapper.unwrap_()
) and adaptee(WrapperAdapter.adaptee_()
) instances.static <T> T
createWrapperAdapter
(Class<? super T> bizInterface, T underlying, T adaptee, Attachable<?, ?> attachable) Creates aWrapperAdapter
instance of the given biz interface type andAttachable
type by the underlying(Wrapper.unwrap_()
), adaptee(WrapperAdapter.adaptee_()
) and attachable instances.static <T> T
createWrapperAdapter
(Class<? super T> bizInterface, T underlying, T adaptee, Attachable<?, ?> attachable, Class<?>... tagInterfaces) Same ascreateWrapperAdapter(Class, Object, Object, Attachable)
, but the returnedWrapperAdapter
instance also implements the given tag interfaces.static <T> T
createWrapperAdapter
(Class<? super T> bizInterface, T underlying, T adaptee, Class<?>... tagInterfaces) Same ascreateWrapperAdapter(Class, Object, Object)
, but the returnedWrapperAdapter
instance also implements the given tag interfaces.
-
Method Details
-
createWrapperAdapter
@NonNull public static <T> T createWrapperAdapter(Class<? super T> bizInterface, T underlying, T adaptee) Creates aWrapperAdapter
instance of the given biz interface type by the underlying(Wrapper.unwrap_()
) and adaptee(WrapperAdapter.adaptee_()
) instances.- Type Parameters:
T
- the type of instances that be wrapped- Parameters:
bizInterface
- the class of instances that be wrappedunderlying
- the underlying instance that be wrapped, more info seeWrapper.unwrap_()
adaptee
- the adapted/existed wrapper instance, more info seeWrapperAdapter.adaptee_()
- Returns:
- the new
WrapperAdapter
instance - Throws:
IllegalArgumentException
- ifbizInterface
is not an interface, orbizInterface
isWrapper
/WrapperAdapter
/Attachable
, or underlying is not an instance ofbizInterface
, or adaptee is not an instance ofbizInterface
, or adaptee is an instance ofWrapper
NullPointerException
- if any argument is null- See Also:
-
createWrapperAdapter
@NonNull public static <T> T createWrapperAdapter(Class<? super T> bizInterface, T underlying, T adaptee, Attachable<?, ?> attachable) Creates aWrapperAdapter
instance of the given biz interface type andAttachable
type by the underlying(Wrapper.unwrap_()
), adaptee(WrapperAdapter.adaptee_()
) and attachable instances.- Type Parameters:
T
- the type of instances that be wrapped- Parameters:
bizInterface
- the class of instances that be wrappedunderlying
- the underlying instance that be wrapped, more info seeWrapper.unwrap_()
adaptee
- the adapted/existed wrapper instance, more info seeWrapperAdapter.adaptee_()
attachable
- the attachable instance, more info seeAttachable
- Returns:
- the new
WrapperAdapter
instance - Throws:
IllegalArgumentException
- ifbizInterface
is not an interface, orbizInterface
isWrapper
/WrapperAdapter
/Attachable
, or underlying is not an instance ofbizInterface
, or adaptee is not an instance ofbizInterface
, or adaptee is an instance ofWrapper
NullPointerException
- if any argument is null- See Also:
-
createWrapperAdapter
@NonNull public static <T> T createWrapperAdapter(Class<? super T> bizInterface, T underlying, T adaptee, Class<?>... tagInterfaces) Same ascreateWrapperAdapter(Class, Object, Object)
, but the returnedWrapperAdapter
instance also implements the given tag interfaces. -
createWrapperAdapter
@NonNull public static <T> T createWrapperAdapter(Class<? super T> bizInterface, T underlying, T adaptee, Attachable<?, ?> attachable, Class<?>... tagInterfaces) Same ascreateWrapperAdapter(Class, Object, Object, Attachable)
, but the returnedWrapperAdapter
instance also implements the given tag interfaces.
-