if (valueHi.getClass().isAssignableFrom(valueLo.getClass()))
loExtendsHi = true;
else if (valueLo.getClass().isAssignableFrom(valueHi.getClass()))
loExtendsHi = false;
else
throw new AraneaRuntimeException("RangeConstraint can be used only with fields of compatible types.");
int comparison = 0; // Will be -1, 0 or 1 depending on whether sLo is <, = or > than sHi
// Strings are handled separately because we have to compare them in given locale.
if (valueLo instanceof String && valueHi instanceof String) {
Collator collator = Collator.getInstance(); // TODO: Must be locale-specific
comparison = collator.compare((String)valueLo, (String)valueHi);
}
else if (valueLo instanceof Comparable && valueHi instanceof Comparable){
if (loExtendsHi)
comparison = ((Comparable)valueLo).compareTo(valueHi);
else
comparison = -1 * ((Comparable)valueHi).compareTo(valueLo);
}
else { // Objects are not comparable
throw new AraneaRuntimeException("RangeConstraint expects fields of Comparable type");
}
if (comparison > 0 || (!allowEquals && comparison == 0)){
addError(
ErrorUtil.localizeAndFormat(