4343 * <li>adaptive collision
4444 * </ul>
4545 */
46-
47- /*
48- * For memory efficiency, TagMap uses a rather complicated bucket system.
49- * <p>
50- * When there is only a single Entry in a particular bucket, the Entry is stored into the bucket directly.
51- * <p>
52- * Because the Entry objects can be shared between multiple TagMaps, the Entry objects cannot
53- * directly form a linked list to handle collisions.
54- * <p>
55- * Instead when multiple entries collide in the same bucket, a BucketGroup is formed to hold multiple entries.
56- * But a BucketGroup is only formed when a collision occurs to keep allocation low in the common case of no collisions.
57- * <p>
58- * For efficiency, BucketGroups are a fixed size, so when a BucketGroup fills up another BucketGroup is formed
59- * to hold the additional Entry-s. And the BucketGroup-s are connected via a linked list instead of the Entry-s.
60- * <p>
61- * This does introduce some inefficiencies when Entry-s are removed.
62- * The assumption is that removals are rare, so BucketGroups are never consolidated.
63- * However as a precaution if a BucketGroup becomes completely empty, then that BucketGroup will be
64- * removed from the collision chain.
65- */
6646public interface TagMap extends Map <String , Object >, Iterable <TagMap .Entry > {
6747 /** Immutable empty TagMap - similar to {@link Collections#emptyMap()} */
6848 public static final TagMap EMPTY = TagMapFactory .INSTANCE .empty ();
@@ -103,15 +83,26 @@ public static Ledger ledger(int size) {
10383
10484 boolean isOptimized ();
10585
86+ /** Inefficiently implemented for optimized TagMap */
10687 @ Deprecated
10788 Set <String > keySet ();
10889
90+ /** Inefficiently implemented for optimized TagMap - requires boxing primitives */
10991 @ Deprecated
11092 Collection <Object > values ();
11193
11294 // @Deprecated -- not deprecated until OptimizedTagMap becomes the default
11395 Set <java .util .Map .Entry <String , Object >> entrySet ();
11496
97+ /**
98+ * Deprecated in favor of typed getters like...
99+ * <ul>
100+ * <li>{@link TagMap#getObject(String)}
101+ * <li>{@link TagMap#getString(String)}
102+ * <li>{@link TagMap#getBoolean(String)
103+ * <li>...
104+ * </ul>
105+ */
115106 @ Deprecated
116107 Object get (Object tag );
117108
@@ -147,6 +138,10 @@ public static Ledger ledger(int size) {
147138 */
148139 Entry getEntry (String tag );
149140
141+ /**
142+ * Deprecated in favor of {@link TagMap#set} methods. set methods don't return the prior value and
143+ * are implemented efficiently for both the legacy and optimized implementations of TagMap.
144+ */
150145 @ Deprecated
151146 Object put (String tag , Object value );
152147
@@ -208,6 +203,10 @@ public static Ledger ledger(int size) {
208203
209204 void fillStringMap (Map <? super String , ? super String > stringMap );
210205
206+ /**
207+ * Deprecated in favor of {@link TagMap#remove(String)} which returns a boolean and is efficiently
208+ * implemented for both legacy and optimal TagMaps
209+ */
211210 @ Deprecated
212211 Object remove (Object tag );
213212
@@ -219,7 +218,7 @@ public static Ledger ledger(int size) {
219218
220219 /**
221220 * Similar to {@link Map#remove(Object)} but returns the prior Entry object rather than the prior
222- * value. For optimized TagMap-s, this preferred because it avoids additional boxing.
221+ * value. For optimized TagMap-s, this method is preferred because it avoids additional boxing.
223222 */
224223 Entry getAndRemove (String tag );
225224
@@ -780,12 +779,23 @@ public final String toString() {
780779 return this .tag () + '=' + this .stringValue ();
781780 }
782781
782+ /** Deprecated in favor of{@link Entry#tag()} */
783783 @ Deprecated
784784 @ Override
785785 public String getKey () {
786786 return this .tag ();
787787 }
788788
789+ /**
790+ * Deprecated in favor of typed getters like...
791+ *
792+ * <ul>
793+ * <li>{@link Entry#objectValue()}
794+ * <li>{@link Entry#stringValue()}
795+ * <li>{@link Entry#booleanValue()}
796+ * <li>...
797+ * </ul>
798+ */
789799 @ Deprecated
790800 @ Override
791801 public Object getValue () {
@@ -1114,6 +1124,25 @@ public LegacyTagMap empty() {
11141124 }
11151125}
11161126
1127+ /*
1128+ * For memory efficiency, OptimizedTagMap uses a rather complicated bucket system.
1129+ * <p>
1130+ * When there is only a single Entry in a particular bucket, the Entry is stored into the bucket directly.
1131+ * <p>
1132+ * Because the Entry objects can be shared between multiple TagMaps, the Entry objects cannot
1133+ * directly form a linked list to handle collisions.
1134+ * <p>
1135+ * Instead when multiple entries collide in the same bucket, a BucketGroup is formed to hold multiple entries.
1136+ * But a BucketGroup is only formed when a collision occurs to keep allocation low in the common case of no collisions.
1137+ * <p>
1138+ * For efficiency, BucketGroups are a fixed size, so when a BucketGroup fills up another BucketGroup is formed
1139+ * to hold the additional Entry-s. And the BucketGroup-s are connected via a linked list instead of the Entry-s.
1140+ * <p>
1141+ * This does introduce some inefficiencies when Entry-s are removed.
1142+ * The assumption is that removals are rare, so BucketGroups are never consolidated.
1143+ * However as a precaution if a BucketGroup becomes completely empty, then that BucketGroup will be
1144+ * removed from the collision chain.
1145+ */
11171146final class OptimizedTagMap implements TagMap {
11181147 // Using special constructor that creates a frozen view of an existing array
11191148 // Bucket calculation requires that array length is a power of 2
@@ -2004,7 +2033,6 @@ private final Entry advance() {
20042033 }
20052034 }
20062035 }
2007- ;
20082036
20092037 return null ;
20102038 }
0 commit comments