21
21
using System . Collections . Generic ;
22
22
using System . Text ;
23
23
24
+ #nullable enable
25
+
24
26
namespace OpenQA . Selenium . Interactions
25
27
{
26
28
/// <summary>
@@ -29,7 +31,7 @@ namespace OpenQA.Selenium.Interactions
29
31
/// </summary>
30
32
public class ActionBuilder
31
33
{
32
- private Dictionary < InputDevice , ActionSequence > sequences = new Dictionary < InputDevice , ActionSequence > ( ) ;
34
+ private readonly Dictionary < InputDevice , ActionSequence > sequences = new Dictionary < InputDevice , ActionSequence > ( ) ;
33
35
34
36
/// <summary>
35
37
/// Adds an action to the built set of actions. Adding an action will
@@ -71,7 +73,7 @@ public IList<ActionSequence> ToActionSequenceList()
71
73
/// </summary>
72
74
public void ClearSequences ( )
73
75
{
74
- this . sequences = new Dictionary < InputDevice , ActionSequence > ( ) ;
76
+ this . sequences . Clear ( ) ;
75
77
}
76
78
77
79
/// <summary>
@@ -94,8 +96,7 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
94
96
List < InputDevice > usedDevices = new List < InputDevice > ( ) ;
95
97
foreach ( Interaction interaction in interactionsToAdd )
96
98
{
97
- InputDevice actionDevice = interaction . SourceDevice ;
98
- if ( usedDevices . Contains ( actionDevice ) )
99
+ if ( usedDevices . Contains ( interaction . SourceDevice ) )
99
100
{
100
101
throw new ArgumentException ( "You can only add one action per device for a single tick." ) ;
101
102
}
@@ -104,8 +105,9 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
104
105
List < InputDevice > unusedDevices = new List < InputDevice > ( this . sequences . Keys ) ;
105
106
foreach ( Interaction interaction in interactionsToAdd )
106
107
{
107
- ActionSequence sequence = this . FindSequence ( interaction . SourceDevice ) ;
108
+ ActionSequence sequence = this . GetOrAddSequence ( interaction . SourceDevice ) ;
108
109
sequence . AddAction ( interaction ) ;
110
+
109
111
unusedDevices . Remove ( interaction . SourceDevice ) ;
110
112
}
111
113
@@ -116,11 +118,11 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
116
118
}
117
119
}
118
120
119
- private ActionSequence FindSequence ( InputDevice device )
121
+ private ActionSequence GetOrAddSequence ( InputDevice device )
120
122
{
121
- if ( this . sequences . ContainsKey ( device ) )
123
+ if ( this . sequences . TryGetValue ( device , out ActionSequence ? existingSequence ) )
122
124
{
123
- return this . sequences [ device ] ;
125
+ return existingSequence ;
124
126
}
125
127
126
128
int longestSequenceLength = 0 ;
0 commit comments