- java.lang.Object
-
- org.github.gestalt.config.utils.GResultOf<T>
-
- Type Parameters:
T- type of validatedOf
public final class GResultOf<T> extends java.lang.ObjectClass that holds the results, errors or both.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> GResultOf<T>errors(java.util.List<ValidationError> errors)Create a GResultOf with errors.static <T> GResultOf<T>errors(ValidationError errors)Create a GResultOf with a error.java.util.List<ValidationError>getErrors()return a list of ValidationError.java.util.List<ValidationError>getErrors(ValidationLevel level)return a list of ValidationError for a level.java.lang.BooleanhasErrors()returns true if the GResultOf has errors.java.lang.BooleanhasErrors(ValidationLevel level)returns true if the GResultOf has errors of level.booleanhasResults()returns true if this GResultOf has results.<U> GResultOf<U>mapWithError(java.util.function.Function<T,U> resultFunction)If a result is present map the result with the resultFunction.<U> GResultOf<U>mapWithError(java.util.function.Function<T,U> resultFunction, ValidationError missingError)If there are results, return the results with any errors.static <T> GResultOf<T>result(T answer)Create a GResultOf with a valid result.static <T> GResultOf<T>resultOf(T answer, java.util.List<ValidationError> errors)Create a GResultOf with a results and an error.static <T> GResultOf<T>resultOf(T answer, ValidationError errors)Create a GResultOf with a results and an error.Tresults()returns the results.<X extends java.lang.Throwable>
voidthrowIfNoResults(java.util.function.Supplier<? extends X> exceptionSupplier)If a result is present, return the result, otherwise throws an exception produced by the exceptionSupplier.
-
-
-
Method Detail
-
result
public static <T> GResultOf<T> result(T answer)
Create a GResultOf with a valid result.- Type Parameters:
T- type of GResultOf- Parameters:
answer- valid results- Returns:
- GResultOf
-
errors
public static <T> GResultOf<T> errors(java.util.List<ValidationError> errors)
Create a GResultOf with errors.- Type Parameters:
T- type of GResultOf- Parameters:
errors- list of ValidationError- Returns:
- GResultOf
-
errors
public static <T> GResultOf<T> errors(ValidationError errors)
Create a GResultOf with a error.- Type Parameters:
T- type of GResultOf- Parameters:
errors- list of ValidationError- Returns:
- GResultOf
-
resultOf
public static <T> GResultOf<T> resultOf(T answer, ValidationError errors)
Create a GResultOf with a results and an error.- Type Parameters:
T- type of GResultOf- Parameters:
answer- valid resultserrors- list of ValidationError- Returns:
- GResultOf
-
resultOf
public static <T> GResultOf<T> resultOf(T answer, java.util.List<ValidationError> errors)
Create a GResultOf with a results and an error.- Type Parameters:
T- type of GResultOf- Parameters:
answer- valid resultserrors- list of ValidationError- Returns:
- GResultOf
-
hasErrors
public java.lang.Boolean hasErrors()
returns true if the GResultOf has errors.- Returns:
- true if the GResultOf has errors
-
hasErrors
public java.lang.Boolean hasErrors(ValidationLevel level)
returns true if the GResultOf has errors of level.- Parameters:
level- level of the error we are checking for.- Returns:
- true if the GResultOf has errors of level
-
getErrors
public java.util.List<ValidationError> getErrors()
return a list of ValidationError.- Returns:
- a list of ValidationError
-
getErrors
public java.util.List<ValidationError> getErrors(ValidationLevel level)
return a list of ValidationError for a level.- Parameters:
level- of errors we are looking for.- Returns:
- errors that match the level.
-
hasResults
public boolean hasResults()
returns true if this GResultOf has results.- Returns:
- true if this GResultOf has results.
-
results
public T results()
returns the results.- Returns:
- the results.
-
throwIfNoResults
public <X extends java.lang.Throwable> void throwIfNoResults(java.util.function.Supplier<? extends X> exceptionSupplier) throws X extends java.lang.ThrowableIf a result is present, return the result, otherwise throws an exception produced by the exceptionSupplier.- Type Parameters:
X- Type of the exception thrown- Parameters:
exceptionSupplier- throw supplied exception if no results- Throws:
X- exception to be thrown by supplierX extends java.lang.Throwable
-
mapWithError
public <U> GResultOf<U> mapWithError(java.util.function.Function<T,U> resultFunction)
If a result is present map the result with the resultFunction. If there are errors it will return a GResultOf with the errors. If there is no result, then it will return a GResultOf with errors.- Type Parameters:
U- The type of the mapped GResultOf to return- Parameters:
resultFunction- function to map the result- Returns:
- a mapped GResultOf with the result and any errors.
-
mapWithError
public <U> GResultOf<U> mapWithError(java.util.function.Function<T,U> resultFunction, ValidationError missingError)
If there are results, return the results with any errors. If there are no results return the errors along with the missing error.- Type Parameters:
U- The type of the mapped GResultOf to return- Parameters:
resultFunction- function to map the resultmissingError- error to return if there is no result- Returns:
- a mapped GResultOf with the result.
-
-