001package headfirst.command.undo;
002
003public class CeilingFanLowCommand implements Command {
004        CeilingFan ceilingFan;
005        int prevSpeed;
006
007        public CeilingFanLowCommand(CeilingFan ceilingFan) {
008                this.ceilingFan = ceilingFan;
009        }
010
011        public void execute() {
012                prevSpeed = ceilingFan.getSpeed();
013                ceilingFan.low();
014        }
015
016        public void undo() {
017                if (prevSpeed == CeilingFan.HIGH) {
018                        ceilingFan.high();
019                } else if (prevSpeed == CeilingFan.MEDIUM) {
020                        ceilingFan.medium();
021                } else if (prevSpeed == CeilingFan.LOW) {
022                        ceilingFan.low();
023                } else if (prevSpeed == CeilingFan.OFF) {
024                        ceilingFan.off();
025                }
026        }
027}