2020 *
2121 * <ul>
2222 * <li>fast copy from one map to another
23- * <li>compatibility with Builder idioms
23+ * <li>compatibility with builder idioms
2424 * <li>building small maps as fast as possible
2525 * <li>storing primitives without boxing
2626 * <li>minimal memory footprint
@@ -71,14 +71,14 @@ private static final TagMap createEmpty() {
7171 return new TagMap (new Object [1 ], 0 );
7272 }
7373
74- /** Creates a new TagMap.Builder */
75- public static final Builder builder () {
76- return new Builder ();
74+ /** Creates a new TagMap.Ledger */
75+ public static final Ledger ledger () {
76+ return new Ledger ();
7777 }
7878
79- /** Creates a new TagMap.Builder which handles <code>size</code> modifications before expansion */
80- public static final Builder builder (int size ) {
81- return new Builder (size );
79+ /** Creates a new TagMap.Ledger which handles <code>size</code> modifications before expansion */
80+ public static final Ledger ledger (int size ) {
81+ return new Ledger (size );
8282 }
8383
8484 /** Creates a new mutable TagMap that contains the contents of <code>map</code> */
@@ -337,8 +337,8 @@ public final void putAll(Iterable<? extends Entry> entries) {
337337 }
338338 }
339339
340- public final void putAll (TagMap .Builder builder ) {
341- putAll (builder .entryChanges , builder .nextPos );
340+ public final void putAll (TagMap .Ledger ledger ) {
341+ putAll (ledger .entryChanges , ledger .nextPos );
342342 }
343343
344344 private final void putAll (EntryChange [] entryChanges , int size ) {
@@ -830,19 +830,19 @@ public final String toString() {
830830 final String toPrettyString () {
831831 boolean first = true ;
832832
833- StringBuilder builder = new StringBuilder (128 );
834- builder .append ('{' );
833+ StringBuilder ledger = new StringBuilder (128 );
834+ ledger .append ('{' );
835835 for (Entry entry : this ) {
836836 if (first ) {
837837 first = false ;
838838 } else {
839- builder .append (", " );
839+ ledger .append (", " );
840840 }
841841
842- builder .append (entry .tag ).append ('=' ).append (entry .stringValue ());
842+ ledger .append (entry .tag ).append ('=' ).append (entry .stringValue ());
843843 }
844- builder .append ('}' );
845- return builder .toString ();
844+ ledger .append ('}' );
845+ return ledger .toString ();
846846 }
847847
848848 /**
@@ -852,25 +852,25 @@ final String toPrettyString() {
852852 final String toInternalString () {
853853 Object [] thisBuckets = this .buckets ;
854854
855- StringBuilder builder = new StringBuilder (128 );
855+ StringBuilder ledger = new StringBuilder (128 );
856856 for (int i = 0 ; i < thisBuckets .length ; ++i ) {
857- builder .append ('[' ).append (i ).append ("] = " );
857+ ledger .append ('[' ).append (i ).append ("] = " );
858858
859859 Object thisBucket = thisBuckets [i ];
860860 if (thisBucket == null ) {
861- builder .append ("null" );
861+ ledger .append ("null" );
862862 } else if (thisBucket instanceof Entry ) {
863- builder .append ('{' ).append (thisBucket ).append ('}' );
863+ ledger .append ('{' ).append (thisBucket ).append ('}' );
864864 } else if (thisBucket instanceof BucketGroup ) {
865865 for (BucketGroup curGroup = (BucketGroup ) thisBucket ;
866866 curGroup != null ;
867867 curGroup = curGroup .prev ) {
868- builder .append (curGroup ).append (" -> " );
868+ ledger .append (curGroup ).append (" -> " );
869869 }
870870 }
871- builder .append ('\n' );
871+ ledger .append ('\n' );
872872 }
873- return builder .toString ();
873+ return ledger .toString ();
874874 }
875875
876876 static final int _hash (String tag ) {
@@ -1439,16 +1439,20 @@ private static final double prim2Double(long prim) {
14391439 }
14401440 }
14411441
1442- public static final class Builder implements Iterable <EntryChange > {
1442+ /*
1443+ * An in-order ledger of changes to be made to a TagMap.
1444+ * Ledger can also serves as a builder for TagMap-s via build & buildImmutable.
1445+ */
1446+ public static final class Ledger implements Iterable <EntryChange > {
14431447 private EntryChange [] entryChanges ;
14441448 private int nextPos = 0 ;
14451449 private boolean containsRemovals = false ;
14461450
1447- private Builder () {
1451+ private Ledger () {
14481452 this (8 );
14491453 }
14501454
1451- private Builder (int size ) {
1455+ private Ledger (int size ) {
14521456 this .entryChanges = new EntryChange [size ];
14531457 }
14541458
@@ -1457,7 +1461,7 @@ public final boolean isDefinitelyEmpty() {
14571461 }
14581462
14591463 /**
1460- * Provides the estimated size of the map created by the builder Doesn't account for overwritten
1464+ * Provides the estimated size of the map created by the ledger Doesn't account for overwritten
14611465 * entries or entry removal
14621466 *
14631467 * @return
@@ -1470,54 +1474,48 @@ public final boolean containsRemovals() {
14701474 return this .containsRemovals ;
14711475 }
14721476
1473- public final Builder put (String tag , Object value ) {
1477+ public final Ledger set (String tag , Object value ) {
14741478 return this .recordEntry (Entry .newAnyEntry (tag , value ));
14751479 }
14761480
1477- public final Builder put (String tag , CharSequence value ) {
1481+ public final Ledger set (String tag , CharSequence value ) {
14781482 return this .recordEntry (Entry .newObjectEntry (tag , value ));
14791483 }
14801484
1481- public final Builder put (String tag , boolean value ) {
1485+ public final Ledger set (String tag , boolean value ) {
14821486 return this .recordEntry (Entry .newBooleanEntry (tag , value ));
14831487 }
14841488
1485- public final Builder put (String tag , int value ) {
1489+ public final Ledger set (String tag , int value ) {
14861490 return this .recordEntry (Entry .newIntEntry (tag , value ));
14871491 }
14881492
1489- public final Builder put (String tag , long value ) {
1493+ public final Ledger set (String tag , long value ) {
14901494 return this .recordEntry (Entry .newLongEntry (tag , value ));
14911495 }
14921496
1493- public final Builder put (String tag , float value ) {
1497+ public final Ledger set (String tag , float value ) {
14941498 return this .recordEntry (Entry .newFloatEntry (tag , value ));
14951499 }
14961500
1497- public final Builder put (String tag , double value ) {
1501+ public final Ledger set (String tag , double value ) {
14981502 return this .recordEntry (Entry .newDoubleEntry (tag , value ));
14991503 }
15001504
1501- public final Builder uncheckedPut (Entry entry ) {
1505+ public final Ledger set (Entry entry ) {
15021506 return this .recordEntry (entry );
15031507 }
15041508
1505- public final Builder put (Entry entry ) {
1506- this .recordChange (entry );
1507- this .containsRemovals |= entry .isRemoval ();
1508- return this ;
1509- }
1510-
1511- public final Builder remove (String tag ) {
1509+ public final Ledger remove (String tag ) {
15121510 return this .recordRemoval (EntryChange .newRemoval (tag ));
15131511 }
15141512
1515- private final Builder recordEntry (Entry entry ) {
1513+ private final Ledger recordEntry (Entry entry ) {
15161514 this .recordChange (entry );
15171515 return this ;
15181516 }
15191517
1520- private final Builder recordRemoval (EntryRemoval entry ) {
1518+ private final Ledger recordRemoval (EntryRemoval entry ) {
15211519 this .recordChange (entry );
15221520 this .containsRemovals = true ;
15231521
@@ -1532,7 +1530,7 @@ private final void recordChange(EntryChange entryChange) {
15321530 this .entryChanges [this .nextPos ++] = entryChange ;
15331531 }
15341532
1535- public final Builder smartRemove (String tag ) {
1533+ public final Ledger smartRemove (String tag ) {
15361534 if (this .contains (tag )) {
15371535 this .remove (tag );
15381536 }
@@ -2153,15 +2151,15 @@ BucketGroup _cloneEntries() {
21532151
21542152 @ Override
21552153 public String toString () {
2156- StringBuilder builder = new StringBuilder (32 );
2157- builder .append ('[' );
2154+ StringBuilder ledger = new StringBuilder (32 );
2155+ ledger .append ('[' );
21582156 for (int i = 0 ; i < BucketGroup .LEN ; ++i ) {
2159- if (i != 0 ) builder .append (", " );
2157+ if (i != 0 ) ledger .append (", " );
21602158
2161- builder .append (this ._entryAt (i ));
2159+ ledger .append (this ._entryAt (i ));
21622160 }
2163- builder .append (']' );
2164- return builder .toString ();
2161+ ledger .append (']' );
2162+ return ledger .toString ();
21652163 }
21662164 }
21672165
0 commit comments