Class ValidationUtils
java.lang.Object
com.broadleafcommerce.data.tracking.core.mapping.validation.ValidationUtils
Helpful class providing convenient methods relevant to validation.
- Author:
- Samarth Dhruva (samarthd)
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
static boolean
isAtLeastZero
(BigDecimal value) Checks if the given value is greater than or equal toBigDecimal.ZERO
.static boolean
isAtLeastZero
(javax.money.MonetaryAmount amount) Checks that thisMonetaryAmount
contains a value that greater than or equal to zero.static boolean
isAtLeastZeroOrNull
(BigDecimal value) Checks if the given value is greater than or equal toBigDecimal.ZERO
.static boolean
isAtLeastZeroOrNull
(javax.money.MonetaryAmount amount) Checks that thisMonetaryAmount
contains a value that greater than or equal to zero.static boolean
isValidEmailAddressOrNull
(String address) Checks the given string to see if it matches the format expected of an email address.static boolean
isValidEndDate
(Instant startDate, Instant endDate) Checks the given dates to ensure that the end date, if it exists, is after the start date.static boolean
Checks the given string to see if it matches the format expected of a URL.
-
Method Details
-
isValidUrlStringOrNull
Checks the given string to see if it matches the format expected of a URL. This validation is set up to match the logic performed by the frontend when it does its own URL validation.- Parameters:
url
- the string whose structure should be checked- Returns:
- true if the string is null or has a leading
/
-
isValidEndDate
Checks the given dates to ensure that the end date, if it exists, is after the start date.- Parameters:
startDate
- the start date for an active date rangeendDate
- the end date for an active date range- Returns:
- true if end date occurs after start date where both exist
-
isAtLeastZero
Checks if the given value is greater than or equal toBigDecimal.ZERO
. Useful for validations of pricing fields where negative values are disallowed.- Parameters:
value
- the number which should be checked- Returns:
- true if the value is at least zero, false otherwise
- See Also:
-
isAtLeastZeroOrNull
Checks if the given value is greater than or equal toBigDecimal.ZERO
. Useful for validations of pricing fields where negative values are disallowed.- Parameters:
value
- the number which should be checked- Returns:
- true if the value is null or at least zero, false otherwise
- See Also:
-
isAtLeastZeroOrNull
public static boolean isAtLeastZeroOrNull(@Nullable javax.money.MonetaryAmount amount) Checks that thisMonetaryAmount
contains a value that greater than or equal to zero. Useful for validations of pricing fields where negative values are disallowed.- Parameters:
amount
-- Returns:
-
isAtLeastZero
public static boolean isAtLeastZero(@NonNull javax.money.MonetaryAmount amount) Checks that thisMonetaryAmount
contains a value that greater than or equal to zero. Useful for validations of pricing fields where negative values are disallowed.- Parameters:
amount
-- Returns:
-
isValidEmailAddressOrNull
Checks the given string to see if it matches the format expected of an email address.While this validation method is not perfect due to the complexity of the standard, this should validate the majority of requirements on email address format. See https://stackoverflow.com/questions/201323/how-to-validate-an-email-address-using-a-regular-expression/201378#201378
- Parameters:
address
- the string whose structure should be checked- Returns:
- true if the string is null or is a valid email address
-
getEmailPattern
-