Changeset 6396 in josm


Ignore:
Timestamp:
2013-11-20T21:18:53+01:00 (10 years ago)
Author:
Don-vip
Message:

allow subclasses of SequenceCommand to change sequence of commands

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/SequenceCommand.java

    r6380 r6396  
    1717 * and undo them in reverse order.
    1818 * @author imi
     19 * @since 31
    1920 */
    2021public class SequenceCommand extends Command {
    2122
    22     /**
    23      * The command sequenz to be executed.
    24      */
     23    /** The command sequence to be executed. */
    2524    private Command[] sequence;
    26     private boolean sequence_complete;
     25    private boolean sequenceComplete;
    2726    private final String name;
     27    /** Determines if the sequence execution should continue after one of its commands fails. */
    2828    public boolean continueOnError = false;
    2929
    3030    /**
    3131     * Create the command by specifying the list of commands to execute.
     32     * @param name The description text
    3233     * @param sequenz The sequence that should be executed.
    3334     */
     
    3536        super();
    3637        this.name = name;
    37         this.sequence = new Command[sequenz.size()];
    38         this.sequence = sequenz.toArray(this.sequence);
     38        this.sequence = sequenz.toArray(new Command[sequenz.size()]);
    3939    }
    4040
    4141    /**
    4242     * Convenient constructor, if the commands are known at compile time.
     43     * @param name The description text
     44     * @param sequenz The sequence that should be executed.
    4345     */
    4446    public SequenceCommand(String name, Command... sequenz) {
     
    4850    @Override public boolean executeCommand() {
    4951        for (int i=0; i < sequence.length; i++) {
    50             Command c = sequence[i];
    51             boolean result = c.executeCommand();
     52            boolean result = sequence[i].executeCommand();
    5253            if (!result && !continueOnError) {
    5354                this.undoCommands(i-1);
     
    5556            }
    5657        }
    57         sequence_complete = true;
     58        sequenceComplete = true;
    5859        return true;
    5960    }
    6061
     62    /**
     63     * Returns the last command.
     64     * @return The last command, or {@code null} if the sequence is empty.
     65     */
    6166    public Command getLastCommand() {
    62         if(sequence.length == 0)
     67        if (sequence.length == 0)
    6368            return null;
    6469        return sequence[sequence.length-1];
    6570    }
     71   
    6672    private void undoCommands(int start) {
    6773        // We probably aborted this halfway though the
    6874        // execution sequence because of a sub-command
    6975        // error.  We already undid the sub-commands.
    70         if (!sequence_complete)
     76        if (!sequenceComplete)
    7177            return;
    7278        for (int i = start; i >= 0; --i) {
     
    108114        return prims;
    109115    }
     116   
     117    protected final void setSequence(Command[] sequence) {
     118        this.sequence = sequence;
     119    }
    110120}
Note: See TracChangeset for help on using the changeset viewer.