2121using System . Collections . Generic ;
2222using System . Text ;
2323
24+ #nullable enable
25+
2426namespace OpenQA . Selenium . Interactions
2527{
2628 /// <summary>
@@ -29,7 +31,7 @@ namespace OpenQA.Selenium.Interactions
2931 /// </summary>
3032 public class ActionBuilder
3133 {
32- private Dictionary < InputDevice , ActionSequence > sequences = new Dictionary < InputDevice , ActionSequence > ( ) ;
34+ private readonly Dictionary < InputDevice , ActionSequence > sequences = new Dictionary < InputDevice , ActionSequence > ( ) ;
3335
3436 /// <summary>
3537 /// Adds an action to the built set of actions. Adding an action will
@@ -71,7 +73,7 @@ public IList<ActionSequence> ToActionSequenceList()
7173 /// </summary>
7274 public void ClearSequences ( )
7375 {
74- this . sequences = new Dictionary < InputDevice , ActionSequence > ( ) ;
76+ this . sequences . Clear ( ) ;
7577 }
7678
7779 /// <summary>
@@ -94,8 +96,7 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
9496 List < InputDevice > usedDevices = new List < InputDevice > ( ) ;
9597 foreach ( Interaction interaction in interactionsToAdd )
9698 {
97- InputDevice actionDevice = interaction . SourceDevice ;
98- if ( usedDevices . Contains ( actionDevice ) )
99+ if ( usedDevices . Contains ( interaction . SourceDevice ) )
99100 {
100101 throw new ArgumentException ( "You can only add one action per device for a single tick." ) ;
101102 }
@@ -104,8 +105,9 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
104105 List < InputDevice > unusedDevices = new List < InputDevice > ( this . sequences . Keys ) ;
105106 foreach ( Interaction interaction in interactionsToAdd )
106107 {
107- ActionSequence sequence = this . FindSequence ( interaction . SourceDevice ) ;
108+ ActionSequence sequence = this . GetOrAddSequence ( interaction . SourceDevice ) ;
108109 sequence . AddAction ( interaction ) ;
110+
109111 unusedDevices . Remove ( interaction . SourceDevice ) ;
110112 }
111113
@@ -116,11 +118,11 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
116118 }
117119 }
118120
119- private ActionSequence FindSequence ( InputDevice device )
121+ private ActionSequence GetOrAddSequence ( InputDevice device )
120122 {
121- if ( this . sequences . ContainsKey ( device ) )
123+ if ( this . sequences . TryGetValue ( device , out ActionSequence ? existingSequence ) )
122124 {
123- return this . sequences [ device ] ;
125+ return existingSequence ;
124126 }
125127
126128 int longestSequenceLength = 0 ;
0 commit comments