From: Roland Haeder Date: Mon, 12 Oct 2015 10:05:24 +0000 (+0200) Subject: need to handle Integer and Long separately X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ac50e5a4d8eb76e78de7d75305c004b07b521740;p=jcoreee.git need to handle Integer and Long separately Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java b/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java index dcfbd8c..ba45913 100644 --- a/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java +++ b/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java @@ -61,18 +61,42 @@ public abstract class BaseLongValidator extends BaseObjectValidator implements V // Generate message requiredMessage = MessageFormat.format("Field {0} is not Long.: {1}", field, value); //NOI18N + // Value is not right type + facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N + break; + } else if ((!allowNull) && (!(value instanceof Integer))) { + // Generate message + requiredMessage = MessageFormat.format("Field {0} is not Integer.: {1}", field, value); //NOI18N + // Value is not right type facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N break; } - // Cast to string - Long num = (Long) value; + // Declare variables + Integer i = null; + Long l = null; + + // Which type? + if (value instanceof Integer) { + // Cast to Long + i = (Integer) value; + } else { + // Cast to Long + l = (Long) value; + } // Is the number below zero? - if (num < 0) { + if ((!allowNull) && ((i instanceof Integer) && (i < 0))) { + // Generate message + requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", i, field); //NOI18N + + // Abort processing here + facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); + break; + } else if ((!allowNull) && ((l instanceof Long) && (l < 0))) { // Generate message - requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", num, field); //NOI18N + requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", l, field); //NOI18N // Abort processing here facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage);