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

Method build

output/java_guava/1.4.17/ImmutableBiMap.java:231–255  ·  view source on GitHub ↗

Returns a newly-created immutable bimap. @throws IllegalArgumentException if duplicate keys or values were added

()

Source from the content-addressed store, hash-verified

229 */
230
231 @Override
232 public ImmutableBiMap<K, V> build() {
233 switch (size) {
234 case 0:
235 return of();
236 case 1:
237 return of(entries[0].getKey(), entries[0].getValue());
238 default:
239 /*
240 * If entries is full, then this implementation may end up using the entries array
241 * directly and writing over the entry objects with non-terminal entries, but this is
242 * safe; if this Builder is used further, it will grow the entries array (so it can't
243 * affect the original array), and future build() calls will always copy any entry
244 * objects that cannot be safely reused.
245 */
246 if (valueComparator != null) {
247 if (entriesUsed) {
248 entries = ObjectArrays.arraysCopyOf(entries, size);
249 }
250 Arrays.sort(entries, 0, size, Ordering.from(valueComparator).onResultOf(Maps.<V>valueFunction()));
251 }
252 entriesUsed = size == entries.length;
253 return RegularImmutableBiMap.fromEntryArray(size, entries);
254 }
255 }
256 }
257
258 /**

Callers

nothing calls this directly

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