Skip to content

Commit 6149c85

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

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

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

Lines changed: 12 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,9 @@ 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+
*/
7577
@Immutable
7678
private static final class DefaultAttachmentKey<V> implements AttachmentKey<V> {
7779
private static final Set<String> AVOID_KEY_DUPLICATION = new HashSet<>();
@@ -83,6 +85,10 @@ private DefaultAttachmentKey(final String key) {
8385
this.key = key;
8486
}
8587

88+
static <V> DefaultAttachmentKey<V> of(final String key) {
89+
return new DefaultAttachmentKey<>(key);
90+
}
91+
8692
@Override
8793
public boolean equals(final Object o) {
8894
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)