11namespace Microsoft . ComponentDetection . Orchestrator . Experiments . Models ;
22
33using System . Collections . Generic ;
4+ using System . Collections . Immutable ;
45using System . Linq ;
56
67/// <summary>
@@ -20,12 +21,12 @@ public ExperimentDiff(
2021 var oldComponentDictionary = controlGroupComponents . ToDictionary ( x => x . Id ) ;
2122 var newComponentDictionary = experimentGroupComponents . ToDictionary ( x => x . Id ) ;
2223
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 ( ) ;
2526
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 > > ( ) ;
2930
3031 // Need performance benchmark to see if this is worth parallelization
3132 foreach ( var id in newComponentDictionary . Keys . Intersect ( oldComponentDictionary . Keys ) )
@@ -35,53 +36,57 @@ public ExperimentDiff(
3536
3637 if ( oldComponent . DevelopmentDependency != newComponent . DevelopmentDependency )
3738 {
38- this . DevelopmentDependencyChanges . Add ( new DevelopmentDependencyChange (
39+ developmentDependencyChanges . Add ( new DevelopmentDependencyChange (
3940 id ,
4041 oldComponent . DevelopmentDependency ,
4142 newComponent . DevelopmentDependency ) ) ;
4243 }
4344
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 ( ) ;
4647
47- if ( addedRootIds . Count > 0 )
48+ if ( newRoots . Count > 0 )
4849 {
49- this . AddedRootIds [ id ] = addedRootIds ;
50+ addedRootIds [ id ] = newRoots ;
5051 }
5152
52- if ( removedRootIds . Count > 0 )
53+ if ( removedRoots . Count > 0 )
5354 {
54- this . RemovedRootIds [ id ] = removedRootIds ;
55+ removedRootIds [ id ] = removedRoots ;
5556 }
5657 }
58+
59+ this . DevelopmentDependencyChanges = developmentDependencyChanges . AsReadOnly ( ) ;
60+ this . AddedRootIds = addedRootIds . ToImmutableDictionary ( ) ;
61+ this . RemovedRootIds = removedRootIds . ToImmutableDictionary ( ) ;
5762 }
5863
5964 /// <summary>
6065 /// Gets a list of component IDs that were present in the experimental group but not the control group.
6166 /// </summary>
62- public List < string > AddedIds { get ; }
67+ public IReadOnlyCollection < string > AddedIds { get ; }
6368
6469 /// <summary>
6570 /// Gets a list of component IDs that were present in the control group but not the experimental group.
6671 /// </summary>
67- public List < string > RemovedIds { get ; }
72+ public IReadOnlyCollection < string > RemovedIds { get ; }
6873
6974 /// <summary>
7075 /// Gets a list of changes to the development dependency status of components.
7176 /// </summary>
72- public List < DevelopmentDependencyChange > DevelopmentDependencyChanges { get ; }
77+ public IReadOnlyCollection < DevelopmentDependencyChange > DevelopmentDependencyChanges { get ; }
7378
7479 /// <summary>
7580 /// Gets a dictionary of component IDs to the set of root IDs that were added to the component. The component ID
7681 /// is the key.
7782 /// </summary>
78- public Dictionary < string , HashSet < string > > AddedRootIds { get ; }
83+ public IReadOnlyDictionary < string , IReadOnlySet < string > > AddedRootIds { get ; }
7984
8085 /// <summary>
8186 /// Gets a dictionary of component IDs to the set of root IDs that were removed from the component. The component
8287 /// ID is the key.
8388 /// </summary>
84- public Dictionary < string , HashSet < string > > RemovedRootIds { get ; }
89+ public IReadOnlyDictionary < string , IReadOnlySet < string > > RemovedRootIds { get ; }
8590
8691 /// <summary>
8792 /// Stores information about a change to the development dependency status of a component.
0 commit comments