/*******************************************************************************
 * Copyright 2012 André Rouél
 * Copyright 2012 Dominik Seichter
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.github.quality.check.exception;

/**
 * Thrown to indicate that a method has been passed with a range as arguments.
 * 
 * A range (<em>start</em>, <em>end</em>, <em>size</em>) is valid if the following conditions are true:
 * - start < size
 * - end < size
 * - start < end
 * 
 * @author André Rouél
 * @author Dominik Seichter
 */
public class IllegalRangeException extends RuntimeException {

	private static final long serialVersionUID = 4515679658955102518L;

	/**
	 * Default message to indicate that the a given arguments are no valid range.
	 */
	protected static final String DEFAULT_MESSAGE = "Arguments must be a valid range.";

	/**
	 * Message to indicate that the the given arguments <em>start</em>, <em>end</em> and <em>size</em> must be a valid range.
	 */
	protected static final String MESSAGE_WITH_VALUES = "Arguments start='%i', end='%i' and size='%i' must be a valid range.";

	private static String format(final int start, final int end, final int size) {
		return String.format(MESSAGE_WITH_VALUES, start, end, size);
	}

	/**
	 * Constructs an {@code IllegalRangeException} with the default message
	 * {@link IllegalRangeException#DEFAULT_MESSAGE}.
	 */
	public IllegalRangeException() {
		super(DEFAULT_MESSAGE);
	}

	/**
	 * Constructs an {@code IllegalRangeException} with the message
	 * {@link IllegalRangeException#MESSAGE_WITH_VALUES} including the given values of the arguments.
	 * 
	 * @param start
	 *            the start value of the invalid range
	 * @param end
	 *            the end value of the invalid range
	 * @param size
	 *            the size value of the invalid range
	 */
	public IllegalRangeException(final int start, final int end, final int size) {
		super(format(start, end, size));
	}

	/**
	 * Constructs a new exception with the message {@link IllegalRangeException#MESSAGE_WITH_VALUES} including the
	 * given values of the arguments.
	 * 
	 * @param start
	 *            the start value of the invalid range
	 * @param end
	 *            the end value of the invalid range
	 * @param size
	 *            the size value of the invalid range
	 * @param cause
	 *            the cause (which is saved for later retrieval by the {@link Throwable#getCause()} method). (A
	 *            {@code null} value is permitted, and indicates that the cause is nonexistent or unknown.)
	 */
	public IllegalRangeException(final int start, final int end, final int size, final Throwable cause) {
		super(format(start, end, size), cause);
	}

	/**
	 * Constructs a new exception with the default message {@link IllegalRangeException#DEFAULT_MESSAGE}.
	 * 
	 * @param cause
	 *            the cause (which is saved for later retrieval by the {@link Throwable#getCause()} method). (A
	 *            {@code null} value is permitted, and indicates that the cause is nonexistent or unknown.)
	 */
	public IllegalRangeException(final Throwable cause) {
		super(DEFAULT_MESSAGE, cause);
	}

}

@@ -1014,19 +1014,16 @@
 re true:
-%0A *
  - start
@@ -1029,21 +1029,21 @@
 t %3C size
+ -
 %0A *
- -
  end %3C s
@@ -1045,19 +1045,16 @@
 d %3C size
-%0A *
  - start
@@ -1542,24 +1542,28 @@
 t be a valid
+%0A%09 *
  range.%0A%09 */
@@ -1635,17 +1635,17 @@
 start='%25
-i
+d
 ', end='
@@ -1645,17 +1645,17 @@
 , end='%25
-i
+d
 ' and si
@@ -1659,17 +1659,17 @@
  size='%25
-i
+d
 ' must b
@@ -2094,36 +2094,32 @@
 with the message
-%0A%09 *
  %7B@link IllegalR
@@ -2144,32 +2144,36 @@
 AGE_WITH_VALUES%7D
+%0A%09 *
  including the g
@@ -2652,18 +2652,18 @@
  the
-%0A%09 *
  given
+%0A%09 *
  val

Format specifier for numbers is %d instead of %i. Fixed.