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

Method build

output/java_guava/1.4.19/ImmutableMap.java:297–320  ·  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

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

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