- java.lang.Object
-
- de.mlo.dev.validation.ValidationInfo
-
- All Implemented Interfaces:
Comparable<ValidationInfo>
public class ValidationInfo extends Object implements Comparable<ValidationInfo>
TheValidationInfocontains a single result of a validation process. MultipleValidationInfos can be aggregated with theValidationResult.
To chain and group validation processes you can use theValidator.- Author:
- mlo
-
-
Constructor Summary
Constructors Constructor Description ValidationInfo(boolean valid, @Nullable String message)Creates a newValidationInfo.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(@NotNull ValidationInfo o)@Nullable StringgetMessage()static @NotNull ValidationInfoinvalid(@NotNull String messageFormat, Object... args)Creates a newValidationInfowhich indicates that the validation process was not successful:isValid()returnsfalse.
In this case you should give a detailed messages what went wrong.
This function has a built-in formatter which usesString.format(String, Object...)static @NotNull ValidationInfoinvalid(@Nullable String message)Creates a newValidationInfowhich indicates that the validation process was not successful:isValid()returnsfalse.
In this case you should give a detailed messages what went wrong.booleanisInvalid()booleanisValid()static @NotNull ValidationInfovalid()Creates a newValidationInfowhich indicates that the validation process was successful:isValid()returnstrue.
The message will benullin this case.static @NotNull ValidationInfovalid(@Nullable String message)Creates a newValidationInfowhich indicates that the validation process was successful:isValid()returnstrue.
-
-
-
Constructor Detail
-
ValidationInfo
public ValidationInfo(boolean valid, @Nullable @Nullable String message)Creates a newValidationInfo. You can also use thevalid()orinvalid(String)function to create a new info object.- Parameters:
valid- true, if the validation process was successfulmessage- A detailed message if the validation failed. If the validation was successful the message usually is not necessary.
-
-
Method Detail
-
valid
@NotNull public static @NotNull ValidationInfo valid()
Creates a newValidationInfowhich indicates that the validation process was successful:isValid()returnstrue.
The message will benullin this case. If you would like to add a message, you can usevalid(String)but this is usually not necessary.- Returns:
- A new
ValidationInfowhich indicates that the validation process was successful
-
valid
@NotNull public static @NotNull ValidationInfo valid(@Nullable @Nullable String message)
Creates a newValidationInfowhich indicates that the validation process was successful:isValid()returnstrue. You also can add a message but this is usually not necessary if a validation was successful.- Parameters:
message- A detailed message of the validation process- Returns:
- A new
ValidationInfowhich indicates that the validation process was successful
-
invalid
@NotNull public static @NotNull ValidationInfo invalid(@Nullable @Nullable String message)
Creates a newValidationInfowhich indicates that the validation process was not successful:isValid()returnsfalse.
In this case you should give a detailed messages what went wrong. It is not mandatory (you can passnull) but it is recommended.- Parameters:
message- A detailed message, what went wrong- Returns:
- A new
ValidationInfowhich indicates that the validation process was not successful
-
invalid
@NotNull public static @NotNull ValidationInfo invalid(@NotNull @NotNull String messageFormat, Object... args)
Creates a newValidationInfowhich indicates that the validation process was not successful:isValid()returnsfalse.
In this case you should give a detailed messages what went wrong.
This function has a built-in formatter which usesString.format(String, Object...)- Parameters:
messageFormat- A detailed message, what went wrongargs- Objects which should replace the placeholder within the message- Returns:
- A new
ValidationInfowhich indicates that the validation process was not successful - See Also:
String.format(String, Object...)
-
isValid
public boolean isValid()
- Returns:
trueif the validation was successful.falseif the validation failed. If the validation failed, checkgetMessage()
-
isInvalid
public boolean isInvalid()
- Returns:
falseif the validation was successful.trueif the validation failed. If the validation failed, checkgetMessage()
-
getMessage
@Nullable public @Nullable String getMessage()
- Returns:
- A detailed message of the validation process. This usually is filled, if the validation failed. If the validation was successful the message can be null.
-
compareTo
public int compareTo(@NotNull @NotNull ValidationInfo o)- Specified by:
compareToin interfaceComparable<ValidationInfo>
-
-