All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.openhft.chronicle.testframework.Delegation Maven / Gradle / Ivy

There is a newer version: 2.27ea0
Show newest version
package net.openhft.chronicle.testframework;

import net.openhft.chronicle.testframework.internal.DelegationBuilder;
import org.jetbrains.annotations.NotNull;

import java.util.function.Function;

import static java.util.Objects.requireNonNull;

/**
 * Utility class to build delegator instances that forward method invocations
 * to a specified delegate object. This class facilitates a fluent API for customizing
 * the behavior of the delegator.
 * 

* This class cannot be instantiated. */ public final class Delegation { // Suppresses default constructor, ensuring non-instantiability. private Delegation() { } /** * Creates and returns a new builder for a delegator instance that will use the provided * {@code delegate} as the delegate. Method invocations on the built instance will be delegated to the * provided delegate. * * @param delegate The object to delegate invocations to * @param Provided delegate type * @return New delegator builder * @throws NullPointerException if the provided delegate is {@code null}. */ public static Builder of(@NotNull final D delegate) { requireNonNull(delegate); return new DelegationBuilder<>(delegate); } /** * Interface for building a delegation object. Allows customization of the type view * and the {@code toString()} method of the delegate. * * @param Target type * @param Delegation type */ public interface Builder { // Future: Add capability to override any method using T::method references /** * Specifies the type the delegate should be viewed as. *

* The default view is {@link Object }. * * @param type The class to view the delegate as (non-null) * @param The new type of how the delegate should be viewed * @return This builder, for chaining */ Builder as(Class type); /** * Specifies the {@code toString()} function the view should use. *

* The default view is {@link Object#toString()}. * * @param toStringFunction The function to be applied to the delegate (non-null) * @return This builder, for chaining */ Builder toStringFunction(Function toStringFunction); /** * Creates and returns a new view of type T of the underlying delegate of type D. *

* This method finalizes the builder and returns the configured delegator. * * @return A new view of the delegate */ T build(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy