Class AbstractUnwrappable<T extends Unwrappable>

java.lang.Object
com.linecorp.armeria.common.util.AbstractUnwrappable<T>
Type Parameters:
T - the type of the object being decorated
All Implemented Interfaces:
Unwrappable
Direct Known Subclasses:
BackoffWrapper, ConnectionPoolListenerWrapper, DecoratingClient, DecoratingClientFactory, DecoratingService, RequestContextStorageWrapper, UserClient

public abstract class AbstractUnwrappable<T extends Unwrappable>
extends Object
implements Unwrappable
Skeletal Unwrappable implementation.
  • Constructor Details

    • AbstractUnwrappable

      protected AbstractUnwrappable​(T delegate)
      Creates a new decorator with the specified delegate.
  • Method Details

    • as

      public final <U> U as​(Class<U> type)
      Description copied from interface: Unwrappable
      Unwraps this object into the object of the specified type. 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);
       
      Specified by:
      as in interface Unwrappable
      Parameters:
      type - the type of the object to return
      Returns:
      the object of the specified type if found, or null if not found.
    • unwrap

      public T unwrap()
      Description copied from interface: Unwrappable
      Unwraps this object and returns the object being decorated. If this Unwrappable is 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;
       
      Specified by:
      unwrap in interface Unwrappable
    • toString

      public String toString()
      Overrides:
      toString in class Object