1
1
namespace Microsoft . ComponentDetection . Orchestrator . Experiments . Models ;
2
2
3
3
using System . Collections . Generic ;
4
+ using System . Collections . Immutable ;
4
5
using System . Linq ;
5
6
6
7
/// <summary>
@@ -20,12 +21,12 @@ public ExperimentDiff(
20
21
var oldComponentDictionary = controlGroupComponents . ToDictionary ( x => x . Id ) ;
21
22
var newComponentDictionary = experimentGroupComponents . ToDictionary ( x => x . Id ) ;
22
23
23
- this . AddedIds = newComponentDictionary . Keys . Except ( oldComponentDictionary . Keys ) . ToList ( ) ;
24
- this . RemovedIds = oldComponentDictionary . Keys . Except ( newComponentDictionary . Keys ) . ToList ( ) ;
24
+ this . AddedIds = newComponentDictionary . Keys . Except ( oldComponentDictionary . Keys ) . ToImmutableList ( ) ;
25
+ this . RemovedIds = oldComponentDictionary . Keys . Except ( newComponentDictionary . Keys ) . ToImmutableList ( ) ;
25
26
26
- this . DevelopmentDependencyChanges = new List < DevelopmentDependencyChange > ( ) ;
27
- this . AddedRootIds = new Dictionary < string , HashSet < string > > ( ) ;
28
- this . RemovedRootIds = new Dictionary < string , HashSet < string > > ( ) ;
27
+ var developmentDependencyChanges = new List < DevelopmentDependencyChange > ( ) ;
28
+ var addedRootIds = new Dictionary < string , IReadOnlySet < string > > ( ) ;
29
+ var removedRootIds = new Dictionary < string , IReadOnlySet < string > > ( ) ;
29
30
30
31
// Need performance benchmark to see if this is worth parallelization
31
32
foreach ( var id in newComponentDictionary . Keys . Intersect ( oldComponentDictionary . Keys ) )
@@ -35,53 +36,57 @@ public ExperimentDiff(
35
36
36
37
if ( oldComponent . DevelopmentDependency != newComponent . DevelopmentDependency )
37
38
{
38
- this . DevelopmentDependencyChanges . Add ( new DevelopmentDependencyChange (
39
+ developmentDependencyChanges . Add ( new DevelopmentDependencyChange (
39
40
id ,
40
41
oldComponent . DevelopmentDependency ,
41
42
newComponent . DevelopmentDependency ) ) ;
42
43
}
43
44
44
- var addedRootIds = newComponent . RootIds . Except ( oldComponent . RootIds ) . ToHashSet ( ) ;
45
- var removedRootIds = oldComponent . RootIds . Except ( newComponent . RootIds ) . ToHashSet ( ) ;
45
+ var newRoots = newComponent . RootIds . Except ( oldComponent . RootIds ) . ToImmutableHashSet ( ) ;
46
+ var removedRoots = oldComponent . RootIds . Except ( newComponent . RootIds ) . ToImmutableHashSet ( ) ;
46
47
47
- if ( addedRootIds . Count > 0 )
48
+ if ( newRoots . Count > 0 )
48
49
{
49
- this . AddedRootIds [ id ] = addedRootIds ;
50
+ addedRootIds [ id ] = newRoots ;
50
51
}
51
52
52
- if ( removedRootIds . Count > 0 )
53
+ if ( removedRoots . Count > 0 )
53
54
{
54
- this . RemovedRootIds [ id ] = removedRootIds ;
55
+ removedRootIds [ id ] = removedRoots ;
55
56
}
56
57
}
58
+
59
+ this . DevelopmentDependencyChanges = developmentDependencyChanges . AsReadOnly ( ) ;
60
+ this . AddedRootIds = addedRootIds . ToImmutableDictionary ( ) ;
61
+ this . RemovedRootIds = removedRootIds . ToImmutableDictionary ( ) ;
57
62
}
58
63
59
64
/// <summary>
60
65
/// Gets a list of component IDs that were present in the experimental group but not the control group.
61
66
/// </summary>
62
- public List < string > AddedIds { get ; }
67
+ public IReadOnlyCollection < string > AddedIds { get ; }
63
68
64
69
/// <summary>
65
70
/// Gets a list of component IDs that were present in the control group but not the experimental group.
66
71
/// </summary>
67
- public List < string > RemovedIds { get ; }
72
+ public IReadOnlyCollection < string > RemovedIds { get ; }
68
73
69
74
/// <summary>
70
75
/// Gets a list of changes to the development dependency status of components.
71
76
/// </summary>
72
- public List < DevelopmentDependencyChange > DevelopmentDependencyChanges { get ; }
77
+ public IReadOnlyCollection < DevelopmentDependencyChange > DevelopmentDependencyChanges { get ; }
73
78
74
79
/// <summary>
75
80
/// Gets a dictionary of component IDs to the set of root IDs that were added to the component. The component ID
76
81
/// is the key.
77
82
/// </summary>
78
- public Dictionary < string , HashSet < string > > AddedRootIds { get ; }
83
+ public IReadOnlyDictionary < string , IReadOnlySet < string > > AddedRootIds { get ; }
79
84
80
85
/// <summary>
81
86
/// Gets a dictionary of component IDs to the set of root IDs that were removed from the component. The component
82
87
/// ID is the key.
83
88
/// </summary>
84
- public Dictionary < string , HashSet < string > > RemovedRootIds { get ; }
89
+ public IReadOnlyDictionary < string , IReadOnlySet < string > > RemovedRootIds { get ; }
85
90
86
91
/// <summary>
87
92
/// Stores information about a change to the development dependency status of a component.
0 commit comments