public class

ValidationHelper

extends Object
java.lang.Object
   ↳ com.microstrategy.utils.ValidationHelper

Class Overview

This is a simple helper class with methods to validate strings.
The methods provided helps validating if a string is a valid integer/real/date. It also provides a method to check if a String is empty.

Summary

Public Constructors
ValidationHelper()
Public Methods
static boolean fixBoolean(String stringToValidate, boolean defaultValue)
static int fixInt(String stringToValidate, int defaultValue)
static Number getValidInt(String value)
Identical to isValidInt(String), except this returns the validated value, which may be different from the original input value since the validation procedure may strip out whitespace and other redundant symbols.
static Number getValidReal(String value, Locale locale)
Identical to isValidReal(String, Locale), except this returns the validated value, which may be different from the original input value since the validation procedure may strip out whitespace and other redundant symbols.
static boolean isNonEmptyString(String value)
Validates that the given is not empty.
static boolean isValidDate(String value, Locale locale, Date min, Date max)
Validates that the given string value is a valid date within the given range.
static boolean isValidDate(String value, Locale locale)
Validates that the given string value is a valid date.
static boolean isValidInt(String value, int min, int max)
Validates that the given string value is an integer in the specified range.
static boolean isValidInt(String value)
Validates that the given string value is an integer.
static boolean isValidReal(String value, Locale locale)
Validates that the given string value is a valid real number.
static boolean isValidReal(String value, Locale locale, double min, double max)
Validates that the given string value is a valid real number within the given range.
static boolean validateValueDataType(String value, int dataType, Locale locale)
Validates that the given value is valid, in accordance to the data type specified.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ValidationHelper ()

Public Methods

public static boolean fixBoolean (String stringToValidate, boolean defaultValue)

public static int fixInt (String stringToValidate, int defaultValue)

public static Number getValidInt (String value)

Identical to isValidInt(String), except this returns the validated value, which may be different from the original input value since the validation procedure may strip out whitespace and other redundant symbols.

Parameters
value unvalidated value
Returns
  • validated value
Throws
ParseException if there was a problem parsing value
NullPointerException if value is null
IllegalArgumentException Thrown when system default locale is null.

public static Number getValidReal (String value, Locale locale)

Identical to isValidReal(String, Locale), except this returns the validated value, which may be different from the original input value since the validation procedure may strip out whitespace and other redundant symbols.

Parameters
value unvalidated value
locale locale
Returns
  • validated value
Throws
ParseException if there was a problem parsing value
NullPointerException if value is null
IllegalArgumentException Thrown when locale is null.

public static boolean isNonEmptyString (String value)

Validates that the given is not empty. It checks for null, for empty strings and for strings with only white spaces

Parameters
value the string to validate
Returns
  • true if the string is not empty

public static boolean isValidDate (String value, Locale locale, Date min, Date max)

Validates that the given string value is a valid date within the given range. The value must be formatted based on the given locale using SHORT date format (i.e. mm/dd/yyyy). It uses a DateFormat to validate the value.

Parameters
value a String representing a date.
locale the locale in which the strings is expected to be formatted.
min the minimum date
max the maximum date
Returns
  • true if the string represents a valid date.

public static boolean isValidDate (String value, Locale locale)

Validates that the given string value is a valid date. The value must be formatted based on the given locale using SHORT date format (i.e. mm/dd/yyyy). It uses a DateFormat to validate the value.

Parameters
value a String representing a date.
locale the locale in which the strings is expected to be formatted.
Returns
  • true if the string represents a valid date.

public static boolean isValidInt (String value, int min, int max)

Validates that the given string value is an integer in the specified range. The value should be a non-formatted integer (i.e. no grouping of thousands), therefore the locale is not necessary. It uses Integer.parseInt to validate the value

Parameters
value a non-formated String representation of an integer.
min the minimum value
max the max value
Returns
  • true if the string represents a valid integer within the given range.

public static boolean isValidInt (String value)

Validates that the given string value is an integer. The value should be a non-formatted integer (i.e. no grouping of thousands), therefore the locale is not necessary. It uses Integer.parseInt to validate the value

Parameters
value a non-formated String representation of an integer.
Returns
  • true if the string represents a valid integer.

public static boolean isValidReal (String value, Locale locale)

Validates that the given string value is a valid real number. The value could be formatted based on the given locale. It uses a NumberFormatter to validate the value

Parameters
value a String representing a real value.
locale the locale in which the strings is expected to be formatted.
Returns
  • true if the string represents a valid real.

public static boolean isValidReal (String value, Locale locale, double min, double max)

Validates that the given string value is a valid real number within the given range. The value could be formatted based on the given locale. It uses a NumberFormat to validate the value

Parameters
value a String representing a real value.
locale the locale in which the strings is expected to be formatted.
min the minimum value
max the max value
Returns
  • true if the string represents a valid real.

public static boolean validateValueDataType (String value, int dataType, Locale locale)

Validates that the given value is valid, in accordance to the data type specified. Data type should be a value taken from EnumDSSXMLDataType

Parameters
value the value to validate.
dataType the date type used to validate the value.
locale locale
Returns
  • whether the value is valid or not.