Ticket #19056: 19056.1.patch

File 19056.1.patch, 2.2 KB (added by taylor.smock, 4 years ago)

createSimplifiedSequenceCommand -> wrapIfNeeded

  • src/org/openstreetmap/josm/command/DeleteCommand.java

     
    462462            cmds.add(new DeleteCommand(primitivesToDelete.iterator().next().getDataSet(), primitivesToDelete));
    463463        }
    464464
    465         return new SequenceCommand(tr("Delete"), cmds);
     465        return SequenceCommand.wrapIfNeeded(tr("Delete"), cmds);
    466466    }
    467467
    468468    /**
  • src/org/openstreetmap/josm/command/SequenceCommand.java

     
    7474        this(name, Arrays.asList(sequenz));
    7575    }
    7676
     77    /**
     78     * Convenient constructor, if the commands are known at compile time.
     79     * @param name The description text to be used for the sequence command, if one is created.
     80     * @param sequenz The sequence that should be executed.
     81     * @return Either a SequenceCommand, or the only command in the potential sequence
     82     * @since xxx
     83     */
     84    public static Command wrapIfNeeded(String name, Command... sequenz) {
     85        if (sequenz.length == 1) {
     86            return sequenz[0];
     87        }
     88        return new SequenceCommand(name, sequenz);
     89    }
     90
     91    /**
     92     * Convenient constructor, if the commands are known at compile time.
     93     * @param name The description text to be used for the sequence command, if one is created.
     94     * @param sequenz The sequence that should be executed.
     95     * @return Either a SequenceCommand, or the only command in the potential sequence
     96     * @since xxx
     97     */
     98    public static Command wrapIfNeeded(String name, Collection<Command> sequenz) {
     99        if (sequenz.size() == 1) {
     100            return sequenz.iterator().next();
     101        }
     102        return new SequenceCommand(name, sequenz);
     103    }
     104
    77105    @Override public boolean executeCommand() {
    78106        for (int i = 0; i < sequence.length; i++) {
    79107            boolean result = sequence[i].executeCommand();