Package tech.jhipster.lite.error.domain
Class Assert
java.lang.Object
tech.jhipster.lite.error.domain.Assert
This class provides utilities for input assertions.
It is designed to validate domain input, if you want to validate application input it's better to stick to BeanValidation to get all errors at once and internationalized error messages.
The main goal of this class is to ensure some basic type validation in your classes. If you have to do business related validation you should create your own exception and code dedicated to that check
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAsserter dedicated toBigDecimalassertionsstatic classAsserter dedicated toCollectionassertionsstatic classAsserter dedicated to double values (double andDouble)static classAsserter dedicated to float values (float andFloat)static classAsserter dedicated to instant valuestatic classAsserter dedicated to Integer values (int andInteger)static classAsserter dedicated to long values (long andLong)static classAsserter dedicated toStringassertions -
Method Summary
Modifier and TypeMethodDescriptionstatic Assert.DoubleAsserterCreate a fluent asserter for Double values (double andDouble)static Assert.FloatAsserterCreate a fluent asserter for Float values (float andFloat)static Assert.IntegerAsserterCreate a fluent asserter for Integer values (int andInteger)static Assert.LongAsserterCreate a fluent asserter for Long values (long andLong)static Assert.StringAsserterCreate a fluent asserter forStringstatic Assert.BigDecimalAsserterfield(String field, BigDecimal input) Create a fluent asserter forBigDecimalvaluesstatic Assert.InstantAsserterCreate a fluent asserter for an Instantstatic <T> Assert.CollectionAsserter<T>field(String field, Collection<T> input) Create a fluent asserter forCollectionstatic voidEnsure that the value is not blank (null, empty or only whitespace)static voidnotEmpty(String field, Collection<?> collection) Ensure that the given collection is not emptystatic voidEnsure that the input is not nullstatic voidnoWhitespace(String field, String input) Ensure that the value contains no whitespace
-
Method Details
-
notNull
Ensure that the input is not null- Parameters:
field- name of the field to check (will be displayed in exception message)input- input to check- Throws:
MissingMandatoryValueException- if the input is null
-
notBlank
Ensure that the value is not blank (null, empty or only whitespace)- Parameters:
field- name of the field to check (will be displayed in exception message)input- input to check- Throws:
MissingMandatoryValueException- if the input is blank
-
notEmpty
Ensure that the given collection is not empty- Parameters:
field- name of the field to check (will be displayed in exception message)collection- collection to check- Throws:
MissingMandatoryValueException- if the collection is null or empty
-
noWhitespace
Ensure that the value contains no whitespace- Parameters:
field- name of the field to check (will be displayed in exception message)input- input to check- Throws:
MissingMandatoryValueException- if the input contains whitespace
-
field
- Parameters:
field- name of the field to check (will be displayed in exception message)input- string to check- Returns:
- A
Assert.StringAsserterfor this field and value
-
field
Create a fluent asserter for Integer values (int andInteger)Usage:
Assert.field("age", age) .min(0) .max(150);- Parameters:
field- name of the field to check (will be displayed in exception message)input- value to check- Returns:
- An
Assert.IntegerAsserterfor this field and value
-
field
Create a fluent asserter for Long values (long andLong)Usage:
Assert.field("duration", duration) .min(100) .max(500_000);- Parameters:
field- name of the field to check (will be displayed in exception message)input- value to check- Returns:
- An
Assert.LongAsserterfor this field and value
-
field
Create a fluent asserter for Float values (float andFloat)Usage:
Assert.field("rate", rate) .min(0) .max(1);- Parameters:
field- name of the field to check (will be displayed in exception message)input- value to check- Returns:
- An
Assert.DoubleAsserterfor this field and value
-
field
Create a fluent asserter for Double values (double andDouble)Usage:
Assert.field("rate", rate) .min(0) .max(1);- Parameters:
field- name of the field to check (will be displayed in exception message)input- value to check- Returns:
- An
Assert.DoubleAsserterfor this field and value
-
field
- Parameters:
field- name of the field to check (will be displayed in exception message)input- value to check- Returns:
- An
Assert.BigDecimalAsserterfor this field and value
-
field
Create a fluent asserter forCollectionUsage:
Assert.field("name", name) .notEmpty() .maxSize(150);- Parameters:
field- name of the field to check (will be displayed in exception message)input- collection to check- Returns:
- A
Assert.CollectionAsserterfor this field and value
-
field
Create a fluent asserter for an InstantUsage:
Assert.field("date", date) .inPast() .after(otherDate);- Parameters:
field- name of the field to check (will be displayed in exception message)input- value to check- Returns:
- An
Assert.InstantAsserterfor this field and value
-