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

Allow index() to be overridden in sets and maps. #502

Merged
merged 1 commit into from Apr 22, 2018

Conversation

gjajoo
Copy link
Contributor

@gjajoo gjajoo commented Apr 9, 2018

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

@gjajoo gjajoo closed this Apr 9, 2018
@gjajoo gjajoo reopened this Apr 9, 2018
@nikhilnanivadekar
Copy link
Contributor

@gjajoo the Java-11-EA build has gone through.

@motlin motlin changed the title Resolve #475 Allow index() to be overridden in sets and maps. Apr 10, 2018
{
return UnifiedMap.newMap(capacity);
return new UnifiedMap<>(capacity, this.loadFactor);
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be public?

Copy link
Contributor Author

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()
Copy link
Contributor

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);
}
Copy link
Contributor

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()
Copy link
Contributor

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?

@motlin
Copy link
Contributor

motlin commented Apr 10, 2018 via email

@gjajoo
Copy link
Contributor Author

gjajoo commented Apr 11, 2018

Closing to restart failed build.

@gjajoo gjajoo closed this Apr 11, 2018
@gjajoo gjajoo reopened this Apr 11, 2018
@gjajoo
Copy link
Contributor Author

gjajoo commented Apr 11, 2018

As far as I know I have removed all the public api breaking changes. Please let me know if there are still any issues.

@nikhilnanivadekar
Copy link
Contributor

@motlin I was suggesting to create an entirely new Map implementation like UnifiedMapWithIndexOverride or something like that. It is possible to re-use most of the implementations from UnifiedMap with slight tweaks to use getIndex() method or something like that. This might be more work for less benefit, but I was looking at it from the perspective of not introducing any breaking changes.
However, if there are no breaking changes (Public API and Serialization) then we should be good.

@nikhilnanivadekar
Copy link
Contributor

@gjajoo please squash all the commits in to a single commit.
@motlin can you please review once all the commits are squashed?

I will be starting a release review for 9.2.0 over the next couple of days. Would like to include this change as well. Thanks!

… where appropriate

Unit tests for making sure Unified collections are indifferent to any override of index

Signed-off-by: Govind Jajoo <govind@aralis.global>
@gjajoo gjajoo reopened this Apr 20, 2018
@gjajoo
Copy link
Contributor Author

gjajoo commented Apr 20, 2018

@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.

@gjajoo gjajoo closed this Apr 20, 2018
@gjajoo gjajoo reopened this Apr 20, 2018
@nikhilnanivadekar
Copy link
Contributor

This is squashed correctly.
The Java 11 build is failing again, I will check that out later. Don't worry about the failing Java 11 builds.

@nikhilnanivadekar
Copy link
Contributor

This is squashed correctly.
The Java 11 build is failing again, I will check that out later. For now don't worry about the failing Java 11 builds.
@motlin can you please review?

Copy link
Contributor

@gs-rezaem gs-rezaem left a comment

Choose a reason for hiding this comment

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

Good work.

@nikhilnanivadekar
Copy link
Contributor

Since IP Validation is not running. Verified the ECA using IP Validation tool
image

@nikhilnanivadekar nikhilnanivadekar merged commit a2d1273 into eclipse:master Apr 22, 2018
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

4 participants