    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      https://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.text;
    018
    019import java.util.function.Supplier;
    020
    021/**
    022 * Duplicates the functionality of {@link Supplier}.
    023 * <p>
    024 * Defines a class as a <em>builder</em> following the Builder design pattern. Builders are capable of creating and configuring objects or results that normally
    025 * take multiple steps to construct or are very complex to derive.
    026 * </p>
    027 * <p>
    028 * The builder interface defines a single method, {@link #get()}, that classes must implement. The result of this method should be the final configured object
    029 * or result after all building operations are performed.
    030 * </p>
    031 * <p>
    032 * It is a recommended practice that the methods supplied to configure the object or result being built return a reference to {@code this} so that method calls
    033 * can be chained together.
    034 * </p>
    035 *
    036 * <p>
    037 * Example Builder:
    038 * </p>
    039 *
    040 * <pre>
    041 * <code>
    042 * class FontBuilder implements Builder&lt;Font&gt; {
    043 *     private Font font;
    044 *
    045 *     public FontBuilder(String fontName) {
    046 *         this.font = new Font(fontName, Font.PLAIN, 12);
    047 *     }
    048 *
    049 *     public FontBuilder bold() {
    050 *         this.font = this.font.deriveFont(Font.BOLD);
    051 *         return this; // Reference returned so calls can be chained
    052 *     }
    053 *
    054 *     public FontBuilder size(float pointSize) {
    055 *         this.font = this.font.deriveFont(pointSize);
    056 *         return this; // Reference returned so calls can be chained
    057 *     }
    058 *
    059 *     // Other Font construction methods
    060 *
    061 *     public Font build() {
    062 *         return this.font;
    063 *     }
    064 * }
    065 * </code>
    066 * </pre>
    067 *
    068 * Example Builder Usage:
    069 *
    070 * <pre>
    071 * {@code
    072 * Font bold14ptSansSerifFont = new FontBuilder(Font.SANS_SERIF)
    073 *      .bold()
    074 *      .size(14.0f)
    075 *      .get();
    076 * }
    077 * </pre>
    078 *
    079 *
    080 * @param <T> the type of object that the builder will construct or compute.
    081 * @since 1.0
    082 * @see Supplier
    083 * @deprecated Use {@link Supplier}.
    084 */
    085@Deprecated
    086public interface Builder<T> extends Supplier<T> {
    087
    088    /**
    089     * Returns a reference to the object being constructed or result being calculated by the builder.
    090     *
    091     * @return The object constructed or result calculated by the builder.
    092     */
    093    T build();
    094
    095}