Repository navigation
enhancement/issue-52: API changes requested to support persistence #53
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 10 additions & 5 deletions
15
core/src/main/java/software/coley/bentofx/Identifiable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,26 @@ | ||
| package software.coley.bentofx; | ||
|
|
||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| /** | ||
| * Outline of an <i>(ideally uniquely)</i> identifiable object. | ||
| * | ||
| * @author Matt Coley | ||
| */ | ||
| public interface Identifiable { | ||
|
|
||
| /** | ||
| * @return This objects identifier. | ||
| * {@return This object's identifier.} | ||
| */ | ||
| String getIdentifier(); | ||
|
|
||
| /** | ||
| * @param other | ||
| * Another identifiable object. | ||
| * {@return {@code true} when the other object has the same identifier.} | ||
| * | ||
| * @return {@code true} when the other object has the same identifier. | ||
| * @param other Another identifiable object. | ||
| */ | ||
| boolean matchesIdentity(Identifiable other); | ||
| default boolean matchesIdentity(final @Nullable Identifiable other) { | ||
| return other != null && | ||
| this.getIdentifier().equals(other.getIdentifier()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
core/src/test/java/software/coley/bentofx/IdentifiableTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package software.coley.bentofx; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** | ||
| * Coverage for {@link Identifiable}'s default {@code matchesIdentity} method. | ||
| * | ||
| * @author Phil Bryant | ||
| */ | ||
| class IdentifiableTest { | ||
|
|
||
| private static final String IDENTIFIER = "identifiable-1"; | ||
| private static final String OTHER_IDENTIFIER = "identifiable-2"; | ||
|
|
||
| @Test | ||
| void matchesIdentityIsTrueWhenTheOtherObjectHasTheSameIdentifier() { | ||
| Identifiable subject = newIdentifiableImpl(IDENTIFIER); | ||
| Identifiable other = newIdentifiableImpl(IDENTIFIER); | ||
|
|
||
| assertThat(subject.matchesIdentity(other)) | ||
| .describedAs("matchesIdentity() for two objects with the same identifier") | ||
| .isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| void matchesIdentityIsFalseWhenTheOtherObjectHasADifferentIdentifier() { | ||
| Identifiable subject = newIdentifiableImpl(IDENTIFIER); | ||
| Identifiable other = newIdentifiableImpl(OTHER_IDENTIFIER); | ||
|
|
||
| assertThat(subject.matchesIdentity(other)) | ||
| .describedAs("matchesIdentity() for objects with different identifiers") | ||
| .isFalse(); | ||
| } | ||
|
|
||
| /** | ||
| * {@code matchesIdentity} widened its parameter to {@code @Nullable} - this | ||
| * is the defect that widening fixed: a {@code null} other used to be a | ||
| * {@code NullPointerException} risk, and must now just report no match. | ||
| */ | ||
| @Test | ||
| void matchesIdentityIsFalseWhenTheOtherObjectIsNull() { | ||
| Identifiable subject = newIdentifiableImpl(IDENTIFIER); | ||
|
|
||
| assertThat(subject.matchesIdentity(null)) | ||
| .describedAs("matchesIdentity(null)") | ||
| .isFalse(); | ||
| } | ||
|
|
||
| /** | ||
| * {@return an {@link Identifiable} whose {@link Identifiable#getIdentifier()} is the given identifier} | ||
| * | ||
| * @param identifier the identifier to return. | ||
| */ | ||
| private static Identifiable newIdentifiableImpl(final String identifier) { | ||
| return () -> identifier; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.