    001// License: GPL. For details, see LICENSE file.
    002package org.openstreetmap.josm.plugins.streetside.history.commands;
    003
    004import static org.openstreetmap.josm.tools.I18n.tr;
    005
    006import java.util.Arrays;
    007import java.util.concurrent.ConcurrentSkipListSet;
    008
    009import org.openstreetmap.josm.plugins.streetside.StreetsideAbstractImage;
    010import org.openstreetmap.josm.plugins.streetside.utils.StreetsideUtils;
    011
    012/**
    013 * Command joined when joining two images into the same sequence.
    014 *
    015 * @author nokutu
    016 *
    017 */
    018public class CommandJoin extends StreetsideExecutableCommand {
    019
    020  private final StreetsideAbstractImage a;
    021  private final StreetsideAbstractImage b;
    022
    023  /**
    024   * Main constructor.
    025   *
    026   * @param a the first image, that is joined with the second one
    027   * @param b the second image, that is joined with the first one
    028   * @throws IllegalArgumentException if the images are already in the same sequence
    029   * @throws NullPointerException if {@code a} or {@code b} is null
    030   */
    031  public CommandJoin(final StreetsideAbstractImage a, final StreetsideAbstractImage b) {
    032    super(new ConcurrentSkipListSet<>(Arrays.asList(a, b))); // throws NPE if a or b is null
    033    if (a.getSequence() == b.getSequence()) {
    034      throw new IllegalArgumentException("Both images must be in different sequences for joining.");
    035    }
    036    this.a = a;
    037    this.b = b;
    038  }
    039
    040  @Override
    041  public void execute() {
    042    redo();
    043  }
    044
    045  @Override
    046  public void undo() {
    047    StreetsideUtils.unjoin(a, b);
    048  }
    049
    050  @Override
    051  public void redo() {
    052    StreetsideUtils.join(a, b);
    053  }
    054
    055  @Override
    056  public void sum(StreetsideCommand command) {
    057  }
    058
    059  @Override
    060  public String toString() {
    061    return tr("2 images joined");
    062  }
    063}