-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAssociationComparer.cs
More file actions
134 lines (112 loc) · 5.63 KB
/
AssociationComparer.cs
File metadata and controls
134 lines (112 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// -------------------------------------------------------------------------------------------------
// <copyright file="AssociationComparer.cs" company="Starion Group S.A.">
//
// Copyright (C) 2022-2026 Starion Group S.A.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!--------
// ------------------------------------------------------------------------------------------------
namespace SysML2.NET.Extensions.Core.DTO.Comparers
{
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using SysML2.NET.Core.DTO.Kernel.Associations;
using SysML2.NET.Extensions.Comparers;
/// <summary>
/// Provides an equality comparison for <see cref="IAssociation"/> instances
/// based on their semantic content rather than object reference identity.
/// </summary>
/// <remarks>
/// This comparer is intended for use in deserialization, testing, and model
/// validation scenarios where two <see cref="IAssociation"/> instances
/// originating from different sources (e.g. JSON and MessagePack) must be
/// considered equal if they represent the same SysML v2 model element.
/// </remarks>
[GeneratedCode("SysML2.NET", "latest")]
public sealed class AssociationComparer : IEqualityComparer<IAssociation>
{
/// <summary>
/// The <see cref="StringComparer"/> used for all string comparisons performed
/// by this comparer.
/// </summary>
/// <remarks>
/// <see cref="StringComparer.Ordinal"/> is used to ensure culture-independent,
/// deterministic comparison semantics suitable for identifiers and
/// model-level string values.
/// </remarks>
private static readonly StringComparer OrdinalStringComparer = StringComparer.Ordinal;
/// <summary>
/// Determines whether two <see cref="IAssociation"/> instances are equal.
/// </summary>
/// <param name="x">
/// The first <see cref="IAssociation"/> to compare.
/// </param>
/// <param name="y">
/// The second <see cref="IAssociation"/> to compare.
/// </param>
/// <returns>
/// <c>true</c> if both instances represent the same <see cref="IAssociation"/>
/// according to their semantic content; otherwise, <c>false</c>.
/// </returns>
/// <remarks>
/// This method performs a deep, deterministic comparison of all relevant
/// properties, ignoring object reference identity and any transient or
/// derived state.
/// </remarks>
public bool Equals(IAssociation x, IAssociation y)
{
if (ReferenceEquals(x, y)) return true;
if (x is null || y is null) return false;
if (x.Id != y.Id) return false;
if (!StringSequenceEquality.OrderedEqual(x.AliasIds, y.AliasIds)) return false;
if (!OrdinalStringComparer.Equals(x.DeclaredName, y.DeclaredName)) return false;
if (!OrdinalStringComparer.Equals(x.DeclaredShortName, y.DeclaredShortName)) return false;
if (!OrdinalStringComparer.Equals(x.ElementId, y.ElementId)) return false;
if (x.IsAbstract != y.IsAbstract) return false;
if (x.IsImplied != y.IsImplied) return false;
if (x.IsImpliedIncluded != y.IsImpliedIncluded) return false;
if (x.IsSufficient != y.IsSufficient) return false;
if (!GuidSequenceEquality.OrderedEqual(x.OwnedRelatedElement, y.OwnedRelatedElement)) return false;
if (!GuidSequenceEquality.OrderedEqual(x.OwnedRelationship, y.OwnedRelationship)) return false;
if (x.OwningRelatedElement != y.OwningRelatedElement) return false;
if (x.OwningRelationship != y.OwningRelationship) return false;
return true;
}
/// <summary>
/// Returns a hash code for the specified <see cref="IAssociation"/>.
/// </summary>
/// <param name="obj">
/// The <see cref="IAssociation"/> for which a hash code is to be returned.
/// </param>
/// <returns>
/// A hash code based on the stable identity of the element.
/// </returns>
/// <remarks>
/// The hash code is intentionally derived from the element identity only,
/// ensuring stability and compatibility with collection-based equality
/// checks
/// </remarks>
public int GetHashCode(IAssociation obj)
{
return HashCode.Combine(typeof(IAssociation), obj.Id);
}
}
}
// ------------------------------------------------------------------------------------------------
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!--------
// ------------------------------------------------------------------------------------------------