How pareshnavalakha/object-diff works
Main Components
• Diff Compute Engine: At the heart of the project, represented by classes such as DiffComputeEngine and Engine. This component orchestrates the diff calculation process.
• Diff Calculators: Multiple calculators (e.g., ObjectDiffCalculator, SimpleCollectionDiffCalculator, ComplexCollectionDiffCalculator, MapDiffCalculator, ComplexObjectDiffCalculator) that perform domain-specific comparisons.
• Configuration & Caching: Classes under the config package (DefaultEngineConfiguration, ClassMetaDataConfiguration, ReflectionConfiguration) maintain settings, while the cache package (ClassMetadataCache) is used to optimize reflection metadata operations.
• Annotations: Custom annotations (Identifier, Description, Ignore, Order) applied on POJO getters to guide how properties are compared.
• Renderers: The renderer package (with Renderer and RenderingPreferences) facilitates the output of the diff results in various formats (with Excel Renderer explicitly mentioned).
• Supporting Utilities: Additional utility classes (e.g., ReflectionUtil, CollectionUtil, StringUtil, SummaryHelper) to handle lower-level operations.
• Data Transfer Objects (DTOs): Classes (like Diff, DiffResponse, ClassMetadata) that encapsulate the results and settings related to the diff process.
• Exceptions: A custom exception (NotSatisfactorilyTested) to capture any unique error states during processing.
Relationships and Interactions
• The DiffComputeEngine (or Engine) acts as the central controller. When its “findDifferences(before, after)” method is called, it delegates the diff task to one or more specialized DiffCalculator classes based on the type of data.
• The Calculators interact with the Configuration classes which determine parameters like whether to use reflection.
• The Calculators also use the utility classes (ReflectionUtil, CollectionUtil, etc.) and consult the cache (ClassMetadataCache) to speed up metadata lookups.
• The output of the diff computations is encapsulated in DTOs, which are then passed to Renderer classes to generate reports (for example, producing an Excel file).
• The custom annotations are used at the POJO level to affect the behavior of the diff calculators (e.g., which fields to compare, in what order, which fields to ignore, and how to display them).
Architectural Patterns/Design Principles
• Modularity and Separation of Concerns: Each package and component has its own responsibility (calculators for domain logic, config for settings, caching for performance, renderers for view/output, etc.).
• Configurability/Extensibility: The use of configuration classes and custom annotations allows developers to extend or alter the diff behavior with minimal changes.
• Use of Java 8 Features: The code leverages modern Java concepts like Streams (and Parallel Streams when appropriate) for performance.
Technology and Frameworks
• Java 8+ (with a dependency on Maven, as indicated by the pom.xml)
• Testing framework (evidenced by tests under src/test, indicating unit testing practices)
• CI/CD tools (Travis CI & Coveralls badges in the README indicate automated builds and test coverage reports)
Elements
• Clear labels for each component (e.g., "DiffComputeEngine", "ObjectDiffCalculator", "ComplexCollectionDiffCalculator", "Configuration", "Cache", "Renderer").
• “Configuration & Caching” as supportive modules that connect with the calculators.
• Optionally, add ancillary components such as “Utilities” that feed into calculators.