Skip to content

How to diff Lists? #42

Open
Open
@bartswen

Description

@bartswen

First of all, thanks for this great library!

I was wondering what is your idea about comparing collections? The DelegatingObjectDifferImpl uses the CollectionDiffer to compare both Sets and Lists. While List order is relevant, the differ does not detect changes in the order of the items.

Consider this code:

List<String> left = Arrays.asList("aaa", "bbb", "ccc");
List<String> right = Arrays.asList("aaa", "ccc", "bbb");
ObjectDiffer objectDiffer = ObjectDifferFactory.getInstance();
final Node root = objectDiffer.compare(left, right);
System.out.println("Equals: " + left.equals(right));
root.visit(new PrintingVisitor(left, right));

Results in:

Equals: false
Property at path '/' has not changed

The items 1 and 2 were swapped so the equals says 'false', but this was not detected as a change. Is this behaviour as intended? I would say that the List deserves a ListDiffer.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions