From 19c28c2a769d489b2db4b4c823d34ff3e62ab782 Mon Sep 17 00:00:00 2001 From: Jade Date: Fri, 12 Jul 2024 21:51:21 +0800 Subject: [PATCH] [commands] Make requirements private (#6769) --- .../src/main/java/edu/wpi/first/wpilibj2/command/Command.java | 2 +- .../edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java | 2 +- .../edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java | 2 +- .../java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java | 2 +- .../src/main/native/include/frc2/command/Command.h | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index 1364c1f3bd1..e64044cab35 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -30,7 +30,7 @@ */ public abstract class Command implements Sendable { /** Requirements set. */ - protected Set m_requirements = new HashSet<>(); + private final Set m_requirements = new HashSet<>(); /** Default constructor. */ @SuppressWarnings("this-escape") diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java index cb5dcf0c0e2..14d93b6961c 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java @@ -50,7 +50,7 @@ public final void addCommands(Command... commands) { CommandScheduler.getInstance().registerComposedCommands(commands); for (Command command : commands) { - if (!Collections.disjoint(command.getRequirements(), m_requirements)) { + if (!Collections.disjoint(command.getRequirements(), getRequirements())) { throw new IllegalArgumentException( "Multiple commands in a parallel composition cannot require the same subsystems"); } diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java index fae0542322a..86417f27b9c 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java @@ -80,7 +80,7 @@ public final void addCommands(Command... commands) { CommandScheduler.getInstance().registerComposedCommands(commands); for (Command command : commands) { - if (!Collections.disjoint(command.getRequirements(), m_requirements)) { + if (!Collections.disjoint(command.getRequirements(), getRequirements())) { throw new IllegalArgumentException( "Multiple commands in a parallel group cannot require the same subsystems"); } diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java index 538ab11d5d2..bd2b214d106 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java @@ -51,7 +51,7 @@ public final void addCommands(Command... commands) { CommandScheduler.getInstance().registerComposedCommands(commands); for (Command command : commands) { - if (!Collections.disjoint(command.getRequirements(), m_requirements)) { + if (!Collections.disjoint(command.getRequirements(), getRequirements())) { throw new IllegalArgumentException( "Multiple commands in a parallel composition cannot require the same subsystems"); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h index 4b508cfb194..c4af1afe81b 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h @@ -484,6 +484,7 @@ class Command : public wpi::Sendable, public wpi::SendableHelper { protected: Command(); + private: /// Requirements set. wpi::SmallSet m_requirements;