|
| 1 | +--- |
| 2 | +title: Nodes Comparison |
| 3 | +sidebar_position: 46 |
| 4 | +--- |
| 5 | + |
| 6 | +# Nodes Comparison |
| 7 | + |
| 8 | +The lionweb-java project provides comprehensive model comparison capabilities through the `io.lionweb.utils.ModelComparator` class. |
| 9 | + |
| 10 | +The `ModelComparator` enables detailed comparison of models, nodes, and classifier instances to identify structural and semantic differences between them. |
| 11 | + |
| 12 | +## Comparison Methods |
| 13 | + |
| 14 | +The `ModelComparator` provides several overloaded `compare()` methods for different types of elements: |
| 15 | + |
| 16 | +- **Node Comparison**: Compare two `Node` objects |
| 17 | +- **AnnotationInstance Comparison**: Compare two `AnnotationInstance` objects |
| 18 | +- **ClassifierInstance Comparison**: Compare two `ClassifierInstance` objects (polymorphic) |
| 19 | + |
| 20 | +## Static Equivalence Checking |
| 21 | + |
| 22 | +Convenience methods for quick equivalence checks: |
| 23 | + |
| 24 | +- `areEquivalent(ClassifierInstance<?> a, ClassifierInstance<?> b)`: Check if two classifier instances are equivalent |
| 25 | +- `areEquivalent(List<A> as, List<B> bs)`: Check if two lists of classifier instances are equivalent |
| 26 | + |
| 27 | +## ComparisonResult |
| 28 | + |
| 29 | +The `ComparisonResult` class encapsulates the outcome of a comparison operation: |
| 30 | + |
| 31 | +### Key Features |
| 32 | + |
| 33 | +- **Difference Tracking**: Maintains a list of all detected differences |
| 34 | +- **Equivalence Check**: Provides `areEquivalent()` method that returns `true` when no differences exist |
| 35 | +- **Detailed Reporting**: Contains methods to mark specific types of differences |
| 36 | + |
| 37 | +### Types of Differences Detected |
| 38 | + |
| 39 | +1. **ID Differences**: Different node IDs |
| 40 | +2. **Concept Differences**: Different concept/classifier assignments |
| 41 | +3. **Property Value Differences**: Different values for properties |
| 42 | +4. **Containment Differences**: Different numbers or values of child nodes |
| 43 | +5. **Reference Differences**: Different reference targets or resolve information |
| 44 | +6. **Annotation Differences**: Different numbers or values of annotations |
| 45 | +7. **Incompatibility**: When instances cannot be compared (different types) |
| 46 | + |
| 47 | +## Comparison Aspects |
| 48 | + |
| 49 | +The `ModelComparator` performs deep comparison across multiple dimensions: |
| 50 | + |
| 51 | +### 1. **Properties** |
| 52 | +Compares all property values defined by the classifier, identifying any discrepancies in property data. |
| 53 | + |
| 54 | +### 2. **References** |
| 55 | +Compares reference values including: |
| 56 | +- Number of references |
| 57 | +- Referenced node IDs |
| 58 | +- Resolve information for each reference |
| 59 | + |
| 60 | +### 3. **Containments** |
| 61 | +Compares child nodes including: |
| 62 | +- Number of children in each containment |
| 63 | +- Recursive comparison of child node structures |
| 64 | + |
| 65 | +### 4. **Annotations** |
| 66 | +Compares annotations including: |
| 67 | +- Number of annotations |
| 68 | +- Annotation IDs and structures |
| 69 | + |
| 70 | +### 5. **Structure** |
| 71 | +Validates structural consistency including: |
| 72 | +- Parent-child relationships |
| 73 | +- Concept/classifier assignments |
| 74 | +- Node hierarchy |
| 75 | + |
| 76 | +## Use Cases |
| 77 | + |
| 78 | +- **Testing**: Verify that model transformations produce expected results |
| 79 | +- **Validation**: Ensure model consistency across operations |
| 80 | +- **Debugging**: Identify unexpected changes in models |
| 81 | +- **Serialization/Deserialization**: Verify round-trip integrity |
| 82 | +- **Version Control**: Compare model versions to detect changes |
| 83 | + |
| 84 | +## Context Information |
| 85 | + |
| 86 | +All differences are reported with contextual information including: |
| 87 | +- Location in the model hierarchy |
| 88 | +- Node IDs involved |
| 89 | +- Specific feature or property names |
| 90 | +- Index positions for list elements |
0 commit comments