Package io.microsphere.lang
Interface DelegatingWrapper
-
- All Superinterfaces:
Wrapper
- All Known Implementing Classes:
DelegatingDeque,DelegatingQueue,ReversedDeque
public interface DelegatingWrapper extends Wrapper
A delegatingWrapperinterface that provides default implementations for unwrapping and checking wrapped object types. This interface is designed to be extended by classes that want to provide a delegated implementation of the wrapper pattern.The main purpose of this interface is to simplify the implementation of the
Wrapperinterface by delegating the actual wrapping and unwrapping logic to thegetDelegate()method, which must be implemented by subclasses.Example Usage
{@code public class MyWrapper implements DelegatingWrapper { private final Object delegate; public MyWrapper(Object delegate) { this.delegate = delegate; }- Since:
- 1.0.0
- Author:
- Mercy
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.lang.ObjectgetDelegate()Get the delegatedefault booleanisWrapperFor(java.lang.Class<?> type)Returns true if this either extends or implements the type argument or is directly or indirectly a wrapper for an object that does.default <T> Tunwrap(java.lang.Class<T> type)Returns an object of the given class to allow access to non-standard methods, or standard methods not exposed by the proxy.
-
-
-
Method Detail
-
getDelegate
java.lang.Object getDelegate()
Get the delegate- Returns:
- the delegate
-
unwrap
default <T> T unwrap(java.lang.Class<T> type) throws java.lang.IllegalArgumentExceptionDescription copied from interface:WrapperReturns an object of the given class to allow access to non-standard methods, or standard methods not exposed by the proxy.If the receiver extends or implements the type then the result is the receiver or a proxy for the receiver. If the receiver is a wrapper and the wrapped object extends or implements the type then the result is the wrapped object or a proxy for the wrapped object. Otherwise return the result of calling
unwraprecursively on the wrapped object or a proxy for that result. If the receiver is not a wrapper and does not implement the type, then anIllegalArgumentExceptionis thrown.
-
isWrapperFor
default boolean isWrapperFor(java.lang.Class<?> type)
Description copied from interface:WrapperReturns true if this either extends or implements the type argument or is directly or indirectly a wrapper for an object that does. Returns false otherwise. If this extends or implements the type then return true, else if this is a wrapper then return the result of recursively callingisWrapperForon the wrapped object. If this does not implement the type and is not a wrapper, return false. This method should be implemented as a low-cost operation compared tounwrapso that callers can use this method to avoid expensiveunwrapcalls that may fail. If this method returns true then callingunwrapwith the same argument should succeed.- Specified by:
isWrapperForin interfaceWrapper- Parameters:
type- the wrapped type- Returns:
- true if this extends or implements the type or directly or indirectly wraps an object that does
-
-