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

Match >= for compareTo if lifecycle events are Comparable #196

Merged
merged 3 commits into from
May 7, 2018

Conversation

ZacSweers
Copy link
Collaborator

@ZacSweers ZacSweers commented Apr 28, 2018

Resolves #192, this checks if the lifecycle even type is comparable and uses it in comparison checking. This works for enums as a convention, I can't think of any examples that don't abide by this, but also allows for overriding the behavior if necessary. The idea here is that if we target end event "B" from start event "A", any events after "B" should also be counted as stop points.

CC @jinatonic

Resolves #192, but I'm not totally sure this is the best approach as it assumes all enum-defined lifecycles go in order. As a convention, I can't think of any examples that don't abide by this. But if one ever did, it would no longer work.

Possible solutions if this is an issue in the future: Add a plugin hook to define custom enum boundary check, just say that if natural ordering fallthrough is not the right complexity then they should probably make a full class instead, or just make a simpler ScopeProvider.
@ZacSweers
Copy link
Collaborator Author

To be clear, I think we should move forward with this approach. I just think we're probably facing a trade-off whatever direction we take and would rather lean in the direction that does what users expect most of the time

@tonycosentini
Copy link
Contributor

Makes sense to me - one question though, can this have adverse effects for people upgrading?

@ZacSweers
Copy link
Collaborator Author

Going to punt on this for the 0.8.0 release while we figure out the behavior of this a bit more. Can do a bugfix release with what we land on easily though

// Match on enum ordinal in case we skip an event
final int targetOrdinal = ((Enum) endEvent).ordinal();
//noinspection unchecked
equalityFunction = (Function<E, Boolean>) new Function<Enum, Boolean>() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All java enums implement Comparable. You can use compareTo to get this behavior by default and allow consumers to provide their own if using custom enum events.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should we check if it implements comparable instead of being an instance of enum?

@ZacSweers ZacSweers changed the title Match >= for ordinals if lifecycle events are enums Match >= for compareTo if lifecycle events are Comparable May 7, 2018
@ZacSweers ZacSweers merged commit e484e7e into master May 7, 2018
@ZacSweers ZacSweers deleted the z/fixOnDestroyView branch May 7, 2018 22:48
@ZacSweers ZacSweers mentioned this pull request May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants