]> git.mxchange.org Git - jcore-utils.git/commitdiff
need to handle Integer and Long separately
authorRoland Haeder <roland@mxchange.org>
Mon, 12 Oct 2015 10:05:24 +0000 (12:05 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 12 Oct 2015 10:05:24 +0000 (12:05 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java

index dcfbd8c46ccc6736660a4550bbcc65a2347d8ad0..ba45913c9955d1b5d63d8d16a172bd29038c969d 100644 (file)
@@ -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);