Package com.linecorp.armeria.common.util
Interface Unwrappable
- All Known Subinterfaces:
Backoff,BlockingWebClient,Client<I,,O> ClientFactory,ClientRequestContext,ConnectionPoolListener,GraphqlService,GrpcService,HttpClient,HttpService,HttpServiceWithRoutes,RequestContext,RequestContextStorage,RestClient,RpcClient,RpcService,RpcServiceWithRoutes,Service<I,,O> ServiceRequestContext,ServiceWithRoutes<I,,O> THttpClient,TransientHttpService,TransientRpcService,TransientService<I,,O> WebClient
- All Known Implementing Classes:
AbstractBackoff,AbstractCircuitBreakerClient,AbstractConcurrencyLimitingClient,AbstractGraphqlService,AbstractHttpService,AbstractRetryingClient,AbstractThrottlingService,AbstractUnaryGrpcService,AbstractUnsafeUnaryGrpcService,AbstractUnwrappable,AuthService,BackoffWrapper,BraveClient,BraveService,CircuitBreakerClient,CircuitBreakerRpcClient,ClientRequestContextWrapper,ConcurrencyLimitingClient,ConnectionPoolListenerAdapter,ConnectionPoolListenerWrapper,ContentPreviewingClient,ContentPreviewingService,CookieClient,CoroutineContextService,CorsService,DecodingClient,DecodingService,DecoratingClient,DecoratingClientFactory,DecoratingService,DocService,EncodingService,FileService,HealthCheckService,JettyService,LoggingClient,LoggingRpcClient,LoggingService,ManagementService,MetricCollectingClient,MetricCollectingRpcClient,MetricCollectingService,OAuth2Client,PrometheusExpositionService,RedirectService,RequestContextStorageWrapper,RequestContextWrapper,ResteasyService,RetryingClient,RetryingRpcClient,ServiceRequestContextWrapper,SimpleDecoratingClient,SimpleDecoratingHttpClient,SimpleDecoratingHttpService,SimpleDecoratingRpcClient,SimpleDecoratingRpcService,SimpleDecoratingService,ThriftCallService,ThrottlingRpcService,ThrottlingService,THttpService,TomcatService,UserClient
public interface Unwrappable
Provides a way to unwrap an object in decorator pattern, similar to down-casting in an inheritance pattern.
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> TUnwraps this object into the object of the specifiedtype.default booleanReference checking thisUnwrappableto anotherUnwrappable, ignoring wrappers.default Unwrappableunwrap()Unwraps this object and returns the object being decorated.default ObjectUnwraps this object and returns the innermost object being decorated.
-
Method Details
-
as
Unwraps this object into the object of the specifiedtype. Use this method instead of an explicit downcast. For example:class Foo {} class Bar<T> extends AbstractWrapper<T> { Bar(T delegate) { super(delegate); } } class Qux<T> extends AbstractWrapper<T> { Qux(T delegate) { super(delegate); } } Qux qux = new Qux(new Bar(new Foo())); Foo foo = qux.as(Foo.class); Bar bar = qux.as(Bar.class);- Parameters:
type- the type of the object to return- Returns:
- the object of the specified
typeif found, ornullif not found.
-
unwrap
Unwraps this object and returns the object being decorated. If thisUnwrappableis the innermost object, this method returns itself. For example:class Foo implements Unwrappable {} class Bar<T extends Unwrappable> extends AbstractUnwrappable<T> { Bar(T delegate) { super(delegate); } } class Qux<T extends Unwrappable> extends AbstractUnwrappable<T> { Qux(T delegate) { super(delegate); } } Foo foo = new Foo(); assert foo.unwrap() == foo; Bar<Foo> bar = new Bar<>(foo); assert bar.unwrap() == foo; Qux<Bar<Foo>> qux = new Qux<>(bar); assert qux.unwrap() == bar; assert qux.unwrap().unwrap() == foo; -
unwrapAll
Unwraps this object and returns the innermost object being decorated. If thisUnwrappableis the innermost object, this method returns itself. For example:class Foo implements Unwrappable {} class Bar<T extends Unwrappable> extends AbstractUnwrappable<T> { Bar(T delegate) { super(delegate); } } class Qux<T extends Unwrappable> extends AbstractUnwrappable<T> { Qux(T delegate) { super(delegate); } } Foo foo = new Foo(); assert foo.unwrapAll() == foo; Bar<Foo> bar = new Bar<>(foo); assert bar.unwrapAll() == foo; Qux<Bar<Foo>> qux = new Qux<>(bar); assert qux.unwrap() == bar; assert qux.unwrapAll() == foo; -
equalsIgnoreWrapper
Reference checking thisUnwrappableto anotherUnwrappable, ignoring wrappers. TwoUnwrappableare considered equal ignoring wrappers if they are of the same object reference afterunwrapAll().- Parameters:
other- TheUnwrappableto compare thisUnwrappableagainst- Returns:
- true if the argument is not
null, and it represents a same object reference afterunwrapAll(), false otherwise.
-