001    /*----------------------------------------------------------------------------*/
002    /* Copyright (c) FIRST 2008-2012. All Rights Reserved.                        */
003    /* Open Source Software - may be modified and shared by FRC teams. The code   */
004    /* must be accompanied by the FIRST BSD license file in the root directory of */
005    /* the project.                                                               */
006    /*----------------------------------------------------------------------------*/
007    
008    package edu.wpi.first.wpilibj.util;
009    
010    /**
011     * This exception represents an error in which a lower limit was set as higher
012     * than an upper limit.
013     * @author dtjones
014     */
015    public class BoundaryException extends RuntimeException{
016    
017        /**
018         * Create a new exception with the given message
019         * @param message the message to attach to the exception
020         */
021        public BoundaryException(String message) {
022            super(message);
023        }
024    
025        /**
026         * Make sure that the given value is between the upper and lower bounds, and
027         * throw an exception if they are not.
028         * @param value The value to check.
029         * @param lower The minimum acceptable value.
030         * @param upper The maximum acceptable value.
031         */
032        public static void assertWithinBounds(double value, double lower, double upper) {
033            if (value < lower || value > upper)
034                throw new BoundaryException("Value must be between " + lower +
035                        " and " + upper + ", " + value + " given");
036        }
037    }