001/* 002 * Copyright (C) 2009 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.google.common.collect; 018 019import static com.google.common.base.Preconditions.checkNotNull; 020 021import com.google.common.annotations.Beta; 022import com.google.common.annotations.GwtCompatible; 023import com.google.common.annotations.GwtIncompatible; 024import com.google.common.base.MoreObjects; 025import com.google.common.base.Preconditions; 026import com.google.errorprone.annotations.CanIgnoreReturnValue; 027import com.google.errorprone.annotations.concurrent.LazyInit; 028import com.google.j2objc.annotations.RetainedWith; 029import com.google.j2objc.annotations.Weak; 030import java.io.IOException; 031import java.io.InvalidObjectException; 032import java.io.ObjectInputStream; 033import java.io.ObjectOutputStream; 034import java.util.Arrays; 035import java.util.Collection; 036import java.util.Comparator; 037import java.util.List; 038import java.util.Map.Entry; 039import java.util.function.Function; 040import java.util.stream.Collector; 041import java.util.stream.Collectors; 042import java.util.stream.Stream; 043import javax.annotation.Nullable; 044 045/** 046 * A {@link SetMultimap} whose contents will never change, with many other important properties 047 * detailed at {@link ImmutableCollection}. 048 * 049 * <p>See the Guava User Guide article on <a href= 050 * "https://github.com/google/guava/wiki/ImmutableCollectionsExplained"> 051 * immutable collections</a>. 052 * 053 * @author Mike Ward 054 * @since 2.0 055 */ 056@GwtCompatible(serializable = true, emulated = true) 057public class ImmutableSetMultimap<K, V> extends ImmutableMultimap<K, V> 058 implements SetMultimap<K, V> { 059 /** 060 * Returns a {@link Collector} that accumulates elements into an {@code ImmutableSetMultimap} 061 * whose keys and values are the result of applying the provided mapping functions to the input 062 * elements. 063 * 064 * <p>For streams with {@linkplain java.util.stream#Ordering defined encounter order}, that order 065 * is preserved, but entries are <a href="ImmutableMultimap.html#iteration">grouped by key</a>. 066 * 067 * Example: 068 * <pre> {@code 069 * 070 * static final Multimap<Character, String> FIRST_LETTER_MULTIMAP = 071 * Stream.of("banana", "apple", "carrot", "asparagus", "cherry") 072 * .collect(toImmutableSetMultimap(str -> str.charAt(0), str -> str.substring(1))); 073 * 074 * // is equivalent to 075 * 076 * static final Multimap<Character, String> FIRST_LETTER_MULTIMAP = 077 * new ImmutableSetMultimap.Builder<Character, String>() 078 * .put('b', "anana") 079 * .putAll('a', "pple", "sparagus") 080 * .putAll('c', "arrot", "herry") 081 * .build();}</pre> 082 * @since 21.0 083 */ 084 @Beta 085 public static <T, K, V> Collector<T, ?, ImmutableSetMultimap<K, V>> toImmutableSetMultimap( 086 Function<? super T, ? extends K> keyFunction, 087 Function<? super T, ? extends V> valueFunction) { 088 checkNotNull(keyFunction, "keyFunction"); 089 checkNotNull(valueFunction, "valueFunction"); 090 return Collector.of( 091 ImmutableSetMultimap::<K, V>builder, 092 (builder, t) -> builder.put(keyFunction.apply(t), valueFunction.apply(t)), 093 ImmutableSetMultimap.Builder::combine, 094 ImmutableSetMultimap.Builder::build); 095 } 096 097 /** 098 * Returns a {@code Collector} accumulating entries into an {@code ImmutableSetMultimap}. Each 099 * input element is mapped to a key and a stream of values, each of which are put into the 100 * resulting {@code Multimap}, in the encounter order of the stream and the encounter order of the 101 * streams of values. 102 * 103 * <p>Example: 104 * 105 * <pre>{@code 106 * static final ImmutableSetMultimap<Character, Character> FIRST_LETTER_MULTIMAP = 107 * Stream.of("banana", "apple", "carrot", "asparagus", "cherry") 108 * .collect( 109 * flatteningToImmutableSetMultimap( 110 * str -> str.charAt(0), 111 * str -> str.substring(1).chars().mapToObj(c -> (char) c)); 112 * 113 * // is equivalent to 114 * 115 * static final ImmutableSetMultimap<Character, Character> FIRST_LETTER_MULTIMAP = 116 * ImmutableSetMultimap.<Character, Character>builder() 117 * .putAll('b', Arrays.asList('a', 'n', 'a', 'n', 'a')) 118 * .putAll('a', Arrays.asList('p', 'p', 'l', 'e')) 119 * .putAll('c', Arrays.asList('a', 'r', 'r', 'o', 't')) 120 * .putAll('a', Arrays.asList('s', 'p', 'a', 'r', 'a', 'g', 'u', 's')) 121 * .putAll('c', Arrays.asList('h', 'e', 'r', 'r', 'y')) 122 * .build(); 123 * 124 * // after deduplication, the resulting multimap is equivalent to 125 * 126 * static final ImmutableSetMultimap<Character, Character> FIRST_LETTER_MULTIMAP = 127 * ImmutableSetMultimap.<Character, Character>builder() 128 * .putAll('b', Arrays.asList('a', 'n')) 129 * .putAll('a', Arrays.asList('p', 'l', 'e', 's', 'a', 'r', 'g', 'u')) 130 * .putAll('c', Arrays.asList('a', 'r', 'o', 't', 'h', 'e', 'y')) 131 * .build(); 132 * } 133 * }</pre> 134 * 135 * @since 21.0 136 */ 137 @Beta 138 public static <T, K, V> 139 Collector<T, ?, ImmutableSetMultimap<K, V>> flatteningToImmutableSetMultimap( 140 Function<? super T, ? extends K> keyFunction, 141 Function<? super T, ? extends Stream<? extends V>> valuesFunction) { 142 checkNotNull(keyFunction); 143 checkNotNull(valuesFunction); 144 return Collectors.collectingAndThen( 145 Multimaps.flatteningToMultimap( 146 input -> checkNotNull(keyFunction.apply(input)), 147 input -> valuesFunction.apply(input).peek(Preconditions::checkNotNull), 148 MultimapBuilder.linkedHashKeys().linkedHashSetValues()::<K, V>build), 149 ImmutableSetMultimap::copyOf); 150 } 151 152 /** Returns the empty multimap. */ 153 // Casting is safe because the multimap will never hold any elements. 154 @SuppressWarnings("unchecked") 155 public static <K, V> ImmutableSetMultimap<K, V> of() { 156 return (ImmutableSetMultimap<K, V>) EmptyImmutableSetMultimap.INSTANCE; 157 } 158 159 /** 160 * Returns an immutable multimap containing a single entry. 161 */ 162 public static <K, V> ImmutableSetMultimap<K, V> of(K k1, V v1) { 163 ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder(); 164 builder.put(k1, v1); 165 return builder.build(); 166 } 167 168 /** 169 * Returns an immutable multimap containing the given entries, in order. 170 * Repeated occurrences of an entry (according to {@link Object#equals}) after 171 * the first are ignored. 172 */ 173 public static <K, V> ImmutableSetMultimap<K, V> of(K k1, V v1, K k2, V v2) { 174 ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder(); 175 builder.put(k1, v1); 176 builder.put(k2, v2); 177 return builder.build(); 178 } 179 180 /** 181 * Returns an immutable multimap containing the given entries, in order. 182 * Repeated occurrences of an entry (according to {@link Object#equals}) after 183 * the first are ignored. 184 */ 185 public static <K, V> ImmutableSetMultimap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) { 186 ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder(); 187 builder.put(k1, v1); 188 builder.put(k2, v2); 189 builder.put(k3, v3); 190 return builder.build(); 191 } 192 193 /** 194 * Returns an immutable multimap containing the given entries, in order. 195 * Repeated occurrences of an entry (according to {@link Object#equals}) after 196 * the first are ignored. 197 */ 198 public static <K, V> ImmutableSetMultimap<K, V> of( 199 K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { 200 ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder(); 201 builder.put(k1, v1); 202 builder.put(k2, v2); 203 builder.put(k3, v3); 204 builder.put(k4, v4); 205 return builder.build(); 206 } 207 208 /** 209 * Returns an immutable multimap containing the given entries, in order. 210 * Repeated occurrences of an entry (according to {@link Object#equals}) after 211 * the first are ignored. 212 */ 213 public static <K, V> ImmutableSetMultimap<K, V> of( 214 K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { 215 ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder(); 216 builder.put(k1, v1); 217 builder.put(k2, v2); 218 builder.put(k3, v3); 219 builder.put(k4, v4); 220 builder.put(k5, v5); 221 return builder.build(); 222 } 223 224 // looking for of() with > 5 entries? Use the builder instead. 225 226 /** 227 * Returns a new {@link Builder}. 228 */ 229 public static <K, V> Builder<K, V> builder() { 230 return new Builder<>(); 231 } 232 233 /** 234 * A builder for creating immutable {@code SetMultimap} instances, especially 235 * {@code public static final} multimaps ("constant multimaps"). Example: 236 * <pre> {@code 237 * 238 * static final Multimap<String, Integer> STRING_TO_INTEGER_MULTIMAP = 239 * new ImmutableSetMultimap.Builder<String, Integer>() 240 * .put("one", 1) 241 * .putAll("several", 1, 2, 3) 242 * .putAll("many", 1, 2, 3, 4, 5) 243 * .build();}</pre> 244 * 245 * <p>Builder instances can be reused; it is safe to call {@link #build} multiple 246 * times to build multiple multimaps in series. Each multimap contains the 247 * key-value mappings in the previously created multimaps. 248 * 249 * @since 2.0 250 */ 251 public static final class Builder<K, V> extends ImmutableMultimap.Builder<K, V> { 252 /** 253 * Creates a new builder. The returned builder is equivalent to the builder 254 * generated by {@link ImmutableSetMultimap#builder}. 255 */ 256 public Builder() { 257 super(MultimapBuilder.linkedHashKeys().linkedHashSetValues().<K, V>build()); 258 } 259 260 /** 261 * Adds a key-value mapping to the built multimap if it is not already 262 * present. 263 */ 264 @CanIgnoreReturnValue 265 @Override 266 public Builder<K, V> put(K key, V value) { 267 builderMultimap.put(checkNotNull(key), checkNotNull(value)); 268 return this; 269 } 270 271 /** 272 * Adds an entry to the built multimap if it is not already present. 273 * 274 * @since 11.0 275 */ 276 @CanIgnoreReturnValue 277 @Override 278 public Builder<K, V> put(Entry<? extends K, ? extends V> entry) { 279 builderMultimap.put(checkNotNull(entry.getKey()), checkNotNull(entry.getValue())); 280 return this; 281 } 282 283 /** 284 * {@inheritDoc} 285 * 286 * @since 19.0 287 */ 288 @CanIgnoreReturnValue 289 @Beta 290 @Override 291 public Builder<K, V> putAll(Iterable<? extends Entry<? extends K, ? extends V>> entries) { 292 super.putAll(entries); 293 return this; 294 } 295 296 @CanIgnoreReturnValue 297 @Override 298 public Builder<K, V> putAll(K key, Iterable<? extends V> values) { 299 Collection<V> collection = builderMultimap.get(checkNotNull(key)); 300 for (V value : values) { 301 collection.add(checkNotNull(value)); 302 } 303 return this; 304 } 305 306 @CanIgnoreReturnValue 307 @Override 308 public Builder<K, V> putAll(K key, V... values) { 309 return putAll(key, Arrays.asList(values)); 310 } 311 312 @CanIgnoreReturnValue 313 @Override 314 public Builder<K, V> putAll(Multimap<? extends K, ? extends V> multimap) { 315 for (Entry<? extends K, ? extends Collection<? extends V>> entry : 316 multimap.asMap().entrySet()) { 317 putAll(entry.getKey(), entry.getValue()); 318 } 319 return this; 320 } 321 322 @CanIgnoreReturnValue 323 @Override 324 Builder<K, V> combine(ImmutableMultimap.Builder<K, V> other) { 325 super.combine(other); 326 return this; 327 } 328 329 /** 330 * {@inheritDoc} 331 * 332 * @since 8.0 333 */ 334 @CanIgnoreReturnValue 335 @Override 336 public Builder<K, V> orderKeysBy(Comparator<? super K> keyComparator) { 337 this.keyComparator = checkNotNull(keyComparator); 338 return this; 339 } 340 341 /** 342 * Specifies the ordering of the generated multimap's values for each key. 343 * 344 * <p>If this method is called, the sets returned by the {@code get()} 345 * method of the generated multimap and its {@link Multimap#asMap()} view 346 * are {@link ImmutableSortedSet} instances. However, serialization does not 347 * preserve that property, though it does maintain the key and value 348 * ordering. 349 * 350 * @since 8.0 351 */ 352 // TODO: Make serialization behavior consistent. 353 @CanIgnoreReturnValue 354 @Override 355 public Builder<K, V> orderValuesBy(Comparator<? super V> valueComparator) { 356 super.orderValuesBy(valueComparator); 357 return this; 358 } 359 360 /** 361 * Returns a newly-created immutable set multimap. 362 */ 363 @Override 364 public ImmutableSetMultimap<K, V> build() { 365 if (keyComparator != null) { 366 Multimap<K, V> sortedCopy = 367 MultimapBuilder.linkedHashKeys().linkedHashSetValues().<K, V>build(); 368 List<Entry<K, Collection<V>>> entries = 369 Ordering.from(keyComparator) 370 .<K>onKeys() 371 .immutableSortedCopy(builderMultimap.asMap().entrySet()); 372 for (Entry<K, Collection<V>> entry : entries) { 373 sortedCopy.putAll(entry.getKey(), entry.getValue()); 374 } 375 builderMultimap = sortedCopy; 376 } 377 return copyOf(builderMultimap, valueComparator); 378 } 379 } 380 381 /** 382 * Returns an immutable set multimap containing the same mappings as 383 * {@code multimap}. The generated multimap's key and value orderings 384 * correspond to the iteration ordering of the {@code multimap.asMap()} view. 385 * Repeated occurrences of an entry in the multimap after the first are 386 * ignored. 387 * 388 * <p>Despite the method name, this method attempts to avoid actually copying 389 * the data when it is safe to do so. The exact circumstances under which a 390 * copy will or will not be performed are undocumented and subject to change. 391 * 392 * @throws NullPointerException if any key or value in {@code multimap} is 393 * null 394 */ 395 public static <K, V> ImmutableSetMultimap<K, V> copyOf( 396 Multimap<? extends K, ? extends V> multimap) { 397 return copyOf(multimap, null); 398 } 399 400 private static <K, V> ImmutableSetMultimap<K, V> copyOf( 401 Multimap<? extends K, ? extends V> multimap, Comparator<? super V> valueComparator) { 402 checkNotNull(multimap); // eager for GWT 403 if (multimap.isEmpty() && valueComparator == null) { 404 return of(); 405 } 406 407 if (multimap instanceof ImmutableSetMultimap) { 408 @SuppressWarnings("unchecked") // safe since multimap is not writable 409 ImmutableSetMultimap<K, V> kvMultimap = (ImmutableSetMultimap<K, V>) multimap; 410 if (!kvMultimap.isPartialView()) { 411 return kvMultimap; 412 } 413 } 414 415 ImmutableMap.Builder<K, ImmutableSet<V>> builder = 416 new ImmutableMap.Builder<>(multimap.asMap().size()); 417 int size = 0; 418 419 for (Entry<? extends K, ? extends Collection<? extends V>> entry : 420 multimap.asMap().entrySet()) { 421 K key = entry.getKey(); 422 Collection<? extends V> values = entry.getValue(); 423 ImmutableSet<V> set = valueSet(valueComparator, values); 424 if (!set.isEmpty()) { 425 builder.put(key, set); 426 size += set.size(); 427 } 428 } 429 430 return new ImmutableSetMultimap<>(builder.build(), size, valueComparator); 431 } 432 433 /** 434 * Returns an immutable multimap containing the specified entries. The 435 * returned multimap iterates over keys in the order they were first 436 * encountered in the input, and the values for each key are iterated in the 437 * order they were encountered. If two values for the same key are 438 * {@linkplain Object#equals equal}, the first value encountered is used. 439 * 440 * @throws NullPointerException if any key, value, or entry is null 441 * @since 19.0 442 */ 443 @Beta 444 public static <K, V> ImmutableSetMultimap<K, V> copyOf( 445 Iterable<? extends Entry<? extends K, ? extends V>> entries) { 446 return new Builder<K, V>().putAll(entries).build(); 447 } 448 449 /** 450 * Returned by get() when a missing key is provided. Also holds the 451 * comparator, if any, used for values. 452 */ 453 private final transient ImmutableSet<V> emptySet; 454 455 ImmutableSetMultimap( 456 ImmutableMap<K, ImmutableSet<V>> map, 457 int size, 458 @Nullable Comparator<? super V> valueComparator) { 459 super(map, size); 460 this.emptySet = emptySet(valueComparator); 461 } 462 463 // views 464 465 /** 466 * Returns an immutable set of the values for the given key. If no mappings 467 * in the multimap have the provided key, an empty immutable set is returned. 468 * The values are in the same order as the parameters used to build this 469 * multimap. 470 */ 471 @Override 472 public ImmutableSet<V> get(@Nullable K key) { 473 // This cast is safe as its type is known in constructor. 474 ImmutableSet<V> set = (ImmutableSet<V>) map.get(key); 475 return MoreObjects.firstNonNull(set, emptySet); 476 } 477 478 @LazyInit 479 @RetainedWith 480 private transient ImmutableSetMultimap<V, K> inverse; 481 482 /** 483 * {@inheritDoc} 484 * 485 * <p>Because an inverse of a set multimap cannot contain multiple pairs with 486 * the same key and value, this method returns an {@code ImmutableSetMultimap} 487 * rather than the {@code ImmutableMultimap} specified in the {@code 488 * ImmutableMultimap} class. 489 * 490 * @since 11.0 491 */ 492 public ImmutableSetMultimap<V, K> inverse() { 493 ImmutableSetMultimap<V, K> result = inverse; 494 return (result == null) ? (inverse = invert()) : result; 495 } 496 497 private ImmutableSetMultimap<V, K> invert() { 498 Builder<V, K> builder = builder(); 499 for (Entry<K, V> entry : entries()) { 500 builder.put(entry.getValue(), entry.getKey()); 501 } 502 ImmutableSetMultimap<V, K> invertedMultimap = builder.build(); 503 invertedMultimap.inverse = this; 504 return invertedMultimap; 505 } 506 507 /** 508 * Guaranteed to throw an exception and leave the multimap unmodified. 509 * 510 * @throws UnsupportedOperationException always 511 * @deprecated Unsupported operation. 512 */ 513 @CanIgnoreReturnValue 514 @Deprecated 515 @Override 516 public ImmutableSet<V> removeAll(Object key) { 517 throw new UnsupportedOperationException(); 518 } 519 520 /** 521 * Guaranteed to throw an exception and leave the multimap unmodified. 522 * 523 * @throws UnsupportedOperationException always 524 * @deprecated Unsupported operation. 525 */ 526 @CanIgnoreReturnValue 527 @Deprecated 528 @Override 529 public ImmutableSet<V> replaceValues(K key, Iterable<? extends V> values) { 530 throw new UnsupportedOperationException(); 531 } 532 533 private transient ImmutableSet<Entry<K, V>> entries; 534 535 /** 536 * Returns an immutable collection of all key-value pairs in the multimap. 537 * Its iterator traverses the values for the first key, the values for the 538 * second key, and so on. 539 */ 540 @Override 541 public ImmutableSet<Entry<K, V>> entries() { 542 ImmutableSet<Entry<K, V>> result = entries; 543 return result == null ? (entries = new EntrySet<>(this)) : result; 544 } 545 546 private static final class EntrySet<K, V> extends ImmutableSet<Entry<K, V>> { 547 @Weak private final transient ImmutableSetMultimap<K, V> multimap; 548 549 EntrySet(ImmutableSetMultimap<K, V> multimap) { 550 this.multimap = multimap; 551 } 552 553 @Override 554 public boolean contains(@Nullable Object object) { 555 if (object instanceof Entry) { 556 Entry<?, ?> entry = (Entry<?, ?>) object; 557 return multimap.containsEntry(entry.getKey(), entry.getValue()); 558 } 559 return false; 560 } 561 562 @Override 563 public int size() { 564 return multimap.size(); 565 } 566 567 @Override 568 public UnmodifiableIterator<Entry<K, V>> iterator() { 569 return multimap.entryIterator(); 570 } 571 572 @Override 573 boolean isPartialView() { 574 return false; 575 } 576 } 577 578 private static <V> ImmutableSet<V> valueSet( 579 @Nullable Comparator<? super V> valueComparator, Collection<? extends V> values) { 580 return (valueComparator == null) 581 ? ImmutableSet.copyOf(values) 582 : ImmutableSortedSet.copyOf(valueComparator, values); 583 } 584 585 private static <V> ImmutableSet<V> emptySet(@Nullable Comparator<? super V> valueComparator) { 586 return (valueComparator == null) 587 ? ImmutableSet.<V>of() 588 : ImmutableSortedSet.<V>emptySet(valueComparator); 589 } 590 591 private static <V> ImmutableSet.Builder<V> valuesBuilder( 592 @Nullable Comparator<? super V> valueComparator) { 593 return (valueComparator == null) 594 ? new ImmutableSet.Builder<V>() 595 : new ImmutableSortedSet.Builder<V>(valueComparator); 596 } 597 598 /** 599 * @serialData number of distinct keys, and then for each distinct key: the 600 * key, the number of values for that key, and the key's values 601 */ 602 @GwtIncompatible // java.io.ObjectOutputStream 603 private void writeObject(ObjectOutputStream stream) throws IOException { 604 stream.defaultWriteObject(); 605 stream.writeObject(valueComparator()); 606 Serialization.writeMultimap(this, stream); 607 } 608 609 @Nullable 610 Comparator<? super V> valueComparator() { 611 return emptySet instanceof ImmutableSortedSet 612 ? ((ImmutableSortedSet<V>) emptySet).comparator() 613 : null; 614 } 615 616 @GwtIncompatible // java.io.ObjectInputStream 617 // Serialization type safety is at the caller's mercy. 618 @SuppressWarnings("unchecked") 619 private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { 620 stream.defaultReadObject(); 621 Comparator<Object> valueComparator = (Comparator<Object>) stream.readObject(); 622 int keyCount = stream.readInt(); 623 if (keyCount < 0) { 624 throw new InvalidObjectException("Invalid key count " + keyCount); 625 } 626 ImmutableMap.Builder<Object, ImmutableSet<Object>> builder = ImmutableMap.builder(); 627 int tmpSize = 0; 628 629 for (int i = 0; i < keyCount; i++) { 630 Object key = stream.readObject(); 631 int valueCount = stream.readInt(); 632 if (valueCount <= 0) { 633 throw new InvalidObjectException("Invalid value count " + valueCount); 634 } 635 636 ImmutableSet.Builder<Object> valuesBuilder = valuesBuilder(valueComparator); 637 for (int j = 0; j < valueCount; j++) { 638 valuesBuilder.add(stream.readObject()); 639 } 640 ImmutableSet<Object> valueSet = valuesBuilder.build(); 641 if (valueSet.size() != valueCount) { 642 throw new InvalidObjectException("Duplicate key-value pairs exist for key " + key); 643 } 644 builder.put(key, valueSet); 645 tmpSize += valueCount; 646 } 647 648 ImmutableMap<Object, ImmutableSet<Object>> tmpMap; 649 try { 650 tmpMap = builder.build(); 651 } catch (IllegalArgumentException e) { 652 throw (InvalidObjectException) new InvalidObjectException(e.getMessage()).initCause(e); 653 } 654 655 FieldSettersHolder.MAP_FIELD_SETTER.set(this, tmpMap); 656 FieldSettersHolder.SIZE_FIELD_SETTER.set(this, tmpSize); 657 FieldSettersHolder.EMPTY_SET_FIELD_SETTER.set(this, emptySet(valueComparator)); 658 } 659 660 @GwtIncompatible // not needed in emulated source. 661 private static final long serialVersionUID = 0; 662}