Skip to content
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 11 commits into from
May 31, 2024
Merged

Generics Refactor #170

merged 11 commits into from
May 31, 2024

Conversation

avlo
Copy link
Collaborator

@avlo avlo commented May 30, 2024

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

nostr-java-test-jacoco-report


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 as IDecoder<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 as JsonDeserializer<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

@avlo
Copy link
Collaborator Author

avlo commented May 30, 2024

hi, eric. assuming this PR gets accepted/merged, i'll next refactor from explicit case/switch logic in:

BaseMessageDecoder
BaseMessageEncoder

to polymorphic implementation provided by related subclasses of the two

@tcheeric
Copy link
Owner

Many thanks for this!! I will be working on it ASAP.

@tcheeric tcheeric merged commit 6934f8d into tcheeric:develop May 31, 2024
@avlo avlo deleted the refactor_generics branch May 31, 2024 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants