- Timestamp:
- 2013-11-20T21:18:53+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/SequenceCommand.java
r6380 r6396 17 17 * and undo them in reverse order. 18 18 * @author imi 19 * @since 31 19 20 */ 20 21 public class SequenceCommand extends Command { 21 22 22 /** 23 * The command sequenz to be executed. 24 */ 23 /** The command sequence to be executed. */ 25 24 private Command[] sequence; 26 private boolean sequence _complete;25 private boolean sequenceComplete; 27 26 private final String name; 27 /** Determines if the sequence execution should continue after one of its commands fails. */ 28 28 public boolean continueOnError = false; 29 29 30 30 /** 31 31 * Create the command by specifying the list of commands to execute. 32 * @param name The description text 32 33 * @param sequenz The sequence that should be executed. 33 34 */ … … 35 36 super(); 36 37 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()]); 39 39 } 40 40 41 41 /** 42 42 * 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. 43 45 */ 44 46 public SequenceCommand(String name, Command... sequenz) { … … 48 50 @Override public boolean executeCommand() { 49 51 for (int i=0; i < sequence.length; i++) { 50 Command c = sequence[i]; 51 boolean result = c.executeCommand(); 52 boolean result = sequence[i].executeCommand(); 52 53 if (!result && !continueOnError) { 53 54 this.undoCommands(i-1); … … 55 56 } 56 57 } 57 sequence _complete = true;58 sequenceComplete = true; 58 59 return true; 59 60 } 60 61 62 /** 63 * Returns the last command. 64 * @return The last command, or {@code null} if the sequence is empty. 65 */ 61 66 public Command getLastCommand() { 62 if (sequence.length == 0)67 if (sequence.length == 0) 63 68 return null; 64 69 return sequence[sequence.length-1]; 65 70 } 71 66 72 private void undoCommands(int start) { 67 73 // We probably aborted this halfway though the 68 74 // execution sequence because of a sub-command 69 75 // error. We already undid the sub-commands. 70 if (!sequence _complete)76 if (!sequenceComplete) 71 77 return; 72 78 for (int i = start; i >= 0; --i) { … … 108 114 return prims; 109 115 } 116 117 protected final void setSequence(Command[] sequence) { 118 this.sequence = sequence; 119 } 110 120 }
Note:
See TracChangeset
for help on using the changeset viewer.