This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push: new f01c32850 Javadoc f01c32850 is described below commit f01c32850373d7c80fa77165162fdd8c22f15b96 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Mon Oct 7 21:14:47 2024 -0400 Javadoc --- .../apache/commons/io/build/AbstractSupplier.java | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/main/java/org/apache/commons/io/build/AbstractSupplier.java b/src/main/java/org/apache/commons/io/build/AbstractSupplier.java index bfbeabad0..61216033e 100644 --- a/src/main/java/org/apache/commons/io/build/AbstractSupplier.java +++ b/src/main/java/org/apache/commons/io/build/AbstractSupplier.java @@ -21,6 +21,99 @@ import org.apache.commons.io.function.IOSupplier; /** * Abstracts supplying an instance of {@code T}. Use to implement the builder pattern. + * <p> + * For example, here is a builder, a domain class, and a test. + * </p> + * <p> + * The builder: + * </p> + * <pre> + ∕** + * Builds Foo instances. + *∕ + public static class Builder extends AbstractSupplier<Foo, Builder> { + + private String bar1; + private String bar2; + private String bar3; + + ∕** + * Builds a new Foo. + *∕ + @Override + public Foo get() { + return new Foo(bar1, bar2, bar3); + } + + public Builder setBar1(final String bar1) { + this.bar1 = bar1; + return this; + } + + public Builder setBar2(final String bar2) { + this.bar2 = bar2; + return this; + } + + public Builder setBar3(final String bar3) { + this.bar3 = bar3; + return this; + } + } + * </pre> + * <p> + * The domain class: + * </p> + * <pre> + ∕** + * Domain class. + *∕ + public class Foo { + + public static Builder builder() { + return new Builder(); + } + + private final String bar1; + private final String bar2; + private final String bar3; + + private Foo(final String bar1, final String bar2, final String bar3) { + this.bar1 = bar1; + this.bar2 = bar2; + this.bar3 = bar3; + } + + public String getBar1() { + return bar1; + } + + public String getBar2() { + return bar2; + } + + public String getBar3() { + return bar3; + } + + } + * </pre> + * <p> + * The test: + * </p> + * <pre> + @Test + public void test() { + final Foo foo = Foo.builder() + .setBar1("value1") + .setBar2("value2") + .setBar3("value3") + .get(); + assertEquals("value1", foo.getBar1()); + assertEquals("value2", foo.getBar2()); + assertEquals("value3", foo.getBar3()); + } + * </pre> * * @param <T> the type of instances to build. * @param <B> the type of builder subclass.