You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Mark Fairchild <ma...@telus.net> on 2005/01/25 10:42:32 UTC

Extending Validate

I've been looking into adding some methods to Validate; I'd appreciate
any feedback that anyone can provide about the utility of adding any/all
of the following methods to the Validate class.

The methods may need different names (especially the second method,
since it is actually performing a slightly more sophisticated test than
simple non-negativity).  Also, the messages could be made more
descriptive.  Still, I'm just looking for feedback on the basic
concepts.  Would these methods be valuable?



// There would be overloads of this for byte, short, and long.  
// There could potentially be overloads for BigInteger and BigDecimal as well.
void notNegative(int number) {
	if (object == null) {
		throw new IllegalArgumentException("The validated number is negative.");
	}
}

// There would be an overload of this for double.
void notNegative(float number) {
	if (0.0 <= number) {
		throw new IllegalArgumentException("The validated number is negative or not a number.");
	}
}

// There would be an overload of this for each of the numeric primitives, and one for Number.
// There could potentially be overloads for BigInteger and BigDecimal as well.
void inRange(int number, Range range) {
	if (0.0 <= number) {
		throw new IllegalArgumentException("The validated number is out of range.");
	}
}



-- 
Mark Fairchild <md...@sfu.ca>
Learn Lisp today!  Uncle Turing wants you!


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org