3636 * @see AttachmentKey
3737 */
3838public final class AttachmentKeys {
39- private static final AttachmentKey <Integer > MAX_WIRE_VERSION = new DefaultAttachmentKey <>("maxWireVersion" );
40- private static final AttachmentKey <BsonDocument > COMMAND = new DefaultAttachmentKey <>("command" );
41- private static final AttachmentKey <Boolean > RETRYABLE_WRITE_COMMAND_FLAG = new DefaultAttachmentKey <>("retryableWriteCommandFlag" );
42- private static final AttachmentKey <Supplier <String >> COMMAND_DESCRIPTION_SUPPLIER = new DefaultAttachmentKey <>(
43- "commandDescriptionSupplier" );
44- private static final AttachmentKey <BulkWriteTracker > BULK_WRITE_TRACKER = new DefaultAttachmentKey <>("bulkWriteTracker" );
39+ private static final AttachmentKey <Integer > MAX_WIRE_VERSION = DefaultAttachmentKey .of ("maxWireVersion" );
40+ private static final AttachmentKey <BsonDocument > COMMAND = DefaultAttachmentKey .of ("command" );
41+ private static final AttachmentKey <Boolean > RETRYABLE_WRITE_COMMAND_FLAG = DefaultAttachmentKey .of ("retryableWriteCommandFlag" );
42+ private static final AttachmentKey <Supplier <String >> COMMAND_DESCRIPTION_SUPPLIER = DefaultAttachmentKey .of ("commandDescriptionSupplier" );
43+ private static final AttachmentKey <BulkWriteTracker > BULK_WRITE_TRACKER = DefaultAttachmentKey .of ("bulkWriteTracker" );
4544
4645 public static AttachmentKey <Integer > maxWireVersion () {
4746 return MAX_WIRE_VERSION ;
@@ -72,6 +71,11 @@ private AttachmentKeys() {
7271 fail ();
7372 }
7473
74+ /**
75+ * A <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/doc-files/ValueBased.html">value-based</a> class.
76+ *
77+ * @param <V>
78+ */
7579 @ Immutable
7680 private static final class DefaultAttachmentKey <V > implements AttachmentKey <V > {
7781 private static final Set <String > AVOID_KEY_DUPLICATION = new HashSet <>();
@@ -83,6 +87,10 @@ private DefaultAttachmentKey(final String key) {
8387 this .key = key ;
8488 }
8589
90+ static <V > DefaultAttachmentKey <V > of (final String key ) {
91+ return new DefaultAttachmentKey <>(key );
92+ }
93+
8694 @ Override
8795 public boolean equals (final Object o ) {
8896 if (this == o ) {
0 commit comments