Ignore:
Timestamp:
2020-06-08T21:02:35+02:00 (5 years ago)
Author:
simon04
Message:

fix #19056 - Add SequenceCommand.wrapIfNeeded (patch by taylor.smock)

Location:
trunk/src/org/openstreetmap/josm/command
Files:
2 edited

Legend:

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

    r16436 r16573  
    463463        }
    464464
    465         return new SequenceCommand(tr("Delete"), cmds);
     465        return SequenceCommand.wrapIfNeeded(tr("Delete"), cmds);
    466466    }
    467467
  • trunk/src/org/openstreetmap/josm/command/SequenceCommand.java

    r14283 r16573  
    7373    public SequenceCommand(String name, Command... sequenz) {
    7474        this(name, Arrays.asList(sequenz));
     75    }
     76
     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 16573
     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 16573
     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);
    75103    }
    76104
Note: See TracChangeset for help on using the changeset viewer.