|
43 | 43 | */ |
44 | 44 | abstract class AbstractBuilder<R, S> extends GitHubInteractiveObject implements GitHubRequestBuilderDone<R> { |
45 | 45 |
|
46 | | - @Nonnull |
47 | | - private final Class<R> returnType; |
| 46 | + @CheckForNull |
| 47 | + private final R baseInstance; |
48 | 48 |
|
49 | 49 | private final boolean commitChangesImmediately; |
50 | 50 |
|
51 | | - @CheckForNull |
52 | | - private final R baseInstance; |
| 51 | + @Nonnull |
| 52 | + private final Class<R> returnType; |
53 | 53 |
|
54 | 54 | /** The requester. */ |
55 | 55 | @Nonnull |
@@ -111,54 +111,54 @@ public R done() throws IOException { |
111 | 111 | } |
112 | 112 |
|
113 | 113 | /** |
114 | | - * Applies a value to a name for this builder. |
| 114 | + * Chooses whether to return a continuing builder or an updated data record |
115 | 115 | * |
116 | 116 | * If {@code S} is the same as {@code R}, this method will commit changes after the first value change and return a |
117 | 117 | * {@code R} from {@link #done()}. |
118 | 118 | * |
119 | 119 | * If {@code S} is not the same as {@code R}, this method will return an {@code S} and letting the caller batch |
120 | 120 | * together multiple changes and call {@link #done()} when they are ready. |
121 | 121 | * |
122 | | - * @param name |
123 | | - * the name of the field |
124 | | - * @param value |
125 | | - * the value of the field |
126 | 122 | * @return either a continuing builder or an updated data record |
127 | 123 | * @throws IOException |
128 | 124 | * if an I/O error occurs |
129 | 125 | */ |
130 | 126 | @Nonnull |
131 | 127 | @BetaApi |
132 | | - protected S with(@Nonnull String name, Object value) throws IOException { |
133 | | - requester.with(name, value); |
134 | | - return continueOrDone(); |
| 128 | + protected S continueOrDone() throws IOException { |
| 129 | + // This little bit of roughness in this base class means all inheriting builders get to create Updater and |
| 130 | + // Setter classes from almost identical code. Creator can often be implemented with significant code reuse as |
| 131 | + // well. |
| 132 | + if (commitChangesImmediately) { |
| 133 | + // These casts look strange and risky, but they they're actually guaranteed safe due to the return path |
| 134 | + // being based on the previous comparison of class instances passed to the constructor. |
| 135 | + return (S) done(); |
| 136 | + } else { |
| 137 | + return (S) this; |
| 138 | + } |
135 | 139 | } |
136 | 140 |
|
137 | 141 | /** |
138 | | - * Chooses whether to return a continuing builder or an updated data record |
| 142 | + * Applies a value to a name for this builder. |
139 | 143 | * |
140 | 144 | * If {@code S} is the same as {@code R}, this method will commit changes after the first value change and return a |
141 | 145 | * {@code R} from {@link #done()}. |
142 | 146 | * |
143 | 147 | * If {@code S} is not the same as {@code R}, this method will return an {@code S} and letting the caller batch |
144 | 148 | * together multiple changes and call {@link #done()} when they are ready. |
145 | 149 | * |
| 150 | + * @param name |
| 151 | + * the name of the field |
| 152 | + * @param value |
| 153 | + * the value of the field |
146 | 154 | * @return either a continuing builder or an updated data record |
147 | 155 | * @throws IOException |
148 | 156 | * if an I/O error occurs |
149 | 157 | */ |
150 | 158 | @Nonnull |
151 | 159 | @BetaApi |
152 | | - protected S continueOrDone() throws IOException { |
153 | | - // This little bit of roughness in this base class means all inheriting builders get to create Updater and |
154 | | - // Setter classes from almost identical code. Creator can often be implemented with significant code reuse as |
155 | | - // well. |
156 | | - if (commitChangesImmediately) { |
157 | | - // These casts look strange and risky, but they they're actually guaranteed safe due to the return path |
158 | | - // being based on the previous comparison of class instances passed to the constructor. |
159 | | - return (S) done(); |
160 | | - } else { |
161 | | - return (S) this; |
162 | | - } |
| 160 | + protected S with(@Nonnull String name, Object value) throws IOException { |
| 161 | + requester.with(name, value); |
| 162 | + return continueOrDone(); |
163 | 163 | } |
164 | 164 | } |
0 commit comments