Class ValidationUtils
- java.lang.Object
-
- com.broadleafcommerce.data.tracking.core.mapping.validation.ValidationUtils
-
public final class ValidationUtils extends Object
Helpful class providing convenient methods relevant to validation.- Author:
- Samarth Dhruva (samarthd)
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
getEmailPattern()
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
isValidUrlStringOrNull(String url)
Checks the given string to see if it matches the format expected of a URL.
-
-
-
Method Detail
-
isValidUrlStringOrNull
public static boolean isValidUrlStringOrNull(@Nullable String url)
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
public static boolean isValidEndDate(@Nullable Instant startDate, @Nullable Instant endDate)
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
public static boolean isAtLeastZero(@NonNull BigDecimal value)
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(BigDecimal)
-
isAtLeastZeroOrNull
public static boolean isAtLeastZeroOrNull(@Nullable BigDecimal value)
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:
isAtLeastZero(BigDecimal)
-
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
public static boolean isValidEmailAddressOrNull(@Nullable String address)
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
public static String getEmailPattern()
-
-