Package com.microstrategy.utils
Class ValidationHelper
- java.lang.Object
-
- com.microstrategy.utils.ValidationHelper
-
public class ValidationHelper extends java.lang.Object
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.- Since:
- MicroStrategy Web 7.3.1 or earlier
-
-
Constructor Summary
Constructors Constructor Description ValidationHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
fixBoolean(java.lang.String stringToValidate, boolean defaultValue)
static int
fixInt(java.lang.String stringToValidate, int defaultValue)
static java.lang.Number
getValidInt(java.lang.String value)
Identical toisValidInt(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 java.lang.Number
getValidReal(java.lang.String value, java.util.Locale locale)
Identical toisValidReal(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(java.lang.String value)
Validates that the given is not empty.static boolean
isValidDate(java.lang.String value, java.util.Locale locale)
Validates that the given string value is a valid date.static boolean
isValidDate(java.lang.String value, java.util.Locale locale, java.util.Date min, java.util.Date max)
Validates that the given string value is a valid date within the given range.static boolean
isValidInt(java.lang.String value)
Validates that the given string value is an integer.static boolean
isValidInt(java.lang.String value, int min, int max)
Validates that the given string value is an integer in the specified range.static boolean
isValidReal(java.lang.String value, java.util.Locale locale)
Validates that the given string value is a valid real number.static boolean
isValidReal(java.lang.String value, java.util.Locale locale, double min, double max)
Validates that the given string value is a valid real number within the given range.static boolean
validateValueDataType(java.lang.String value, int dataType, java.util.Locale locale)
Validates that the given value is valid, in accordance to the data type specified.
-
-
-
Method Detail
-
isValidInt
public static boolean isValidInt(java.lang.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 usesInteger.parseInt
to validate the value- Parameters:
value
- a non-formated String representation of an integer.- Returns:
- true if the string represents a valid integer.
-
getValidInt
public static java.lang.Number getValidInt(java.lang.String value) throws java.text.ParseException, java.lang.IllegalArgumentException
Identical toisValidInt(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:
java.text.ParseException
- if there was a problem parsing valuejava.lang.NullPointerException
- if value is nulljava.lang.IllegalArgumentException
- Thrown when system default locale is null.- Since:
- MicroStrategy Web 8.0.0
-
isValidInt
public static boolean isValidInt(java.lang.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 usesInteger.parseInt
to validate the value- Parameters:
value
- a non-formated String representation of an integer.min
- the minimum valuemax
- the max value- Returns:
- true if the string represents a valid integer within the given range.
-
isValidReal
public static boolean isValidReal(java.lang.String value, java.util.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 aNumberFormatter
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.
-
getValidReal
public static java.lang.Number getValidReal(java.lang.String value, java.util.Locale locale) throws java.text.ParseException, java.lang.IllegalArgumentException
Identical toisValidReal(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 valuelocale
- locale- Returns:
- validated value
- Throws:
java.text.ParseException
- if there was a problem parsing valuejava.lang.NullPointerException
- if value is nulljava.lang.IllegalArgumentException
- Thrown whenlocale
is null.- Since:
- MicroStrategy Web 8.0.0
-
isValidReal
public static boolean isValidReal(java.lang.String value, java.util.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 aNumberFormat
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 valuemax
- the max value- Returns:
- true if the string represents a valid real.
-
isValidDate
public static boolean isValidDate(java.lang.String value, java.util.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 aDateFormat
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.
-
isValidDate
public static boolean isValidDate(java.lang.String value, java.util.Locale locale, java.util.Date min, java.util.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 aDateFormat
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 datemax
- the maximum date- Returns:
- true if the string represents a valid date.
-
isNonEmptyString
public static boolean isNonEmptyString(java.lang.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
-
validateValueDataType
public static boolean validateValueDataType(java.lang.String value, int dataType, java.util.Locale locale)
Validates that the given value is valid, in accordance to the data type specified. Data type should be a value taken fromEnumDSSXMLDataType
- 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.
-
fixBoolean
public static boolean fixBoolean(java.lang.String stringToValidate, boolean defaultValue)
-
fixInt
public static int fixInt(java.lang.String stringToValidate, int defaultValue)
-
-