    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 *      http://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
    019/**
    020 * <p>
    021 * The Builder interface is designed to designate a class as a <em>builder</em>
    022 * object in the Builder design pattern. Builders are capable of creating and
    023 * configuring objects or results that normally take multiple steps to construct
    024 * or are very complex to derive.
    025 * </p>
    026 *
    027 * <p>
    028 * The builder interface defines a single method, {@link #build()}, that
    029 * classes must implement. The result of this method should be the final
    030 * configured object or result after all building operations are performed.
    031 * </p>
    032 *
    033 * <p>
    034 * It is a recommended practice that the methods supplied to configure the
    035 * object or result being built return a reference to {@code this} so that
    036 * method calls can be chained together.
    037 * </p>
    038 *
    039 * <p>
    040 * Example Builder:
    041 * </p>
    042 * <pre><code>
    043 * class FontBuilder implements Builder&lt;Font&gt; {
    044 *     private Font font;
    045 *
    046 *     public FontBuilder(String fontName) {
    047 *         this.font = new Font(fontName, Font.PLAIN, 12);
    048 *     }
    049 *
    050 *     public FontBuilder bold() {
    051 *         this.font = this.font.deriveFont(Font.BOLD);
    052 *         return this; // Reference returned so calls can be chained
    053 *     }
    054 *
    055 *     public FontBuilder size(float pointSize) {
    056 *         this.font = this.font.deriveFont(pointSize);
    057 *         return this; // Reference returned so calls can be chained
    058 *     }
    059 *
    060 *     // Other Font construction methods
    061 *
    062 *     public Font build() {
    063 *         return this.font;
    064 *     }
    065 * }
    066 * </code></pre>
    067 *
    068 * Example Builder Usage:
    069 * <pre><code>
    070 * Font bold14ptSansSerifFont = new FontBuilder(Font.SANS_SERIF).bold()
    071 *                                                              .size(14.0f)
    072 *                                                              .build();
    073 * </code></pre>
    074 *
    075 *
    076 * @param <T> the type of object that the builder will construct or compute.
    077 * @since 1.0
    078 *
    079 */
    080public interface Builder<T> {
    081
    082    /**
    083     * Returns a reference to the object being constructed or result being
    084     * calculated by the builder.
    085     *
    086     * @return The object constructed or result calculated by the builder.
    087     */
    088    T build();
    089}