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

Comparing CharSequence property of different types returns ValueChange for same value #262

Closed
rschertz opened this issue Dec 3, 2015 · 4 comments

Comments

@rschertz
Copy link

rschertz commented Dec 3, 2015

This is related to comparing CharSequence values in issue #250.

Having looked into the implementation of an Avro Utf8 string, I added a test to compare CharSequence property values where the value instances are of different types.

Adding the test below to Case250CharSequence.java:

@Test
public void shouldCompareTwoObjectsWithCharSequencePropertiesOfDifferentTypes() {
    //given
    Javers javers = JaversBuilder.javers().build();

    AvroAddress oldVersion = new AvroAddress("New York", "First Avenue");
    AvroAddress currentVersion = new AvroAddress(new Utf8("New York"), new Utf8("Second Avenue"));

    //when
    Diff diff = javers.compare(oldVersion, currentVersion);

    //then
    //there should be one change of type {@link ValueChange}
    ValueChange change = diff.getChangesByType(ValueChange.class).get(0);

    assertThat(diff.getChanges()).hasSize(1);
    assertThat(change.getProperty().getName()).isEqualTo("street");
    assertThat(change.getLeft()).isEqualTo(oldVersion.getStreet());
    assertThat(change.getRight()).isEqualTo(currentVersion.getStreet());

    System.out.println(diff);
}

I expected (well, hoped) that the String value "New York" would compare to the Avro Utf8 value "New York", however the city property values are identified as a ValueChange.

java.lang.AssertionError: expected size:<1> but was:<2> in:<[ValueChange{globalId:'com.maxpoint.minion.monitor.change.JaVersAvroUtf8Test$AvroAddress/', property:'city', oldVal:'New York', newVal:'New York'}, ValueChange{globalId:'com.maxpoint.minion.monitor.change.JaVersAvroUtf8Test$AvroAddress/', property:'street', oldVal:'First Avenue', newVal:'Second Avenue'}]>

Caveat from the 'CharSequence.java' documentation:

  • This interface does not refine the general contracts of the {@link

  • java.lang.Object#equals(java.lang.Object) equals} and {@link
  • java.lang.Object#hashCode() hashCode} methods. The result of comparing two
  • objects that implement CharSequence is therefore, in general,
  • undefined. Each object may be implemented by a different class, and there
  • is no guarantee that each class will be capable of testing its instances
  • for equality with those of the other. It is therefore inappropriate to use
  • arbitrary CharSequence instances as elements in a set or as keys in
  • a map.

Questions: How should the diff engine treat this value type comparison? Can the diff engine reliably suppress this as appearing as a ValueChange?

Note: I have considered experimenting with a custom comparator, but have not yet.

Thanks,
Rick

@bartoszwalacik
Copy link
Member

Hi @rschertz , we are moving Q&A to stackoverflow, see http://stackoverflow.com/questions/tagged/javers?sort=newest
Could you please move this question there?

I dont know much about Avro Utf8 String. JaVers compares ValueTypes using equals().
new Utf8("new york").equals("new york") is true or false?
If false, than you can try to register CustomComparator for CharSequence.

@rschertz
Copy link
Author

rschertz commented Dec 6, 2015

I wasn't certain where to add that question. Yes, I can move the question
there. Plus look into a CustomComparator.

Thanks,
Rick

On Sat, Dec 5, 2015 at 4:44 PM, Bartosz Walacik notifications@github.com
wrote:

Hi @rschertz https://github.com/rschertz , we are moving Q&A to
stackoverflow, see
http://stackoverflow.com/questions/tagged/javers?sort=newest
Could you please move this question there?

I dont know much about Avro Utf8 String. JaVers compares ValueTypes using
equals().
new Utf8("new york").equals("new york") is true or false?
If false, than you can try to register CustomComparator for CharSequence.


Reply to this email directly or view it on GitHub
#262 (comment).

@bartoszwalacik
Copy link
Member

let me know when you post this question at Stack

@bartoszwalacik
Copy link
Member

closing due to lack of activity

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

No branches or pull requests

2 participants