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

returns unmodifiable sets #1071

Merged
merged 2 commits into from Apr 22, 2019
Merged

returns unmodifiable sets #1071

merged 2 commits into from Apr 22, 2019

Conversation

rvandoosselaer
Copy link
Contributor

Returns an unmodifiable set when retrieving the available animation names and available animation clips instead of an unmodifiable collection. fixes: #1070

…ames and available animation clips instead of an unmodifiable collection. fixes: #1070
@pspeed42
Copy link
Contributor

These changes create a LOT of garbage. The animation names one does so unnecessarily since it was already a set. No need to create a new one just to again wrap it in an unmodifiable wrapper.

I'm kind of against the clips -> Set change just because the data doesn't support it. There is no good reason to return Set here when a documentation change would do and not have as much garbage.

@rvandoosselaer
Copy link
Contributor Author

rvandoosselaer commented Apr 17, 2019

I agree with you concerning the animation names, I did wrap them in an UnmodifiableSet to keep in line with the current implementation but I indeed used an unnecessary wrapper set. Just need to be careful that the returned object is wrapped in a new object (be it collection or set) so the underlying map isn't modified.

For the Collection vs Set discussion, I don't really have a strong opinion. But a Set makes senses imo.

@pspeed42
Copy link
Contributor

For AnimClip objects, a set would make sense if it were already a set. But it isn't. Set is "nice to have" because it auto-documents. That's it. In this case, the same can be achieved by mentioning something in the javadoc... though I guess no one will ever really care because the names are already a set.

Also, while today's implementation may be one-to-one mapping between name and AnimClip instance, that is not a requirement of this part of the API and I think it's a mistake to reflect it here for "no good reason".

@stephengold
Copy link
Member

If it's not possible to convert Collection.values() to a Set without creating extra garbage, then we should skip the getAnimClips() half of the change. The change to getAnimClipsNames() still seems worthwhile.

@rvandoosselaer
Copy link
Contributor Author

rvandoosselaer commented Apr 18, 2019

I concur with avove remarks.
I’ll revert the change for the Collection.values() part, leaving it an unmodifiable collection. Effectively removing the overhead of wrapping it in a hashset and again wrapping it in an unmodifiable set, but adapting the javadoc as Paul mentioned to better describe the behaviour.

Is this an ok solution?

@stephengold
Copy link
Member

ok

@stephengold stephengold merged commit ffa1df2 into jMonkeyEngine:master Apr 22, 2019
@Ali-RS
Copy link
Member

Ali-RS commented Apr 22, 2019

@stephengold wasn't getAnimClips supposed to reverted back to return Collection ?

@pspeed42
Copy link
Contributor

Yep... this wasn't ready to apply yet, unfortunately. Still has the crappy duplication of hashset every time getAnimClips() is called... for no good reason other than "let's return a set"... which itself is also not a good reason.

@rvandoosselaer
Copy link
Contributor Author

I was/am on a short holiday during the easter weekend with no access to my pc. I'll create a new PR this evening with the discussed changes in it.

stephengold added a commit that referenced this pull request Apr 22, 2019
@stephengold
Copy link
Member

Oops! My bad.

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.

AnimComposer.getAnimClips() and .getAnimClipsNames() should return sets, not collections
4 participants