Nodes Comparison
The lionweb-java project provides comprehensive model comparison capabilities through the io.lionweb.utils.ModelComparator class.
The ModelComparator enables detailed comparison of models, nodes, and classifier instances to identify structural and semantic differences between them.
Comparison Methods
The ModelComparator provides several overloaded compare() methods for different types of elements:
- Node Comparison: Compare two
Nodeobjects - AnnotationInstance Comparison: Compare two
AnnotationInstanceobjects - ClassifierInstance Comparison: Compare two
ClassifierInstanceobjects (polymorphic)
Static Equivalence Checking
Convenience methods for quick equivalence checks:
areEquivalent(ClassifierInstance<?> a, ClassifierInstance<?> b): Check if two classifier instances are equivalentareEquivalent(List<A> as, List<B> bs): Check if two lists of classifier instances are equivalent
ComparisonResult
The ComparisonResult class encapsulates the outcome of a comparison operation:
Key Features
- Difference Tracking: Maintains a list of all detected differences
- Equivalence Check: Provides
areEquivalent()method that returnstruewhen no differences exist - Detailed Reporting: Contains methods to mark specific types of differences
Types of Differences Detected
- ID Differences: Different node IDs
- Concept Differences: Different concept/classifier assignments
- Property Value Differences: Different values for properties
- Containment Differences: Different numbers or values of child nodes
- Reference Differences: Different reference targets or resolve information
- Annotation Differences: Different numbers or values of annotations
- Incompatibility: When instances cannot be compared (different types)
Comparison Aspects
The ModelComparator performs deep comparison across multiple dimensions:
1. Properties
Compares all property values defined by the classifier, identifying any discrepancies in property data.
2. References
Compares reference values including:
- Number of references
- Referenced node IDs
- Resolve information for each reference
3. Containments
Compares child nodes including:
- Number of children in each containment
- Recursive comparison of child node structures
4. Annotations
Compares annotations including:
- Number of annotations
- Annotation IDs and structures
5. Structure
Validates structural consistency including:
- Parent-child relationships
- Concept/classifier assignments
- Node hierarchy
Use Cases
- Testing: Verify that model transformations produce expected results
- Validation: Ensure model consistency across operations
- Debugging: Identify unexpected changes in models
- Serialization/Deserialization: Verify round-trip integrity
- Version Control: Compare model versions to detect changes
Context Information
All differences are reported with contextual information including:
- Location in the model hierarchy
- Node IDs involved
- Specific feature or property names
- Index positions for list elements