001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.util; 020 021import lucee.runtime.exp.ExpressionException; 022 023/** 024 * checks for a Number range 025 */ 026public final class NumberRange { 027 028 /** 029 * checks if number between from and to (inlude from and to) 030 * @param number 031 * @param from 032 * @param to 033 * @return given number when range ok 034 * @throws ExpressionException 035 */ 036 public static double range(double number, double from, double to) throws ExpressionException { 037 if(number>=from && number<=to) return number; 038 throw new ExpressionException("number must between ["+from+" - "+to+"] now "+number+""); 039 } 040 /** 041 * checks if number is greater than from (inlude from) 042 * @param number 043 * @param from 044 * @return given number when range ok 045 * @throws ExpressionException 046 */ 047 public static double range(double number, double from) throws ExpressionException { 048 if(number>=from) return number; 049 throw new ExpressionException("number must be greater than ["+from+"] now "+number+""); 050 } 051 052 public static int range(int number, int from) throws ExpressionException { 053 if(number>=from) return number; 054 throw new ExpressionException("number must be greater than ["+from+"] now "+number+""); 055 } 056 057}