Skip to content

Commit 332f5ab

Browse files
committed
Do small improvements related to value-based classes
1 parent c0f9627 commit 332f5ab

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

driver-core/src/main/com/mongodb/internal/operation/retry/AttachmentKeys.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@
3636
* @see AttachmentKey
3737
*/
3838
public 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) {

driver-core/src/main/com/mongodb/internal/time/TimePoint.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class TimePoint implements Comparable<TimePoint>, StartTime, Timeout {
5050
@Nullable
5151
private final Long nanos;
5252

53+
@VisibleForTesting(otherwise = PRIVATE)
5354
TimePoint(@Nullable final Long nanos) {
5455
this.nanos = nanos;
5556
}

0 commit comments

Comments
 (0)