Newer
Older
comparator / README.md
@aljunggren aljunggren on 20 Oct 2021 926 bytes Refactored to chain of responsibility

Comparator

Compare objects by annotated member variables. Non-annotated members will be ignored.

public class User {
    @Comparable
    private String name;
}

Instantiate

Comparator comparator = new Comparator<T>(object1, object2);

Is Equal

boolean equal = comparator.isEqual()

Differences

List<Diff> diffs = comparator.compare();

Diff

  • name - Field name
  • value1 - value of object1 field
  • value2 - value of object2 field
  • clazz - Class containing the field that has a diff. This is useful for embedded objects.

Embedded Objects

Objects other than boxed types and Strings can be marked as @Comparable.

public class User {
    @Comparable
    private Address address;
}

public class Address {
    @Comparable
    private String city;
    private String state;
}

TODO

Add iterable handling

Dependencies

  • reflection-utils