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
Allow index() to be overridden in sets and maps. #502
Conversation
|
@gjajoo the Java-11-EA build has gone through. |
| { | ||
| return UnifiedMap.newMap(capacity); | ||
| return new UnifiedMap<>(capacity, this.loadFactor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea, but it breaks backwards compatibility, so we probably need to merge it when preparing a major version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider creating a new Map implementation which extends UnifiedMap but has a non-final index? That way we don't break backwards compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@motlin Actually I changed this more out of consistency in mind. We can keep the return type the same (MutableMap) and cast it to UnifiedMap when we call it internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gjajoo Changing the return type to a subtype is probably fine. It's source compatible anyway, I'd have to check if it's also binary compatible. I meant adding generic types to an existing method isn't backwards compatible. I like the idea, just wanted to highlight the change since we're very careful about compatibility, and gather breaking changes in major version releases.
| { | ||
| return UnifiedMapWithHashingStrategy.newMap(this.hashingStrategy, capacity); | ||
| return new UnifiedMapWithHashingStrategy<>(this.hashingStrategy, capacity, this.loadFactor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your change to UnifiedMap.newEmpty(), you allowed the generic types to vary. Here we're passing the hashing strategy as a parameter, so we cannot allow K to vary. But we could allow V to vary, right? It's still a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@motlin similar to the comment above, we don't need to change the newEmpty signature. Where we call it in retainAll we just know newEmpty is expected to return a UnifiedMap or it's derivative so we can cast it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@motlin We could allow V to vary, yes but I couldn't find a way to convince the compiler that only V varied. It was either vary both K and V or none.
| @Override | ||
| public UnifiedSet<T> newEmpty(int size) | ||
| { | ||
| return UnifiedSet.newSet(size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you pass loadFactor here for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, will change that.
| super(initialCapacity, loadFactor); | ||
| } | ||
|
|
||
| UnifiedMapOverrides(Map<? extends K, ? extends V> map) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@motlin The only reason that one constructor is public is because it's invoked using reflection. It does stick out like a sore thumb so I'll make the rest of them public too.
| } | ||
|
|
||
| @Override | ||
| public <K, V> MutableMap<K, V> newMap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change the return type to UnifiedMap here, and then basically combine the two methods into one?
| UnifiedMapWithHashingStrategyOverrides(HashingStrategy<? super K> hashingStrategy, int capacity, float loadFactor) | ||
| { | ||
| super(hashingStrategy, capacity, loadFactor); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these constructors be public?
| } | ||
|
|
||
| @Override | ||
| public <K, V> MutableMap<K, V> newMap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, could the return type be UnifiedMapWithHashingStrategy?
|
Not sure I understand. You can’t use inheritance to turn something private
or final into non private or non final.
…On Tue, Apr 10, 2018 at 9:19 AM Nikhil Nanivadekar ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
eclipse-collections/src/main/java/org/eclipse/collections/impl/map/mutable/UnifiedMap.java
<#502 (comment)>
:
> {
- return UnifiedMap.newMap(capacity);
+ return new UnifiedMap<>(capacity, this.loadFactor);
Should we consider creating a new Map implementation which extends
UnifiedMap but has a non-final index? That way we don't break backwards
compatibility
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#502 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAO6Iu22vn1ScjKHhhgyuQtOTz7gtbJFks5tnLFjgaJpZM4TM_0y>
.
|
|
Closing to restart failed build. |
|
As far as I know I have removed all the public api breaking changes. Please let me know if there are still any issues. |
|
@motlin I was suggesting to create an entirely new Map implementation like |
… where appropriate Unit tests for making sure Unified collections are indifferent to any override of index Signed-off-by: Govind Jajoo <govind@aralis.global>
|
@nikhilnanivadekar I wasn't sure what the right way to squash the commits on github is (I thought it's done when pulling in the request). Anyway I just reset and forced push a single commit with all the changes. Hope that works. Please let me know if there's a better way. |
|
This is squashed correctly. |
|
This is squashed correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work.

Unit tests rely on Map/Set being able to clone or create empty copies of themselves. Most changes to code are due to that.