Re: Complex Example

34 views
Skip to first unread message

Chris Purcell

unread,
Sep 24, 2016, 7:08:58 PM9/24/16
to arbei...@gmail.com, FreeBuilder
Sorry for the delay! You won't get a getBarBuilder() if bar is a List<Bar>. Instead, you'll need to write code like:

Foo foo = new Foo.Builder()
        .addBar(new Foo.Bar.Builder()
                .addBaz(new Foo.Bar.Baz.Builder().setBlah("Blaah1").build())
                .build())
        .addBar(new Foo.Bar.Builder()
                .addBaz(new Foo.Bar.Baz.Builder().setBlah("Blaah2").build())
                .addBaz(new Foo.Bar.Baz.Builder().setBlah("Blaah2").build())
                .build())
        .build();

Cheers,
Chris

N.B. Issue #8 has been open for a while now, but if that gets addressed, you'd be able to drop many of those build() calls.

On Wed, 21 Sep 2016 at 09:58 <arbei...@gmail.com> wrote:
Hi.
The documentation is very nice and easy to understand.

We want to use FreeBuilder for a complex use case nested class design in Eclipse and Maven (incremental-build false).
I can not find an example for such a Szenario.
How would you explain or maybe there is a good documentation?

I create a Interface like this for my classes:

I get the set, remove, mutate, merge, add, clear  methods.
I dont get a method java new Foo.Builder().getBarBuilder();

To take theabove linked code and do some more complex code with lists:

@FreeBuilder
public interface Foo {
  List<Bar> getBar();
  static class Builder extends Foo_Builder() {}
  @FreeBuilder
  public interface Bar {
   List<Baz> getBaz();
   static class Builder extends Foo_Bar_Builder() {}

  @FreeBuilder
  public interface Baz{
   String getBlah();
   static class Builder extends Foo_Bar_Baz_Builder() {}
  }
  }


}

Is FreeBuilder to use with Method Chaining or Parameter?
From the examples I read i think it could be written in this way?

Foo foo = new foo.Builder()
            .addBar(getBarBuilder.addBaz(bar.getBazBuilder().setBlah("Blaah1")
            .addBar(getBarBuilder
                  .addBaz(bar.getBazBuilder().setBlah("Blaah2")
                  .addBaz(bar.getBazBuilder().setBlah("Blaah2")
             .build();

To complete my question Why I dont get nested builder and How should i use FreeBuilder for this case?

Thanks you a lot!

--
You received this message because you are subscribed to the Google Groups "FreeBuilder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to freebuilder...@googlegroups.com.
To post to this group, send email to freeb...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/freebuilder/84855d61-c68a-4fcd-ba7b-f950299f7d11%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages