Package net.groboclown.retval.impl
Class RetGenerator
- java.lang.Object
-
- net.groboclown.retval.impl.RetGenerator
-
public class RetGenerator extends java.lang.ObjectCentral handler for creating Ret* instances.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ReturnTypeFactorygetFactory()Allows for querying the active return type factory.static <T> RetNullable<T>nullableFromProblem(java.util.Collection<Problem> problems)Create aRetNullableinstance with one or more problems.static <T> RetNullable<T>nullableOk(T value)Create aRetNullableinstance with a value.static voidsetFactory(ReturnTypeFactory factory)Allows for replacing the active return type factory.static <T> RetVal<T>valFromProblem(java.util.Collection<Problem> problems)Create a new RetVal instance that has errors.static <T> RetVal<T>valOk(T value)Create a new RetVal instance that has a value and no problems.static RetVoidvoidFromProblem(java.util.Collection<Problem> problems)Constructs aRetVoidinstance with the collections of problems.static RetVoidvoidOk()Return a void object with no problems.
-
-
-
Method Detail
-
nullableOk
@Nonnull public static <T> RetNullable<T> nullableOk(@Nullable T value)
Create aRetNullableinstance with a value.- Type Parameters:
T- type of the value.- Parameters:
value- value to store in the return object.- Returns:
- the return object.
-
nullableFromProblem
@Nonnull public static <T> RetNullable<T> nullableFromProblem(@Nonnull java.util.Collection<Problem> problems)
Create aRetNullableinstance with one or more problems.- Type Parameters:
T- type of the value.- Parameters:
problems- collection of problem values.- Returns:
- the return object.
-
valOk
@Nonnull public static <T> RetVal<T> valOk(@Nonnull T value)
Create a new RetVal instance that has a value and no problems.- Type Parameters:
T- type of the value.- Parameters:
value- non-null value.- Returns:
- a RetVal containing the value.
- Throws:
java.lang.NullPointerException- if the value is null.
-
valFromProblem
@Nonnull public static <T> RetVal<T> valFromProblem(@Nonnull java.util.Collection<Problem> problems)
Create a new RetVal instance that has errors.- Type Parameters:
T- type of the value- Parameters:
problems- list of other problems to include in this value.- Returns:
- an error RetVal.
-
voidOk
@Nonnull public static RetVoid voidOk()
Return a void object with no problems.- Returns:
- a no-problem void object.
-
voidFromProblem
@Nonnull public static RetVoid voidFromProblem(@Nonnull java.util.Collection<Problem> problems)
Constructs aRetVoidinstance with the collections of problems. This is optimized to reduce the memory load where easy. If the problem list is empty, then- Parameters:
problems- collection of problems- Returns:
- a problem version of a void ret.
-
getFactory
@Nonnull public static ReturnTypeFactory getFactory()
Allows for querying the active return type factory. Primarily useful for unit tests or other systems that need runtime replacements of the type.- Returns:
- the current return type factory instance.
-
setFactory
public static void setFactory(@Nonnull ReturnTypeFactory factory)Allows for replacing the active return type factory. Primarily useful for unit tests or other systems that need runtime replacements of the type.- Parameters:
factory- the new factory to use; must be non-null.
-
-