
sirius.kernel.di.transformers.Transformable Maven / Gradle / Ivy
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - [email protected]
*/
package sirius.kernel.di.transformers;
import javax.annotation.Nonnull;
import java.util.Optional;
/**
* A class implementing this interface supports the Adapter Pattern.
*
* Using the {@link #as(Class)} method, the object can be casted or transformed to fulfill the requested type.
*/
public interface Transformable {
/**
* Determines if this can be transformed to the given type.
*
* @param type the target type to check for
* @return true if this implements the type already or it can be transformed into the given
* type
*/
boolean is(@Nonnull Class> type);
/**
* Tries to transform this into the given adapterType.
*
* @param adapterType the target type to adapt to
* @param the type of the adapter type
* @return an optional which either contains the adapted value matching the requested adapterType or
* an empty optional if no transformation was possible
*/
@SuppressWarnings("unchecked")
Optional tryAs(@Nonnull Class adapterType);
/**
* Adapts this into the given adapterType.
*
* @param adapterType the target type to adapt to
* @param the type of the adapter type
* @return this adapted to match the requested adapterType
* @throws IllegalArgumentException if no transformation was possible
*/
A as(@Nonnull Class adapterType);
}