-
Notifications
You must be signed in to change notification settings - Fork 4
Convert immutable classes to Java records #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
510ef31
04fb8f6
17c4e2b
ab350b6
faa688f
febc83c
fb8d468
de1251d
beb16bc
31601b3
20c9068
fac1098
bc4e999
f66504d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,46 +24,31 @@ | |
| */ | ||
| package org.bitrepository.client.conversation.selector; | ||
|
|
||
| import org.jspecify.annotations.NonNull; | ||
|
|
||
| /** | ||
| * Container for information about a pillar which as been identified and are marked as selected for a request. | ||
| * Container for information about a pillar which has been identified and marked as selected for a request. | ||
| * | ||
| * @param componentID The ID of the selected pillar | ||
| * @param componentTopic The topic for communication with the selected pillar | ||
| */ | ||
| public class SelectedComponentInfo { | ||
| /** | ||
| * The ID of the selected pillar | ||
| */ | ||
| protected final String componentID; | ||
| /** | ||
| * The topic for communication with the selected pillar | ||
| */ | ||
| protected final String componentTopic; | ||
| public record SelectedComponentInfo(@NonNull String componentID, @NonNull String componentTopic) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wish I knew whether
Let it be or add the alternative interpretation to the Javadoc comment, for example “The topic or destination for comm...”. |
||
|
|
||
| /** | ||
| * @param componentID The ID of the pillar | ||
| * @param componentTopic the topic for communication with the selected pillar | ||
| * @return The ID of the pillar chosen by this selector | ||
| * @deprecated Use {@link #componentID()} instead | ||
| */ | ||
| public SelectedComponentInfo(String componentID, String componentTopic) { | ||
| super(); | ||
| this.componentID = componentID; | ||
| this.componentTopic = componentTopic; | ||
| } | ||
|
|
||
| /** | ||
| * @return The ID of the pillar chosen by this selector if finished. If unfinished null is returned | ||
| */ | ||
| public String getID() { | ||
| @Deprecated(forRemoval = true) | ||
| public @NonNull String getID() { | ||
| return componentID; | ||
| } | ||
|
|
||
| /** | ||
| * @return If finished return the topic for sending messages to the pillar chosen by this selector. | ||
| * If unfinished null is returned | ||
| * @return The topic for sending messages to the pillar chosen by this selector | ||
| * @deprecated Use {@link #componentTopic()} instead | ||
| */ | ||
| public String getDestination() { | ||
| @Deprecated(forRemoval = true) | ||
| public @NonNull String getDestination() { | ||
| return componentTopic; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return getClass().getSimpleName() + ": componentID=" + componentID + ", componentTopic=" + componentTopic; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,7 @@ public abstract class CompleteEventAwaiter implements EventHandler { | |
| * @param settings The settings. | ||
| * @param outputHandler The {@link OutputHandler} for handling outputting results | ||
| */ | ||
| public CompleteEventAwaiter(Settings settings, OutputHandler outputHandler) { | ||
| protected CompleteEventAwaiter(Settings settings, OutputHandler outputHandler) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the class is abstract, I guess it’s OK to declare the constructor protected. |
||
| this.timeout = settings.getIdentificationTimeout().plus(settings.getOperationTimeout()); | ||
| this.output = outputHandler; | ||
| } | ||
|
|
@@ -88,7 +88,7 @@ public void handleEvent(OperationEvent event) { | |
| public OperationEvent getFinish() { | ||
| try { | ||
| CountAndTimeUnit pollTimeout = TimeUtils.durationToCountAndTimeUnit(timeout); | ||
| return finalEventQueue.poll(pollTimeout.getCount(), pollTimeout.getUnit()); | ||
| return finalEventQueue.poll(pollTimeout.count(), pollTimeout.unit()); | ||
| } catch (InterruptedException e) { | ||
| throw new IllegalStateException("Interrupted while waiting for the final response.", e); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package org.bitrepository.client.conversation.selector; | ||
|
|
||
| import org.junit.jupiter.api.Tag; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| @Tag("regressiontest") | ||
| class SelectedComponentInfoTest { | ||
|
|
||
| @Test | ||
| void delegationMethodsReturnCorrectComponents() { | ||
| SelectedComponentInfo info = new SelectedComponentInfo("pillar1", "pillar1-topic"); | ||
| assertEquals("pillar1", info.getID()); | ||
| assertEquals("pillar1-topic", info.getDestination()); | ||
| } | ||
|
|
||
| @Test | ||
| void equalityIsComponentBased() { | ||
| SelectedComponentInfo a = new SelectedComponentInfo("p1", "t1"); | ||
| SelectedComponentInfo b = new SelectedComponentInfo("p1", "t1"); | ||
| assertEquals(a, b); | ||
| assertEquals(a.hashCode(), b.hashCode()); | ||
| } | ||
|
|
||
| @Test | ||
| void toStringContainsComponentValues() { | ||
| String s = new SelectedComponentInfo("p1", "t1").toString(); | ||
| assertTrue(s.contains("p1")); | ||
| assertTrue(s.contains("t1")); | ||
| } | ||
| } |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This an example where for compatibility we still need to have a |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,13 +24,11 @@ | |
| /** | ||
| * Contains information about the message, not contained in the message itself. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Outside this task, may delete the comma. |
||
| */ | ||
| public class MessageContext { | ||
| private final String certificateFingerprint; | ||
|
|
||
| public MessageContext(String certificateFingerprint) { | ||
| this.certificateFingerprint = certificateFingerprint; | ||
| } | ||
|
|
||
| public record MessageContext(String certificateFingerprint) { | ||
| /** | ||
| * @deprecated Use {@link #certificateFingerprint()} instead | ||
| */ | ||
| @Deprecated(forRemoval = true) | ||
| public String getCertificateFingerprint() { | ||
| return certificateFingerprint; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were Javadoc comments in this file before, and I consider that some of them were rather helpful. Can we fit in the same information in Javadoc comments on the record class?
In particular I don’t find it obvious that
componentIDis the ID of a pillar. On the other hand I don’t believe thatgetID()returnsnullin practice though one comment claims that it can.