1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | /* * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package Torello.Java.ReadOnly; import java.util.*; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; /** * A Copy of Java's {@code HashMap} class; used for building a {@link ReadOnlyHashMap}. * Maintains <I>an internal and inaccessible {@code HashMap<E>} instance</I>. * * <EMBED CLASS=globalDefs DATA-JDK=HashMap> * <EMBED CLASS='external-html' DATA-A_AN=a DATA-FILE-ID=BUILDERS> * * @param <K> the type of keys maintained by this map * @param <V> the type of mapped values * @see ReadOnlyHashMap */ @Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="JDHBI_BUILDER") public final class ROHashMapBuilder<K, V> extends HashMap<K, V> implements Cloneable, java.io.Serializable { // ******************************************************************************************** // ******************************************************************************************** // Fields & Builder Stuff // ******************************************************************************************** // ******************************************************************************************** /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ protected static final long serialVersionUID = 1; // Exception messages need this private static final String ROHM = "HashMap"; private boolean built = false; // Mimics the C++ Concept of "Friend Class". This badge is utilized by the "build()" method // directly below this inner-class declaration. It is the only place where this declaration is // actually used anywhere. This prohibits access to the constructor that is used to anybody // else static class AccessBadge { private AccessBadge() { } } private static final AccessBadge friendClassBadge = new AccessBadge(); /** * Simply transfers {@code 'this'} instance' internal {@code HashMap} to the * {@code ReadOnlyHashMap} Wrapper-Class. * * @return a newly constructed {@code ReadOnlyHashMap} "Wrapper-Class", shielding the internal * {@code 'hashMap'} private-field from any modification. */ public ReadOnlyHashMap<K, V> build() { this.built = true; return (size() == 0) ? ReadOnlyHashMap.emptyROHM() : new ReadOnlyHashMap<>(this, friendClassBadge); } // ******************************************************************************************** // ******************************************************************************************** // Modified Constructors // ******************************************************************************************** // ******************************************************************************************** /** * Constructs an empty {@code ROHashMapBuilder} with the specified initial capacity and load * factor. * * <BR /><BR />To create a {@code ROHashMapBuilder} with an initial capacity that accommodates * an expected number of mappings, use {@link #newROHashMapBuilder(int) newROHashMapBuilder}. * * @param initialCapacity the initial capacity * @param loadFactor the load factor * @throws IllegalArgumentException if the initial capacity is negative or the load factor is * nonpositive */ public ROHashMapBuilder(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); } /** * Constructs an empty {@code ROHashMapBuilder} with the specified initial capacity and the * default load factor (0.75). * * <BR /><BR />To create a {@code ROHashMapBuilder} with an initial capacity that accommodates * an expected number of mappings, use {@link #newROHashMapBuilder(int) newROHashMapBuilder}. * * @param initialCapacity the initial capacity. * @throws IllegalArgumentException if the initial capacity is negative. */ public ROHashMapBuilder(int initialCapacity) { super(initialCapacity); } /** * Constructs an empty {@code ROHashMapBuilder} with the default initial capacity (16) and the * default load factor (0.75). */ public ROHashMapBuilder() { super(); } /** * Constructs a new {@code ROHashMapBuilder} with the same mappings as the specified * {@code Map}. The {@code ROHashMapBuilder} is created with default load factor (0.75) and an * initial capacity sufficient to hold the mappings in the specified {@code Map}. * * @param m the map whose mappings are to be placed in this map * @throws NullPointerException if the specified map is null */ public ROHashMapBuilder(Map<? extends K, ? extends V> m) { super(m); } /** * Creates a new, empty {@code ROHashMapBuilder} suitable for the expected number of mappings. * The returned map uses the default load factor of 0.75, and its initial capacity is generally * large enough so that the expected number of mappings can be added without resizing the map. * * @param numMappings the expected number of mappings * @param <K> the type of keys maintained by the new map * @param <V> the type of mapped values * @return the newly created map * @throws IllegalArgumentException if numMappings is negative */ public static <K, V> ROHashMapBuilder<K, V> newROHashMapBuilder(int numMappings) { if (numMappings < 0) throw new IllegalArgumentException("Negative number of mappings: " + numMappings); return new ROHashMapBuilder<>(calculateHashMapCapacity(numMappings)); } // Copied from JDK-21, java.util.HashMap // Calculate initial capacity for HashMap based classes, from expected size and default load // factor (0.75). private static int calculateHashMapCapacity(int numMappings) { return (int) Math.ceil(numMappings / (double) /* DEFAULT_LOAD_FACTOR */ 0.75f); } // ******************************************************************************************** // ******************************************************************************************** // Original JDK Methods // ******************************************************************************************** // ******************************************************************************************** /** * Associates the specified value with the specified key in this map. If the map previously * contained a mapping for the key, the old value is replaced. * * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> * * @param key key with which the specified value is to be associated * @param value value to be associated with the specified key * * @return the previous value associated with {@code key}, or {@code null} if there was no * mapping for {@code key}. (A {@code null} return can also indicate that the map previously * associated {@code null} with {@code key}.) */ public V put(K key, V value) { if (this.built) throw new AttemptedModificationException(ROHM); return super.put(key, value); } /** * Copies all of the mappings from the specified map to this map. These mappings will replace * any mappings that this map had for any of the keys currently in the specified map. * * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> * * @param m mappings to be stored in this map * @throws NullPointerException if the specified map is null */ public void putAll(Map<? extends K, ? extends V> m) { if (this.built) throw new AttemptedModificationException(ROHM); super.putAll(m); } /** * Removes the mapping for the specified key from this map if present. * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> * @param key key whose mapping is to be removed from the map * * @return the previous value associated with {@code key}, or {@code null} if there was no * mapping for {@code key}. (A {@code null} return can also indicate that the map previously * associated {@code null} with {@code key}.) */ public V remove(Object key) { if (this.built) throw new AttemptedModificationException(ROHM); return super.remove(key); } /** * Removes all of the mappings from this map. The map will be empty after this call returns. * * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> */ public void clear() { if (this.built) throw new AttemptedModificationException(ROHM); super.clear(); } // ******************************************************************************************** // ******************************************************************************************** // Overrides of JDK8 Map extension methods // ******************************************************************************************** // ******************************************************************************************** /** * If the specified key is not already associated with a value (or is mapped to {@code null}) * associates it with the given value and returns {@code null}, else returns the current value. * * <BR /><BR />The default implementation is equivalent to, for this {@code map}: * * <BR /><DIV CLASS=SNIP>{@code * V v = map.get(key); * * if (v == null) v = map.put(key, value); * * return v; * }</DIV> * * <BR /><BR />The default implementation makes no guarantees about synchronization or * atomicity properties of this method. Any implementation providing atomicity guarantees must * override this method and document its concurrency properties. * * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> * * @param key key with which the specified value is to be associated * @param value value to be associated with the specified key * * @return the previous value associated with the specified key, or {@code null} if there was * no mapping for the key. (A {@code null} return can also indicate that the map previously * associated {@code null} with the key, if the implementation supports null values.) * * @throws UnsupportedOperationException if the {@code put} operation is not supported by this * map * * @throws ClassCastException if the key or value is of an inappropriate type for this map * * @throws NullPointerException if the specified key or value is null, and this map does not * permit null keys or values * * @throws IllegalArgumentException if some property of the specified key or value prevents it * from being stored in this map */ public V putIfAbsent(K key, V value) { if (this.built) throw new AttemptedModificationException(ROHM); return super.putIfAbsent(key, value); } /** * Removes the entry for the specified key only if it is currently mapped to the specified * value. * * <BR /><BR />The default implementation is equivalent to, for this {@code map}: * * <BR /><DIV CLASS=SNIP>{@code * if (map.containsKey(key) && Objects.equals(map.get(key), value)) * { * map.remove(key); * return true; * } * * return false; * }</DIV> * * <BR /><BR />The default implementation makes no guarantees about synchronization or * atomicity properties of this method. Any implementation providing atomicity guarantees must * override this method and document its concurrency properties. * * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> * * @param key key with which the specified value is associated * @param value value expected to be associated with the specified key * @return {@code true} if the value was removed * * @throws UnsupportedOperationException if the {@code remove} operation is not supported by * this map * * @throws ClassCastException if the key or value is of an inappropriate type for this map * * @throws NullPointerException if the specified key or value is null, and this map does not * permit null keys or values */ public boolean remove(Object key, Object value) { if (this.built) throw new AttemptedModificationException(ROHM); return super.remove(key, value); } /** * Replaces the entry for the specified key only if currently mapped to the specified value. * * <BR /><BR />The default implementation is equivalent to, for this {@code map}: * * <DIV CLASS=SNIP>{@code * if (map.containsKey(key) && Objects.equals(map.get(key), oldValue)) * { * map.put(key, newValue); * return true; * } * * return false; * }</DIV> * * <BR /><BR />The default implementation does not throw {@code NullPointerException} for maps * that do not support null values if oldValue is null unless newValue is also null. * * <BR /><BR />The default implementation makes no guarantees about synchronization or * atomicity properties of this method. Any implementation providing atomicity guarantees must * override this method and document its concurrency properties. * * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> * * @param key key with which the specified value is associated * @param oldValue value expected to be associated with the specified key * @param newValue value to be associated with the specified key * @return {@code TRUE} if the value was replaced * * @throws UnsupportedOperationException if the {@code put} operation is not supported by this * map * * @throws ClassCastException if the class of a specified key or value prevents it from being * stored in this map * * @throws NullPointerException if a specified key or newValue is null, and this map does not * permit null keys or values * * @throws NullPointerException if oldValue is null and this map does not permit null values * * @throws IllegalArgumentException if some property of a specified key or value prevents it * from being stored in this map */ public boolean replace(K key, V oldValue, V newValue) { if (this.built) throw new AttemptedModificationException(ROHM); return super.replace(key, oldValue, newValue); } /** * Replaces the entry for the specified key only if it is currently mapped to some value. * * <BR /><BR />The default implementation is equivalent to, for this {@code map}: * * <BR /><DIV CLASS=SNIP>{@code * if (map.containsKey(key)) return map.put(key, value); * return null; * }</DIV> * * <BR /><BR />The default implementation makes no guarantees about synchronization or * atomicity properties of this method. Any implementation providing atomicity guarantees must * override this method and document its concurrency properties. * * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> * * @param key key with which the specified value is associated * @param value value to be associated with the specified key * * @return the previous value associated with the specified key, or {@code null} if there was * no mapping for the key. (A {@code null} return can also indicate that the map previously * associated {@code null} with the key, if the implementation supports null values.) * * @throws UnsupportedOperationException if the {@code put} operation is not supported by this * map * * @throws ClassCastException if the class of the specified key or value prevents it from being * stored in this map * * @throws NullPointerException if the specified key or value is null, and this map does not * permit null keys or values * * @throws IllegalArgumentException if some property of the specified key or value prevents it * from being stored in this map */ public V replace(K key, V value) { if (this.built) throw new AttemptedModificationException(ROHM); return super.replace(key, value); } /** * If the specified key is not already associated with a value (or is mapped to null), attempts * to compute its value using the given mapping function and enters it into this map unless * null. * * <BR /><BR />If the mapping function returns null, no mapping is recorded. If the mapping * function itself throws an (unchecked) exception, the exception is rethrown, and no mapping * is recorded. The most common usage is to construct a new object serving as an initial mapped * value or memoized result, as in: * * <BR /><DIV CLASS=SNIP>{@code * map.computeIfAbsent(key, k -> new Value(f(k))); * }</DIV> * * <BR /><BR />Or to implement a multi-value map, {@code Map<K,Collection<V>>}, supporting * multiple values per key: * * <BR /><DIV CLASS=SNIP>{@code * map.computeIfAbsent(key, k -> new HashSet<V>()).add(v); * }</DIV> * * <BR /><BR />The mapping function should not modify this map during computation. * * <BR /><BR />This method will, on a best-effort basis, throw a * {@link ConcurrentModificationException} if it is detected that the mapping function modifies * this map during computation. * * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> * * @param key key with which the specified value is to be associated * @param mappingFunction the mapping function to compute a value * * @return the current (existing or computed) value associated with the specified key, or null * if the computed value is null * * @throws ConcurrentModificationException if it is detected that the mapping function modified * this map */ public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) { if (this.built) throw new AttemptedModificationException(ROHM); return super.computeIfAbsent(key, mappingFunction); } /** * If the value for the specified key is present and non-null, attempts to compute a new * mapping given the key and its current mapped value. * * <BR /><BR />If the remapping function returns null, the mapping is removed. If the remapping * function itself throws an (unchecked) exception, the exception is rethrown, and the current * mapping is left unchanged. * * <BR /><BR />The remapping function should not modify this map during computation. * * <BR /><BR />This method will, on a best-effort basis, throw a * {@link ConcurrentModificationException} if it is detected that the remapping function * modifies this map during computation. * * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> * * @param key key with which the specified value is to be associated * @param remappingFunction the remapping function to compute a value * @return the new value associated with the specified key, or null if none * @throws ConcurrentModificationException if it is detected that the remapping function * modified this map */ public V computeIfPresent (K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { if (this.built) throw new AttemptedModificationException(ROHM); return super.computeIfPresent(key, remappingFunction); } /** * Attempts to compute a mapping for the specified key and its current mapped value (or null if * there is no current mapping). For example, to either create or append a String msg to a * value mapping: * * <BR ><DIV CLASS=SNIP>{@code * map.compute(key, (k, v) -> (v == null) ? msg : v.concat(msg)) * }</DIV> * * <BR /><BR />(Method merge() is often simpler to use for such purposes.) * * <BR /><BR />If the remapping function returns null, the mapping is removed (or remains * absent if initially absent). If the remapping function itself throws an (unchecked) * exception, the exception is rethrown, and the current mapping is left unchanged. * * <BR /><BR />The remapping function should not modify this map during computation. * * <BR /><BR />This method will, on a best-effort basis, throw a * {@link ConcurrentModificationException} if it is detected that the remapping function * modifies this map during computation. * * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> * * @param key key with which the specified value is to be associated * @param remappingFunction the remapping function to compute a value * @return the new value associated with the specified key, or null if none * * @throws ConcurrentModificationException if it is detected that the remapping function * modified this map */ public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { if (this.built) throw new AttemptedModificationException(ROHM); return super.compute(key, remappingFunction); } /** * If the specified key is not already associated with a value or is associated with null, * associates it with the given non-null value. Otherwise, replaces the associated value with * the results of the given remapping function, or removes if the result is null. This method * may be of use when combining multiple mapped values for a key. For example, to either create * or append a String msg to a value mapping: * * <BR /><DIV CLASS=SNIP>{@code * map.merge(key, msg, String::concat) * }</DIV> * * <BR /><BR />If the remapping function returns null, the mapping is removed. If the remapping * function itself throws an (unchecked) exception, the exception is rethrown, and the current * mapping is left unchanged. * * <BR /><BR />The remapping function should not modify this map during computation. * * <BR /><BR />This method will, on a best-effort basis, throw a * {@code ConcurrentModificationException} if it is detected that the remapping function * modifies this map during computation. * * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> * * @param key key with which the resulting value is to be associated * * @param value the non-null value to be merged with the existing value associated with the key * or, if no existing value or a null value is associated with the key, to be associated with * the key * * @parma remappingFunction the remapping function to recompute a value if present * * @return the new value associated with the specified key, or null if no value is associated * with the key * * @throws ConcurrentModificationException if it is detected that the remapping function * modified this map */ public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) { if (this.built) throw new AttemptedModificationException(ROHM); return super.merge(key, value, remappingFunction); } /** * Replaces each entry's value with the result of invoking the given function on that entry * until all entries have been processed or the function throws an exception. Exceptions thrown * by the function are relayed to the caller. * * <BR /><BR />The implementation is equivalent to: * * <BR /><DIV CLASS=SNIP>{@code * for (Map.Entry<K, V> entry : map.entrySet()) * entry.setValue(function.apply(entry.getKey(), entry.getValue())); * }</DIV> * * <BR /><BR />No guarantees about synchronization or atomicity properties of this method. * * <EMBED DATA-TYPE=HashMap CLASS='external-html' DATA-FILE-ID=MUTATOR> * * @param function the function to apply to each entry * * @throws UnsupportedOperationException if the set operation is not supported by this map's * entry set iterator. * * @throws ClassCastException if the class of a replacement value prevents it from being * stored in this map (optional) * * @throws NullPointerException if the specified function is null, or if a replacement value is * null and this map does not permit null values (optional) * * @throws IllegalArgumentException if some property of a replacement value prevents it from * being stored in this map (optional) * * @throws ConcurrentModificationException - if an entry is found to be removed during * iteration */ public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) { if (this.built) throw new AttemptedModificationException(ROHM); super.replaceAll(function); } // ******************************************************************************************** // ******************************************************************************************** // Methods inherited from class java.util.HashMap // ******************************************************************************************** // ******************************************************************************************** // containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, size, // values // // Introspection Only: containsKey, containsValue, forEach, get, getOrDefault, isEmpty, size // Mutator or Potential Mutator: entrySet, keySet, values // // *** OTHER INHERITED METHODS - ALL READ-ONLY METHODS *** // // Methods inherited from class java.util.AbstractMap: hashCode, toString // Methods inherited from interface java.util.Map: hashCode /** * Restricts a back-door into the underlying data-structure. * <EMBED CLASS='external-html'DATA-RET_TYPE=Set DATA-FILE-ID=UNMODIFIABLE> * @return a {@code java.util.Set} that cannot modify this {@code HashMap-Builder} */ public Set<Map.Entry<K, V>> entrySet() { return Collections.unmodifiableSet(super.entrySet()); } Set<Map.Entry<K, V>> _entrySet(ReadOnlyHashMap.AccessBadge friendClassBadge) { return super.entrySet(); } /** * Restricts a back-door into the underlying data-structure. * <EMBED CLASS='external-html'DATA-RET_TYPE=Set DATA-FILE-ID=UNMODIFIABLE> * @return a {@code java.util.Set} that cannot modify this {@code HashMap-Builder} */ public Set<K> keySet() { return Collections.unmodifiableSet(super.keySet()); } Set<K> _keySet(ReadOnlyHashMap.AccessBadge friendClassBadge) { return super.keySet(); } /** * Restricts a back-door into the underlying data-structure. * <EMBED CLASS='external-html'DATA-RET_TYPE=Collection DATA-FILE-ID=UNMODIFIABLE> * @return a {@code java.util.Collection} that cannot modify this {@code HashMap-Builder} */ public Collection<V> values() { return Collections.unmodifiableCollection(super.values()); } Collection<V> _values(ReadOnlyHashMap.AccessBadge friendClassBadge) { return super.values(); } // ******************************************************************************************** // ******************************************************************************************** // java.lang.Object & Cloneable // ******************************************************************************************** // ******************************************************************************************** /** * Compares the specified Object with this Builder for equality, as per the definition in the * original class {@code java.util.HashMap}. Ignores the private field {@code 'built'}. If * {@code 'this'} has not been built, but {@code 'o'} has been, that fact is ignored during the * equality-comparison. * * @param o object to be compared for equality with this {@code ROHashMapBuilder} instance * @return true if the specified Object is equal to this Builder */ public synchronized boolean equals(Object o) { if (this == o) return true; if (! (o instanceof ROHashMapBuilder)) return false; return super.equals((HashMap) o); } /** * Clones this instance' of {@code ROHashMapBuilder}. * * <BR /><BR />The clone that's returned has had it's internal {@code 'built'} boolean-flag set * {@code FALSE} * * @return a clone of this builder */ public synchronized ROHashMapBuilder<K, V> clone() { return new ROHashMapBuilder<>(this); } private ROHashMapBuilder(ROHashMapBuilder<K, V> rohmb) { super(rohmb); this.built=false; } } |