11package org .carlmontrobotics .lib199 .sim ;
22
3- import java .util .ArrayList ;
4- import java .util .HashMap ;
3+ import java .util .concurrent .ConcurrentHashMap ;
4+ import java .util .concurrent .CopyOnWriteArrayList ;
5+
6+ import org .carlmontrobotics .lib199 .DummySparkMaxAnswer ;
7+ import org .carlmontrobotics .lib199 .Mocks ;
8+ import org .carlmontrobotics .lib199 .REVLibErrorAnswer ;
59
6- import com .revrobotics .REVLibError ;
7- import com .revrobotics .RelativeEncoder ;
8- import com .revrobotics .SparkMaxPIDController ;
910import com .revrobotics .CANSparkMax ;
1011import com .revrobotics .CANSparkMax .ExternalFollower ;
1112import com .revrobotics .CANSparkMax .IdleMode ;
1213import com .revrobotics .CANSparkMaxLowLevel .MotorType ;
13-
14- import org .carlmontrobotics .lib199 .DummySparkMaxAnswer ;
15- import org .carlmontrobotics .lib199 .Mocks ;
16- import org .carlmontrobotics .lib199 .REVLibErrorAnswer ;
14+ import com .revrobotics .REVLibError ;
15+ import com .revrobotics .RelativeEncoder ;
16+ import com .revrobotics .SparkMaxPIDController ;
1717
1818import edu .wpi .first .hal .SimDevice ;
19- import edu .wpi .first .hal .SimDouble ;
2019import edu .wpi .first .hal .SimDevice .Direction ;
20+ import edu .wpi .first .hal .SimDouble ;
2121
2222public class MockSparkMax {
2323 // Assign the CAN port to a PWM port so it works with the simulator. Not a fan
@@ -30,7 +30,7 @@ public class MockSparkMax {
3030 private SparkMaxPIDController pidController ;
3131 private boolean isInverted ;
3232 // Since we need to keep a record of all the motor's followers
33- private static HashMap <Integer , ArrayList <SimDouble >> followMap = new HashMap <>();
33+ private static ConcurrentHashMap <Integer , CopyOnWriteArrayList <SimDouble >> followMap = new ConcurrentHashMap <>();
3434
3535 public MockSparkMax (int port , MotorType type ) {
3636 this .port = port ;
@@ -67,7 +67,7 @@ public REVLibError follow(ExternalFollower leader, int deviceID) {
6767
6868 public REVLibError follow (ExternalFollower leader , int deviceID , boolean invert ) {
6969 if (!followMap .containsKey (deviceID )) {
70- followMap .put (deviceID , new ArrayList <SimDouble >());
70+ followMap .put (deviceID , new CopyOnWriteArrayList <SimDouble >());
7171 }
7272 followMap .get (deviceID ).add (speed );
7373 return REVLibError .kOk ;
0 commit comments