### Patching Object Changes with canonicalSet in Java Source: https://github.com/sqisher/java-object-diff/blob/master/docs/getting-started.md Shows how to apply changes from a `DiffNode` to a new object (e.g., a `HashMap`) using `node.canonicalSet()`. This example demonstrates merging changes into a 'head' map, specifically targeting leaf nodes with changes. ```Java final Map head = new HashMap(base); head.put("another", "map"); diff.visit(new DiffNode.Visitor() { public void node(DiffNode node, Visit visit) { // only leaf-nodes with changes if (node.hasChanges() && !node.hasChildren()) { node.canonicalSet(head, node.canonicalGet(working)); } } }); assert head.get("item").equals("foo"); assert head.get("another").equals("map"); ``` -------------------------------- ### Traversing Diff Nodes with Visitor Pattern in Java Source: https://github.com/sqisher/java-object-diff/blob/master/docs/getting-started.md Illustrates how to iterate over all `DiffNode` instances in the object graph using the `diff.visit()` method with a `DiffNode.Visitor` implementation. This allows processing each node's path and state. ```Java diff.visit(new DiffNode.Visitor() { public void node(DiffNode node, Visit visit) { System.out.println(node.getPath() + " => " + node.getState()); } }); ``` -------------------------------- ### Reading Base and Working Values from Diff Nodes in Java Source: https://github.com/sqisher/java-object-diff/blob/master/docs/getting-started.md Expands on node traversal by demonstrating how to retrieve the actual base and working values associated with each `DiffNode` using `node.canonicalGet()`. This allows printing detailed change messages. ```Java diff.visit(new DiffNode.Visitor() { public void node(DiffNode node, Visit visit) { final Object baseValue = node.canonicalGet(base); final Object workingValue = node.canonicalGet(working); final String message = node.getPath() + " changed from " + baseValue + " to " + workingValue; System.out.println(message); } }); ``` -------------------------------- ### Asserting DiffNode Changes and Child Count in Java Source: https://github.com/sqisher/java-object-diff/blob/master/docs/getting-started.md Shows how to verify if a `DiffNode` has changes, its child count, and the state of a specific child node using `NodePath` and `DiffNode.State.CHANGED`. ```Java assert diff.hasChanges(); assert diff.childCount() == 1; NodePath itemPath = NodePath.startBuilding().mapKey("item").build(); assert diff.getChild(itemPath).getState() == DiffNode.State.CHANGED; ``` -------------------------------- ### Creating a Diff for Java Maps Source: https://github.com/sqisher/java-object-diff/blob/master/docs/getting-started.md Demonstrates how to create a difference (diff) between two `java.util.Map` objects using `ObjectDifferBuilder.buildDefault().compare()`. The result is a `DiffNode` representing the root of the object graph. ```Java Map working = Collections.singletonMap("item", "foo"); Map base = Collections.singletonMap("item", "bar"); DiffNode diff = ObjectDifferBuilder.buildDefault().compare(working, base); ``` -------------------------------- ### ObjectDifferBuilder API Overview Source: https://github.com/sqisher/java-object-diff/blob/master/docs/user-guide.md The `ObjectDifferBuilder` serves as the primary entry point for all diffing operations, acting as a factory to obtain `ObjectDiffer` instances. It provides a comprehensive configuration API to customize the diffing process. ```APIDOC ObjectDifferBuilder: Description: Entry point for diffing operations. Role: Factory for ObjectDiffer instances. Features: Exposes a powerful configuration API for customization. ``` -------------------------------- ### ObjectDiffer API Overview Source: https://github.com/sqisher/java-object-diff/blob/master/docs/user-guide.md The `ObjectDiffer` is an instance created by the `ObjectDifferBuilder`. It takes two objects, referred to as 'working' and 'base', compares them, and returns a `DiffNode` representing the entire object graph. It is thread-safe and designed for reuse. ```APIDOC ObjectDiffer: Creation: Created by the ObjectDifferBuilder. Function: Compares two objects (working and base). Output: Returns a DiffNode representing the entire object graph. Thread_Safety: Thread-safe and reusable. Naming_Convention: 'working' (modified) and 'base' (original) for clarity, no technical constraint on their relationship. ``` -------------------------------- ### CategoryConfiguration API Source: https://github.com/sqisher/java-object-diff/blob/master/docs/user-guide.md This configuration allows assigning custom categories or tags to entire types or selected elements and properties. These categories are particularly useful when combined with the `InclusionConfiguration` to easily limit the comparison to a specific subset of the object graph. ```APIDOC CategoryConfiguration: Purpose: Assigns custom categories (tags) to entire types or selected elements and properties. Benefit: Very handy when combined with the InclusionConfiguration. Use_Case: Easily limit the comparison to a specific subset of the object graph. ``` -------------------------------- ### ComparisonConfiguration API Source: https://github.com/sqisher/java-object-diff/blob/master/docs/user-guide.md This configuration allows defining alternative comparison strategies for objects when introspection is not suitable, such as for performance reasons or when objects don't expose useful properties. Strategies include using the `equals` method, a `Comparator`, or a custom strategy, applicable to specific nodes or entire types. ```APIDOC ComparisonConfiguration: Purpose: Configures the way objects are compared. Alternatives_to_Introspection: - Use the equals method. - Use a Comparator. - Use a custom strategy. Scope: Settings can be made for specific nodes or entire types. Reasons: Performance, objects without useful properties. ``` -------------------------------- ### ReturnableNodeConfiguration API Source: https://github.com/sqisher/java-object-diff/blob/master/docs/user-guide.md This configuration allows excluding nodes from the object graph based on criteria known only after the diffing process for the node and its children is complete. Currently, it supports configuration based on the `DiffNode` state (added, changed, untouched). ```APIDOC ReturnableNodeConfiguration: Purpose: Excludes nodes from being added to the object graph. Criteria: Based on DiffNode state (added, changed, untouched) after diffing. Future_Possibilities: Matchers for dynamic criteria. ``` -------------------------------- ### InclusionConfiguration API Source: https://github.com/sqisher/java-object-diff/blob/master/docs/user-guide.md This configuration allows including or excluding nodes from comparison based on property name, object type, category, or location in the object graph. Excluded nodes are not compared, preventing calls to their accessors, which is useful for avoiding exceptions, expensive calls, or irrelevant properties. ```APIDOC InclusionConfiguration: Purpose: Includes or excludes nodes from comparison. Criteria: Property name, object type, category, or location in the object graph. Effect: Excluded nodes will not be compared (accessors won't get called). Use_Cases: - Avoid exceptions from getters. - Skip expensive or irrelevant accessors. - Combine with categories to define subsets of properties (e.g., exclude metadata). ``` -------------------------------- ### CircularReferenceConfiguration API Source: https://github.com/sqisher/java-object-diff/blob/master/docs/user-guide.md This configuration defines how the circular reference detector compares object instances. By default, it uses the equality operator (`==`). It can be switched to use the `equals` method for scenarios where objects might be different instances but logically the same, and allows registering custom handlers for detected circular references. ```APIDOC CircularReferenceConfiguration: Purpose: Defines how the circular reference detector compares object instances. Default_Comparison: Equality operator (==). Alternative_Comparison: Use equals() method for objects returning copies. Exception_Handling: - Register custom handler for exceptions thrown when a circular reference is detected. - Default handler logs a warning. ``` -------------------------------- ### IntrospectionConfiguration API Source: https://github.com/sqisher/java-object-diff/blob/master/docs/user-guide.md This configuration enables replacing the default bean introspector with a custom implementation. The default introspector, which uses `java.beans.Introspector`, is limited to getters and setters. Custom introspectors can be used for field introspection, set globally, or applied per-property, and introspection can be turned off for specific properties. ```APIDOC IntrospectionConfiguration: Purpose: Replaces the default bean introspector with a custom implementation. Default_Introspector: Uses java.beans.Introspector (limited to getters/setters). Customization: - Use custom introspector for field introspection. - Set as global default or on a per-property basis. - Turn off introspection for specific properties (compares via equals method). ``` -------------------------------- ### Compare Java Objects with Default Builder Source: https://github.com/sqisher/java-object-diff/blob/master/docs/index.md This snippet demonstrates the core functionality of the java-object-diff library. It shows how to use the ObjectDifferBuilder to create a default differ and compare two Java objects, 'workingObject' and 'baseObject', resulting in a 'Node' tree that represents the differences. This tree can then be traversed to identify specific changes. ```Java Node root = ObjectDifferBuilder.buildDefault().compare(workingObject, baseObject); ``` -------------------------------- ### Add Gradle Dependency for Java Object Diff Source: https://github.com/sqisher/java-object-diff/blob/master/README.md To include the `java-object-diff` library in a Gradle project, add the following line to your `build.gradle` file, typically within the `dependencies` block. This will allow Gradle to download and manage the library. ```Groovy compile 'de.danielbechler:java-object-diff:0.95' ``` -------------------------------- ### Add Maven Dependency for Java Object Diff Source: https://github.com/sqisher/java-object-diff/blob/master/README.md To include the `java-object-diff` library in a Maven project, add the following dependency block to your `pom.xml` file within the `` section. This will allow Maven to download and manage the library. ```XML de.danielbechler java-object-diff ``` -------------------------------- ### Perform Deep Object Comparison Source: https://github.com/sqisher/java-object-diff/blob/master/README.md This core snippet demonstrates how to use the ObjectDifferBuilder to perform a deep comparison between two Java objects. It returns a DiffNode root, representing a tree structure of differences, abstracting away the complexities of recursive comparison for collections and nested objects. ```java DiffNode root = ObjectDifferBuilder.buildDefault().compare(workingObject, baseObject); ``` -------------------------------- ### Add java-object-diff Maven Dependency Source: https://github.com/sqisher/java-object-diff/blob/master/docs/maven.md This XML snippet shows the required dependency configuration to include the java-object-diff library in your Maven project's pom.xml file. Add this block within the section of your POM. ```XML de.danielbechler java-object-diff 0.95 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.