Committed by
Gerrit Code Review
Add helper to build DefaultAnnotations based on existing Annotations
Change-Id: Ibbc598f90888aa60dc32ed84a79bda4d4cc615ff
Showing
1 changed file
with
28 additions
and
0 deletions
... | @@ -218,6 +218,34 @@ public final class DefaultAnnotations implements SparseAnnotations { | ... | @@ -218,6 +218,34 @@ public final class DefaultAnnotations implements SparseAnnotations { |
218 | } | 218 | } |
219 | 219 | ||
220 | /** | 220 | /** |
221 | + * Adds all specified annotation. Any previous value associated with | ||
222 | + * the given annotations will be overwritten. | ||
223 | + * | ||
224 | + * @param base annotations | ||
225 | + * @return self | ||
226 | + */ | ||
227 | + public Builder putAll(Annotations base) { | ||
228 | + if (base instanceof DefaultAnnotations) { | ||
229 | + builder.putAll(((DefaultAnnotations) base).map); | ||
230 | + | ||
231 | + } else if (base instanceof SparseAnnotations) { | ||
232 | + final SparseAnnotations sparse = (SparseAnnotations) base; | ||
233 | + for (String key : base.keys()) { | ||
234 | + if (sparse.isRemoved(key)) { | ||
235 | + remove(key); | ||
236 | + } else { | ||
237 | + set(key, base.value(key)); | ||
238 | + } | ||
239 | + } | ||
240 | + | ||
241 | + } else { | ||
242 | + base.keys().forEach(key -> set(key, base.value(key))); | ||
243 | + | ||
244 | + } | ||
245 | + return this; | ||
246 | + } | ||
247 | + | ||
248 | + /** | ||
221 | * Adds the specified annotation. Any previous value associated with | 249 | * Adds the specified annotation. Any previous value associated with |
222 | * the given annotation key will be overwritten. | 250 | * the given annotation key will be overwritten. |
223 | * | 251 | * | ... | ... |
-
Please register or login to post a comment