/** * Check to make sure that the boolean test value is true. * * @param test * A true value. * @param message * The exception message thrown if "test" is invalid. */ protected void requireTrue(boolean test, String message) throws WingInvalidArgument { if (!test) { throw new WingInvalidArgument(message); } }
/** * Check to make sure that the boolean test value is false. * * @param test * A false value. * @param message * The exception message thrown if "test" is invalid. */ protected void requireFalse(boolean test, String message) throws WingInvalidArgument { if (test) { throw new WingInvalidArgument(message); } }
/** * Check to make sure the parameter is not null or an empty string. * * @param parameter * A non null and none empty string * @param message * The exception message thrown if parameter is invalid. */ protected void require(Message parameter, String message) throws WingInvalidArgument { if (parameter == null) { throw new WingInvalidArgument(message); } }
/** * Check to make sure that the parameter is GREATER THAN (note: not equal * to) the given greater variable. * * @param parameter * An int who's value is greater than greater. * @param greater * An int who's value is lesser that greater. * @param message * The exception message thrown if the parameter is invalid. */ protected void greater(int parameter, int greater, String message) throws WingInvalidArgument { if (parameter <= greater) { throw new WingInvalidArgument(message); } }
/** * Check to make sure that the parameter is LESS THAN (note: not equal to) * the given lesser variable. * * @param parameter * An int who's value is less than lesser. * @param lesser * An int who's value is greater that lesser. * @param message * The exception message thrown if the parameter is invalid. */ protected void lesser(int parameter, int lesser, String message) throws WingInvalidArgument { if (parameter >= lesser) { throw new WingInvalidArgument(message); } }
/** * Check to make sure the parameter is not null or an empty string. * * @param parameter * A non null and none empty string * @param message * The exception message thrown if parameter is invalid. */ protected void require(String parameter, String message) throws WingInvalidArgument { if (parameter == null || parameter.equals("")) { throw new WingInvalidArgument(message); } }
/** * Check to make sure that the parameter is a member of one of the options. * This method will accept null values, if you need to restrict and not * allow null values then use the require() method in conjunction with this * method. * * @param parameter * A null string, or a member of the options array. * @param options * A list of possible values for the parameter. * @param message * The exception message thrown if the parameter is invalid. */ protected void restrict(String parameter, String[] options, String message) throws WingInvalidArgument { if (parameter == null) { return; } for (String test : options) { if (parameter.equals(test)) { return; } } // short circuit the method call. throw new WingInvalidArgument(message); }