1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.text;
18
19 import java.util.function.Supplier;
20
21 /**
22 * Duplicates the functionality of {@link Supplier}.
23 * <p>
24 * 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
25 * take multiple steps to construct or are very complex to derive.
26 * </p>
27 * <p>
28 * The builder interface defines a single method, {@link #get()}, that classes must implement. The result of this method should be the final configured object
29 * or result after all building operations are performed.
30 * </p>
31 * <p>
32 * 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
33 * can be chained together.
34 * </p>
35 *
36 * <p>
37 * Example Builder:
38 * </p>
39 *
40 * <pre>
41 * <code>
42 * class FontBuilder implements Builder<Font> {
43 * private Font font;
44 *
45 * public FontBuilder(String fontName) {
46 * this.font = new Font(fontName, Font.PLAIN, 12);
47 * }
48 *
49 * public FontBuilder bold() {
50 * this.font = this.font.deriveFont(Font.BOLD);
51 * return this; // Reference returned so calls can be chained
52 * }
53 *
54 * public FontBuilder size(float pointSize) {
55 * this.font = this.font.deriveFont(pointSize);
56 * return this; // Reference returned so calls can be chained
57 * }
58 *
59 * // Other Font construction methods
60 *
61 * public Font build() {
62 * return this.font;
63 * }
64 * }
65 * </code>
66 * </pre>
67 *
68 * Example Builder Usage:
69 *
70 * <pre>
71 * {@code
72 * Font bold14ptSansSerifFont = new FontBuilder(Font.SANS_SERIF)
73 * .bold()
74 * .size(14.0f)
75 * .get();
76 * }
77 * </pre>
78 *
79 *
80 * @param <T> the type of object that the builder will construct or compute.
81 * @since 1.0
82 * @see Supplier
83 * @deprecated Use :@link Supplier}.
84 */
85 @Deprecated
86 public interface Builder<T> extends Supplier<T> {
87
88 /**
89 * Returns a reference to the object being constructed or result being calculated by the builder.
90 *
91 * @return The object constructed or result calculated by the builder.
92 */
93 T build();
94
95 }