-
Notifications
You must be signed in to change notification settings - Fork 18
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
Generics Refactor #170
Merged
Merged
Generics Refactor #170
Conversation
This file contains 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
contextual differences between NIP-related classes and non-NIP-related classes have been separated
begin increase unit test coverage
… (it's type is always Filters)
hi, eric. assuming this PR gets accepted/merged, i'll next refactor from explicit case/switch logic in:
to polymorphic implementation provided by related subclasses of the two |
Many thanks for this!! I will be working on it ASAP. |
tcheeric
approved these changes
May 31, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
systematic base-level generics (mis)configuration results in improper/forced downstream (over)casting use- which propagates further abuse/misuse of generic types. this PR rectifies those base-level issues and all existing classes that use them.
below is a general description of PR code changes or jump directly to PR code diffs and refer to the description here as contextual reference for code changes.
note: although numerous, each PR change is quite small, including unit tests- which all continue to pass.
to that end, i've also introduced jacoco code-coverage metrics/report plugin as a part of this PR. jacoco is lightweight java developer community standard unit/integration- testing tool which integrates automatically into maven build process (via maven-surefire plugin) and generates useful visual/navigable metrics for every class' code coverage/un-coverage.
to view/nagivate the report/metrics- perform your build as usual then simply point a browser to:
nostr-java-test/target/site/jacoco-aggregate/index.html
description of PR changes:
IElement
since IElement is not appropriate for classes which are not nips:
Filters
GenericTagQuery
the use of:
GenericTagQuery implements IElement
Filters extends BaseEvent (which implements IElement)
are now refactored to proper form:
GenericTagQuery
Filters
IDecoder
IDecoder<IElement>
now properly properly genericized asIDecoder<T extends IElement>
formerly used via:
GenericEventDecoder implements IDecoder<BaseMessage>
Nip05ContentDecoder implements IDecoder<BaseMessage>
BaseMessageDecoder implements IDecoder<BaseMessage>
GenericTagDecoder implements IDecoder<BaseMessage>
BaseTagDecoder implements IDecoder<BaseMessage>
now refactored to proper generic form:
GenericEventDecoder<T extends GenericEvent> implements IDecoder<T>
Nip05ContentDecoder<T extends Nip05Content> implements IDecoder<T>
BaseMessageDecoder <T extends BaseMessage> implements IDecoder<T>
GenericTagDecoder <T extends GenericTag> implements IDecoder<T>
BaseTagDecoder <T extends BaseTag> implements IDecoder<T>
decoding non-NIP classes
since IElement is not appropriate for classes which are not nips:
Filters
GenericTagQuery
the use of
IDecoder<IElement>
is contextually incorrect for those classes.FDecoder<T>
has been introduced for them instead.formerly used via:
FiltersDecoder implements IDecoder<Filters>
FiltersListDecoder implements IDecoder<FiltersList>
GenericTagQueryDecoder implements IDecoder<GenericTagQuery>
now refactored to proper generic form:
FiltersDecoder implements FDecoder<Filters>
FiltersListDecoder implements FDecoder<Filters>
GenericTagQueryDecoder<T extends GenericTagQuery> implements FDecoder<T>
IEncoder
IEncoder<IElement>
now properly properly genericized as:
IEncoder<T extends IElement>
formerly used via:
BaseEventEncoder implements IEncoder<BaseEvent>
BaseMessageEncoder implements IEncoder<BaseMessage>
GenericTagEncoder implements IEncoder<GenericTag>
now refactored to proper generic form:
BaseEventEncoder <T extends BaseEvent> implements IEncoder<T>
BaseMessageEncoder<T extends BaseMessage> implements IEncoder<T>
GenericTagEncoder <T extends GenericTag> implements IEncoder<T>
encoding non-NIP classes
since IElement is not appropriate for classes which are not nips:
Filters
GenericTagQuery
the use of
IEncoder<IElement>
is contextually incorrect for those classes.FDecoder<T>
has been introduced for them instead.formerly used via:
FiltersEncoder extends BaseEventEncoder (which implements IEncoder<T>)
FiltersListEncoder extends BaseEventEncoder (which implements IEncoder<T>)
GenericTagQueryEncoder implements IEncoder<GenericTagQuery>
now refactored to proper generic form:
FiltersEncoder implements FEncoder<T>
FiltersListEncoder implements FEncoder<T>
GenericTagQueryEncoder<T extends GenericTagQuery> implements FEncoder<T>
deserializers
JsonDeserializer<[some explicit type]>
now properly properly genericized asJsonDeserializer<T>
formerly used via:
CustomGenericTagQueryListDeserializer extends JsonDeserializer<GenericTagQueryList>
CustomGenericTagQueryListSerializer extends JsonSerializer<GenericTagQueryList>
CustomPublicKeyListDeserializer extends JsonDeserializer<PublicKeyList>
CustomEventListDeserializer extends JsonDeserializer<EventList>
CustomIdEventListSerializer extends JsonSerializer<EventList>
CustomBaseListSerializer extends JsonSerializer<BaseList>
now refactored to proper generic form:
CustomGenericTagQueryListDeserializer<T extends GenericTagQueryList<U>, U extends GenericTagQuery> extends JsonDeserializer<T>
CustomGenericTagQueryListSerializer <T extends GenericTagQueryList<U>, U extends GenericTagQuery> extends JsonSerializer<T>
CustomPublicKeyListDeserializer <T extends PublicKeyList<U>, U extends PublicKey> extends JsonDeserializer<T>
CustomEventListDeserializer <T extends EventList<U>, U extends GenericEvent> extends JsonDeserializer<T>
CustomIdEventListSerializer <T extends EventList<U>, U extends GenericEvent> extends JsonSerializer<T>
CustomBaseListSerializer <T extends BaseList<U>, U extends BaseEvent> extends JsonSerializer<T>
INostrList
since
interface INostrList<T> extends IElement
exclusively pushes List responsibilies up to implementing classes, it has been converted to an abstracdt class w/ generic behavior refactored into it.formerly used via:
BaseList<T> implements INostrList<T>
now refactored to proper generic form:
BaseList<T extends BaseEvent> extends INostrList<T> implements IElement
and it's subclasses formerly used via:
EventList extends BaseList<GenericEvent>
now refactored to proper generic form
EventList<T extends GenericEvent> extends BaseList<T>
BaseList
since BaseList is not appropriate for classes which are not nips:
FiltersList
the use of
extends BaseList<[some explicit type]>
is contextually incorrect for those classes.FNostrList<T>
has been introduced for them instead.formerly used via:
GenericTagQueryList extends BaseList<GenericTagQuery> (which implements INostrList<T>)
PublicKeyList extends BaseList<PublicKey>
KindList extends BaseList<Integer> (which implements INostrList<T>)
now refactored to proper generic form
GenericTagQueryList<T extends GenericTagQuery> extends FNostrList<T>
PublicKeyList <T extends PublicKey> extends INostrList<T>
KindList extends FNostrList<Integer>
Filters
formerly
Filters extends BaseEvent
now simply:
Filters