private void checkBoundsAfterParticipantP1DeletionOfTestCreateMessageDeletion2() {
    Bounds newDiagramElementP2Bounds = getBounds(diagramElementP2, participantP2);
    Bounds newDiagramElementP3Bounds = getBounds(diagramElementP3, participantP3);
    Bounds newDiagramElementP4Bounds = getBounds(diagramElementP4, participantP4);

    Range newCreateP4Range =
        new SequenceMessageViewQuery(getGmfEdge(createP4Edge)).getVerticalRange();
    Range newCreateP3Range =
        new SequenceMessageViewQuery(getGmfEdge(createP3Edge)).getVerticalRange();

    assertEquals(
        diagramElementP1Bounds.getX()
            + diagramElementP1Bounds.getWidth()
            + LayoutConstants.LIFELINES_MIN_X_GAP,
        newDiagramElementP2Bounds.getX());
    assertEquals(origin.y, newDiagramElementP2Bounds.getY());

    assertEquals(
        diagramElementP2Bounds.getX()
            + diagramElementP2Bounds.getWidth()
            + LayoutConstants.LIFELINES_MIN_X_GAP,
        newDiagramElementP3Bounds.getX());
    int yP3 = newCreateP3Range.getLowerBound() - newDiagramElementP3Bounds.getHeight() / 2;
    assertEquals(yP3, newDiagramElementP3Bounds.getY());

    assertEquals(
        diagramElementP3Bounds.getX()
            + diagramElementP3Bounds.getWidth()
            + LayoutConstants.LIFELINES_MIN_X_GAP,
        newDiagramElementP4Bounds.getX());
    int yP4 = newCreateP4Range.getLowerBound() - newDiagramElementP4Bounds.getHeight() / 2;
    assertEquals(yP4, newDiagramElementP4Bounds.getY());
  }
  private void checkInitialBounds() {
    assertEquals(origin.x, diagramElementP1Bounds.getX());
    assertEquals(origin.y, diagramElementP1Bounds.getY());

    assertEquals(
        diagramElementP1Bounds.getX()
            + diagramElementP1Bounds.getWidth()
            + LayoutConstants.LIFELINES_MIN_X_GAP,
        diagramElementP2Bounds.getX());
    int yP2 = createP2EdgeRange.getLowerBound() - diagramElementP2Bounds.getHeight() / 2;
    assertEquals(yP2, diagramElementP2Bounds.getY());

    assertEquals(
        diagramElementP2Bounds.getX()
            + diagramElementP2Bounds.getWidth()
            + LayoutConstants.LIFELINES_MIN_X_GAP,
        diagramElementP3Bounds.getX());
    int yP3 = createP3EdgeRange.getLowerBound() - diagramElementP3Bounds.getHeight() / 2;
    assertEquals(yP3, diagramElementP3Bounds.getY());

    assertEquals(
        diagramElementP3Bounds.getX()
            + diagramElementP3Bounds.getWidth()
            + LayoutConstants.LIFELINES_MIN_X_GAP,
        diagramElementP4Bounds.getX());
    int yP4 = createP4EdgeRange.getLowerBound() - diagramElementP4Bounds.getHeight() / 2;
    assertEquals(yP4, diagramElementP4Bounds.getY());

    // TODO : checks messages bounds.
  }
/**
 * Abstract validator providing common services for user interactions.
 *
 * @author mporhel
 */
public abstract class AbstractSequenceInteractionValidator {

  /** Keep the value of the validation. */
  protected boolean valid = true;

  /** {@link RequestQuery} for the current Request. */
  protected final RequestQuery request;

  /** The expansionZine. */
  protected Range expansionZone = Range.emptyRange();

  /** {@link ISequenceEvent} in errors. */
  protected final Set<ISequenceEvent> eventInError = new HashSet<ISequenceEvent>();

  /** invalid positions. */
  protected final Set<Integer> invalidPositions = new HashSet<Integer>();

  /** invalid ranges. */
  protected final Set<Range> invalidRanges = new HashSet<Range>();

  /** {@link ISequenceEvent}s moved. */
  protected final Collection<ISequenceEvent> movedElements = new ArrayList<ISequenceEvent>();

  /** {@link ISequenceEvent}s moved. */
  protected final Collection<Range> createdElements = new ArrayList<Range>();

  /** startReflexiveMessageToResize. */
  protected final Collection<Message> startReflexiveMessageToResize = new HashSet<Message>();

  /** endReflexiveMessageToResize. */
  protected final Collection<Message> endReflexiveMessageToResize = new HashSet<Message>();

  private boolean initialized;

  /**
   * Constructor.
   *
   * @param request a request query
   */
  public AbstractSequenceInteractionValidator(RequestQuery request) {
    this.request = request;
  }

  /**
   * Get the {@link SequenceDiagram}.
   *
   * @return the {@link SequenceDiagram}
   */
  public abstract SequenceDiagram getDiagram();

  /**
   * Get the {@link Function} which give the {@link Range} of a {@link ISequenceEvent}.
   *
   * @return the {@link Range} of a {@link ISequenceEvent}
   */
  public abstract Function<ISequenceEvent, Range> getRangeFunction();

  /** Do the validation of the request. */
  protected abstract void doValidation();

  /**
   * Return the validation status. Validate the request result in the first call only.
   *
   * @return the validation status.
   */
  public final boolean isValid() {
    validate();
    return valid;
  }

  /**
   * Performs all the computations required to validate the resizing, and stores any important
   * information which will be useful to actually execute the move if it is valid, like for example
   * avoid contact with siblings or handle reconnection.
   */
  public final void validate() {
    if (!initialized) {
      doValidation();
      initialized = true;
    }
  }

  public Collection<ISequenceEvent> getMovedElements() {
    return movedElements;
  }

  public Collection<Range> getCreatedElements() {
    return createdElements;
  }

  public Collection<Message> getResizedStartMessages() {
    return startReflexiveMessageToResize;
  }

  public Collection<Message> getResizedEndMessages() {
    return endReflexiveMessageToResize;
  }

  public Range getExpansionZone() {
    return expansionZone;
  }

  public Collection<ISequenceEvent> getEventsInError() {
    return eventInError;
  }

  public Collection<Integer> getInvalidPostions() {
    return invalidPositions;
  }

  public Collection<Range> getInvalidRanges() {
    return invalidRanges;
  }
}