BaseList (and all other custom List implementations) refactor #171
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.
hi, eric. per your consideration, upon careful attention to
@guilherme
comment inBaseList.java
, commit2803d1111af47069d7470e6917c7d714d527f3d0
:diff --git a/nostr-java-event/src/main/java/nostr/event/list/BaseList.java b/nostr-java-event/src/main/java/nostr/event/list/BaseList.java
index f23837a..054c9d4 100644
--- a/nostr-java-event/src/main/java/nostr/event/list/BaseList.java
+// TODO: Why are we using this instead of just use a regular java collection?
<--- @guilherme's commenti think he is absolutely correct. it appears the existence of
BaseList
customList
implementation is exclusively used to enforce uniqueness when adding items to a list:which instead, can- and should- be achieved by using
Set
rather thanList
.in general, extending
List/Collection
implementations are commonly considered an anti-pattern (turns out, commonly known as pseudo-type) for the following reasons among others:to that end, i experimented with a quick refactoring of all code requiring custom List implementations:
which have now been removed and all existing project classes (in particular, classes implementing
IElement
still do implement it) refactored as below, with all unit tests passing (and incidentally, my nostr-relay implementation, which relies heavily on these classes and their serializers/deserializers), functioning as expected:before:
EventList<GenericEvent> events;
after:
List<GenericEvent> events;
before:
PublicKeyList<PublicKey> authors;
after:
List<PublicKey> authors;
before:
KindList kinds;
after:
List<Kind> kinds;
before:
EventList<GenericEvent> referencedEvents
after:
List<GenericEvent> referencedEvents;
before:
PublicKeyList<PublicKey> referencePubKeys;
after:
List<PublicKey> referencePubKeys;
anyway, just wanted to bring the consideration to your attention and provide this PR as an alternate/"correct" implementation if you think there's value to it.