@CanIgnoreReturnValue Builder<K, V> combine(Builder<K, V> other) { checkNotNull(other); ensureCapacity(this.size + other.size); System.arraycopy(other.entries, 0, this.entries, this.size, other.size); this.size += other.size; return this; }
/** * Adds all of the given entries to the built map. Duplicate keys are not * allowed, and will cause {@link #build} to fail. * * @throws NullPointerException if any key, value, or entry is null * @since 19.0 */ @CanIgnoreReturnValue @Beta public Builder<K, V> putAll(Iterable<? extends Entry<? extends K, ? extends V>> entries) { if (entries instanceof Collection) { ensureCapacity(size + ((Collection<?>) entries).size()); } for (Entry<? extends K, ? extends V> entry : entries) { put(entry); } return this; }
/** * Associates {@code key} with {@code value} in the built map. Duplicate * keys are not allowed, and will cause {@link #build} to fail. */ @CanIgnoreReturnValue public Builder<K, V> put(K key, V value) { ensureCapacity(size + 1); Entry<K, V> entry = entryOf(key, value); // don't inline this: we want to fail atomically if key or value is null entries[size++] = entry; return this; }