MCPcopy Create free account
hub / github.com/antlr/codebuff / build

Method build

output/java_guava/1.4.18/ImmutableMap.java:296–319  ·  view source on GitHub ↗

Returns a newly-created immutable map. @throws IllegalArgumentException if duplicate keys were added

()

Source from the content-addressed store, hash-verified

294
295
296 public ImmutableMap<K, V> build() {
297 switch (size) {
298 case 0:
299 return of();
300 case 1:
301 return of(entries[0].getKey(), entries[0].getValue());
302 default:
303 /*
304 * If entries is full, then this implementation may end up using the entries array
305 * directly and writing over the entry objects with non-terminal entries, but this is
306 * safe; if this Builder is used further, it will grow the entries array (so it can't
307 * affect the original array), and future build() calls will always copy any entry
308 * objects that cannot be safely reused.
309 */
310 if (valueComparator != null) {
311 if (entriesUsed) {
312 entries = ObjectArrays.arraysCopyOf(entries, size);
313 }
314 Arrays.sort(entries, 0, size, Ordering.from(valueComparator).onResultOf(Maps.<V>valueFunction()));
315 }
316 entriesUsed = size == entries.length;
317 return RegularImmutableMap.fromEntryArray(size, entries);
318 }
319 }
320 }
321
322 /**

Callers 1

createMapMethod · 0.45

Calls 9

arraysCopyOfMethod · 0.95
fromMethod · 0.95
valueFunctionMethod · 0.95
fromEntryArrayMethod · 0.95
sortMethod · 0.80
getKeyMethod · 0.65
getValueMethod · 0.65
ofMethod · 0.45
onResultOfMethod · 0.45

Tested by

no test coverage detected