Coder Social home page Coder Social logo

Comments (3)

luispollo avatar luispollo commented on May 20, 2024

Cc: @robfletcher, @lorin

from java-object-diff.

luispollo avatar luispollo commented on May 20, 2024

@lorin just pointed out that this may be a duplicate of #96

from java-object-diff.

syzsh avatar syzsh commented on May 20, 2024

比较两个集合对象, 会执行de.danielbechler.diff.differ.CollectionDiffer比较器逻辑:

  • 遍历working集合中的每个元素, 如果不存在于base集合中, 则认为working集合新增了元素
  • 遍历base集合中的每个元素, 如果不存在于working集合中, 则认为working集合删除了元素
  • 元素同时存在于两个集合中, 才会继续比较每个属性的值, 这种情况你的配置才会生效

关键代码:

de.danielbechler.diff.differ.CollectionDiffer#compareInternally
de.danielbechler.diff.access.CollectionItemAccessor#get
de.danielbechler.diff.identity.EqualsIdentityStrategy#equals

判断集合中元素是否相同, 默认调用对象的equals方法, 基于此, 提供两种解决办法:

  1. 可以重写数据类的equalshashCode方法, 忽略添加ExcludedFromDiff注解的字段
  2. 自定义并配置IdentityStrategy

from java-object-diff.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.