-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make generateModelBuilder generate deep builders (instead of shallow)
For each builder generate additional setter with `Consumer<*.Builder>` as an argument: ``` public Builder hero(@nonnull Consumer<Hero.Builder> mutator) { Hero.Builder builder = this.hero != null ? this.hero.toBuilder() : Hero.builder(); mutator.accept(builder); this.hero = builder.build(); return this; } ``` That will allow user to do next: ``` data.toBuilder() .hero(someHero) // or .hero(new Consumer<>() { void accept(Hero.Builder builder) { builder.name("Joe") .age(31) } }) ``` This will be even better with lambda support: ``` data.toBuilder() .hero(someHero) // or .hero(builder -> builder .name("Joe") .age(31) } }) ``` Closes #643
- Loading branch information
Showing
9 changed files
with
273 additions
and
35 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
apollo-api/src/main/java/com/apollographql/apollo/api/internal/Consumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.apollographql.apollo.api.internal; | ||
|
||
/** | ||
* Represents an operation that accepts a single input argument and returns no result. Unlike most other functional | ||
* interfaces, {@code Consumer} is expected to operate via side-effects. | ||
* | ||
* <p>This is a <a href="package-summary.html">functional interface</a> whose functional method is {@link | ||
* #accept(Object)}. | ||
* | ||
* @param <T> the type of the input to the operation | ||
*/ | ||
public interface Consumer<T> { | ||
|
||
/** | ||
* Performs this operation on the given argument. | ||
* | ||
* @param t the input argument | ||
*/ | ||
void accept(T t); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.