
net.java.trueupdate.manager.spec.cmd.CompositeCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trueupdate-manager-spec Show documentation
Show all versions of trueupdate-manager-spec Show documentation
Specifies an API for update managers.
The newest version!
/*
* Copyright (C) 2013 Schlichtherle IT Services & Stimulus Software.
* All rights reserved. Use is subject to license terms.
*/
package net.java.trueupdate.manager.spec.cmd;
/**
* A composite command.
*
* @author Christian Schlichtherle
*/
public final class CompositeCommand implements Command {
private final Command[] commands;
private int index;
public CompositeCommand(final Command... commands) {
if (0 >= commands.length) throw new IllegalArgumentException();
this.commands = commands.clone();
}
@Override public void perform() throws Exception {
if (0 != index) throw new IllegalStateException("Not idempotent.");
while (index < commands.length) commands[index++].perform();
}
@Override public void revert() throws Exception {
while (0 < index) {
final int i = index - 1;
commands[i].revert();
index = i;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy