001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.wpilibj2.command;
006
007import java.util.Set;
008
009/**
010 * Schedules the given commands when this command is initialized. Useful for forking off from
011 * CommandGroups. Note that if run from a CommandGroup, the group will not know about the status of
012 * the scheduled commands, and will treat this command as finishing instantly.
013 */
014public class ScheduleCommand extends CommandBase {
015  private final Set<Command> m_toSchedule;
016
017  /**
018   * Creates a new ScheduleCommand that schedules the given commands when initialized.
019   *
020   * @param toSchedule the commands to schedule
021   */
022  public ScheduleCommand(Command... toSchedule) {
023    m_toSchedule = Set.of(toSchedule);
024  }
025
026  @Override
027  public void initialize() {
028    for (Command command : m_toSchedule) {
029      command.schedule();
030    }
031  }
032
033  @Override
034  public boolean isFinished() {
035    return true;
036  }
037
038  @Override
039  public boolean runsWhenDisabled() {
040    return true;
041  }
042}