Returns a newly-created immutable bimap. @throws IllegalArgumentException if duplicate keys or values were added
()
| 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 | /** |
nothing calls this directly
no test coverage detected