Class Result<T>

  • Type Parameters:
    T -

    public class Result<T>
    extends java.lang.Object
    There are various forms of results that are represented by this class:
    1. success - in which case only the model field is set
    2. success with warnings - model field + non-error model problems
    3. error - no model, but diagnostics
    4. error - (partial) model and diagnostics
    Could encode these variants as subclasses, but kept in one for now
    • Field Detail

      • errors

        private final boolean errors
        Class definition
      • value

        private final T value
      • problems

        private final java.lang.Iterable<? extends ModelProblem> problems
    • Constructor Detail

      • Result

        private Result​(boolean errors,
                       T model,
                       java.lang.Iterable<? extends ModelProblem> problems)
    • Method Detail

      • success

        public static <T> Result<T> success​(T model)
        Success without warnings
        Parameters:
        model -
      • success

        public static <T> Result<T> success​(T model,
                                            java.lang.Iterable<? extends ModelProblem> problems)
        Success with warnings
        Parameters:
        model -
        problems -
      • success

        public static <T> Result<T> success​(T model,
                                            Result<?>... results)
        Success with warnings
        Parameters:
        model -
        results -
      • error

        public static <T> Result<T> error​(java.lang.Iterable<? extends ModelProblem> problems)
        Error with problems describing the cause
        Parameters:
        problems -
      • error

        public static <T> Result<T> error​(T model)
      • error

        public static <T> Result<T> error​(Result<?> result)
      • error

        public static <T> Result<T> error​(Result<?>... results)
      • error

        public static <T> Result<T> error​(T model,
                                          java.lang.Iterable<? extends ModelProblem> problems)
        Error with partial result and problems describing the cause
        Parameters:
        model -
        problems -
      • newResult

        public static <T> Result<T> newResult​(T model,
                                              java.lang.Iterable<? extends ModelProblem> problems)
        New result - determine whether error or success by checking problems for errors
        Parameters:
        model -
        problems -
      • addProblem

        public static <T> Result<T> addProblem​(Result<T> result,
                                               ModelProblem problem)
        New result consisting of given result and new problem. Convenience for newResult(result.get(), concat(result.getProblems(),problems)).
        Parameters:
        result -
        problem -
      • addProblems

        public static <T> Result<T> addProblems​(Result<T> result,
                                                java.lang.Iterable<? extends ModelProblem> problems)
        New result that includes the given
        Parameters:
        result -
        problems -
      • addProblems

        public static <T> Result<T> addProblems​(Result<T> result,
                                                Result<?>... results)
      • newResultSet

        public static <T> Result<java.lang.Iterable<T>> newResultSet​(java.lang.Iterable<? extends Result<? extends T>> results)
        Turns the given results into a single result by combining problems and models into single collection.
        Parameters:
        results -
      • hasErrors

        private static boolean hasErrors​(java.lang.Iterable<? extends ModelProblem> problems)
      • getProblems

        public java.lang.Iterable<? extends ModelProblem> getProblems()
      • get

        public T get()
      • hasErrors

        public boolean hasErrors()