package net.openhft.chronicle.core.util;

import org.jetbrains.annotations.NotNull;

import java.util.function.Supplier;

/**
 * A Builder is a configurable Supplier which always creates a new object.
 *
 * @param <T> Of object created
 */
public interface Builder<T> extends Supplier<T> {
    @NotNull
    T build();

    @Override
    @NotNull
    default T get() {
        return build();
    }
}

package net.openhft.chronicle.core.util;

import org.jetbrains.annotations.NotNull;

import java.util.function.Supplier;

/**
 * A Builder of type T is a configurable object that can provide
 * another non-null instance of type T.
 *
 * @param <T> of object provided
 */
@FunctionalInterface
public interface Builder<T> extends Supplier<T> {

    /**
     * Builds and returns a non-null instance of type T.
     * <p>
     * The builder always creates a new instance if the
     * instance is mutable. If the instance is immutable,
     * the builder may create a new instance or it may return
     * a previously existing instance at its own discretion.
     * <p>
     * As opposed to a factory, a Builder is often unipotent
     * meaning that this method can be invoked at most one time.
     *
     * @return a non-null instance of type T
     *
     * @throws IllegalStateException if the builder is unipotent
     * and this method is invoked more than once.
     */
    @NotNull
    T build();

    @Override
    @NotNull
    @Deprecated // For removal now
    default T get() {
        return build();
    }
}

Improve Builder doc and deprecate get(), work on #185