在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:SQiShER/java-object-diff开源软件地址:https://github.com/SQiShER/java-object-diff开源编程语言:Java 53.4%开源软件介绍:Introduction
Features
Support this ProjectIf you like this project, there are a few things you can do to show your support:
But most importantly: don't ever hesitate to ask me for help, if you're having trouble getting this library to work. The only way to make it better is by hearing about your use-cases and pushing the limits! Getting StartedTo learn how to use Java Object Diff have a look at the Getting Started Guide. Using with Maven<dependency>
<groupId>de.danielbechler</groupId>
<artifactId>java-object-diff</artifactId>
<version>0.95</version>
</dependency> Using with Gradlecompile 'de.danielbechler:java-object-diff:0.95' DocumentationThe documentation can be found over at ReadTheDocs. Caveats
Why would you need this?Sometimes you need to figure out, how one version of an object differs from another one. One of the simplest solutions that'll cross your mind is most certainly to use reflection to scan the object for fields or getters and use them to compare the values of the different object instances. In many cases this is a perfectly valid strategy and the way to go. After all, we want to keep things simple, don't we? However, there are some cases that can increase the complexity dramatically. What if you need to find differences in collections or maps? What if you have to deal with nested objects that also need to be compared on a per-property basis? Or even worse: what if you need to merge such objects? You suddenly realize that you need to scan the objects recursively, figure out which collection items have been added, removed or changed; find a way to return your results in a way that allows you to easily access the information you are looking for and provide accessors to apply changes. While all this isn't exactly rocket science, it is complex enough to add quite a lot of extra code to your project. Code that needs to be tested and maintained. Since the best code is the code you didn't write, this library aims to help you with all things related to diffing and merging of Java objects by providing a robust foundation and a simple, yet powerful API. This library will hide all the complexities of deep object comparison behind one line of code: DiffNode root = ObjectDifferBuilder.buildDefault().compare(workingObject, baseObject); This generates a tree structure of the given object type and lets you traverse its nodes via visitors. Each node represents one property (or collection item) of the underlying object and tells you exactly if and how the value differs from the base version. It also provides accessors to read, write and remove the value from or to any given instance. This way, all you need to worry about is how to treat changes and not how to find them. This library has been battle-tested in a rather big project of mine, where I use it to generate activity streams, resolve database update conflics, display change logs and limit the scope of entity updates to only a subset of properties, based on the context or user permissions. It didn't let me down so far and I hope it can help you too! ContributeYou discovered a bug or have an idea for a new feature? Great, why don't you send me a Pull Request so everyone can benefit from it? To help you getting started, here is a brief guide with everyting you need to know to get involved! Thanks to JetBrains for supporting this project with a free open source license for their amazing IDE IntelliJ IDEA. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论