Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions dotnet/src/webdriver/Interactions/ActionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using System.Collections.Generic;
using System.Text;

#nullable enable

namespace OpenQA.Selenium.Interactions
{
/// <summary>
Expand All @@ -29,7 +31,7 @@ namespace OpenQA.Selenium.Interactions
/// </summary>
public class ActionBuilder
{
private Dictionary<InputDevice, ActionSequence> sequences = new Dictionary<InputDevice, ActionSequence>();
private readonly Dictionary<InputDevice, ActionSequence> sequences = new Dictionary<InputDevice, ActionSequence>();

/// <summary>
/// Adds an action to the built set of actions. Adding an action will
Expand Down Expand Up @@ -71,7 +73,7 @@ public IList<ActionSequence> ToActionSequenceList()
/// </summary>
public void ClearSequences()
{
this.sequences = new Dictionary<InputDevice, ActionSequence>();
this.sequences.Clear();
}

/// <summary>
Expand All @@ -94,8 +96,7 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
List<InputDevice> usedDevices = new List<InputDevice>();
foreach (Interaction interaction in interactionsToAdd)
{
InputDevice actionDevice = interaction.SourceDevice;
if (usedDevices.Contains(actionDevice))
if (usedDevices.Contains(interaction.SourceDevice))
{
throw new ArgumentException("You can only add one action per device for a single tick.");
}
Expand All @@ -104,8 +105,9 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
List<InputDevice> unusedDevices = new List<InputDevice>(this.sequences.Keys);
foreach (Interaction interaction in interactionsToAdd)
{
ActionSequence sequence = this.FindSequence(interaction.SourceDevice);
ActionSequence sequence = this.GetOrAddSequence(interaction.SourceDevice);
sequence.AddAction(interaction);

unusedDevices.Remove(interaction.SourceDevice);
}

Expand All @@ -116,11 +118,11 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
}
}

private ActionSequence FindSequence(InputDevice device)
private ActionSequence GetOrAddSequence(InputDevice device)
{
if (this.sequences.ContainsKey(device))
if (this.sequences.TryGetValue(device, out ActionSequence? existingSequence))
{
return this.sequences[device];
return existingSequence;
}

int longestSequenceLength = 0;
Expand Down
Loading