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

Google Guava support #80

Closed
tomazic89 opened this Issue Jan 9, 2015 · 9 comments

Comments

Projects
None yet
3 participants
@tomazic89

tomazic89 commented Jan 9, 2015

This is more an 'enhancement' than a bug I suppose.
javers.compare() doesn't detect changes in the object variables of type com.google.common.collectMultiMap.

Since Guava is increasingly used this feature would be nice to have.

Is it possible to register my own comparator for custom types? Can't find that in the documentation.

Thanks, Nejc

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Jan 9, 2015

Well, true, Guava's MultiMaps are nice. But, JaVers can't have dependency on Guava (as it meant to be a lightweight library).
For now there are no custom comparators, but it seams like a good idea. Could you propose an API for this custom comparators?

Lets, assume that custom comparator could be bounded to specified class (e.g MultiMap)
but what this comparator could produce, in terms of JaVers Change model. Do we need also custom Change here?

bests

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Jan 9, 2015

take a look at http://javers.org/javadoc_1.0.0/org/javers/core/diff/Change.html class hierarchy

That is what core javers comparators produce. Suppose we need also new custom Change type for MultiMaps ...

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Jan 9, 2015

Short answer is yes, we can develop a feature for registering custom comparators as far as they would produce one of existing Change classes. So for this case it would be existing http://javers.org/javadoc_1.0.0/org/javers/core/diff/changetype/map/MapChange.html class.

What do you think about that, would it solve your case?

@tomazic89

This comment has been minimized.

tomazic89 commented Jan 9, 2015

I respect lightweight decision and I'd also like to leave it like that.
I currently don't have a case that I would need Multimap attributes to be compared, but I believe that I will in the near future.
MapChange seems like a good class to start with and I believe that it would solve my case.
I can give it a closer look and maybe propose an API in 2 days, I'm totally overbooked till Sunday.

In my mind I was thinking of an API that would allow registering a Class type and a comparator for it which would be called wen such a class is encountered (maybe also expected ChangeType out of existing ones). That kind of API would allow users to simply generate custom diffs or even generating changes for unsupported types (Like Guava MultiMap). I'm not sure if this is possible right away without any extra dependencies, so as I said, will give it a closer look in a couple of days.
If get any ideas, I would be glad to test them.

KR, nejc

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Jan 13, 2015

ok, I'm starting to work on this issue, soon, I'll give you an insight into new API

bartoszwalacik added a commit that referenced this issue Jan 13, 2015

#80
CustomMapComparator
@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Jan 13, 2015

I have came up with this simple interface

/**
 * Custom Map comparator.
 * <br/>
 * Useful for classes that are logically maps but do not implement java.util.Map interface.
 * <br/><br/>
 *
 * Implementation should calculate diff between two maps of type T
 * and return the result as MapChange.
 * For example, T could be a Multimap from Guava.
 */
public interface CustomMapComparator<T> extends CustomPropertyComparator<T, MapChange>{

    MapChange compare(T left, T right);
}
@pszymczyk

This comment has been minimized.

Member

pszymczyk commented Jan 14, 2015

I have noticed that Jackson had resolved similiar problem:
https://github.com/FasterXML/jackson-databind/blob/master/src/test/java/com/fasterxml/jackson/databind/module/TestTypeModifiers.java#L218

The had MyMapLikeType and posibility to register custom modifiers

bartoszwalacik added a commit that referenced this issue Jan 16, 2015

#80
first test passing

bartoszwalacik added a commit that referenced this issue Jan 17, 2015

#80
passing test for Guava

bartoszwalacik added a commit that referenced this issue Jan 17, 2015

#80
unifying CustomPropertyComparator

bartoszwalacik added a commit that referenced this issue Jan 17, 2015

#80
javadoc

bartoszwalacik added a commit that referenced this issue Jan 17, 2015

#80
test fixes

bartoszwalacik added a commit that referenced this issue Jan 17, 2015

#80
javadoc

bartoszwalacik added a commit that referenced this issue Jan 18, 2015

#80
housekeeping
@bartoszwalacik

This comment has been minimized.

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Jan 20, 2015

give us a star if you like javers
https://github.com/javers/javers/stargazers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment