I'm new to Java. I wrote a class called QueryCondition which is used to represent query conditions in a SQL command, such as id > 5, bankBalance < 100, etc. Obviously, a query condition like this needs to have both of the operands, so in the constructor of QueryCondition I check for empty or null operands and throw an exception if such is the case. Is this good practice?
public class QueryCondition
{
public enum Comparator
{
smallerThan,
smallerThanOrEqualTo,
largerThan,
largerThanOrEqualTo,
equals,
doesNotEqual
}
private final String _leftOp;
private final String _rightOp;
private final Comparator _comp;
public QueryCondition( String leftOperand, Comparator compare, String rightOperand ) throws Exception
{
if( leftOperand == null || leftOperand.isEmpty() ||
rightOperand == null || rightOperand.isEmpty() )
{
throw new Exception("QueryCondition cannot be constructed with empty operands.");
}
_leftOp = leftOperand;
_rightOp = rightOperand;
_comp = compare;
}
}