Class Outcome


  • public class Outcome
    extends java.lang.Object
    Indicates the outcome of a user-initiated action, typically an activation action.

    As well as a success/failure flag, instances of this class contain a message to be directed to the user who initiated the action. In case of success this is a short indication of what happened, and in case of failure it is an error message. The context of the action may be assumed, and does not need to be repeated here. The message should be concise (one line). In case of success, if there's really nothing to say, a null message is permitted.

    Since:
    10 Apr 2018
    Author:
    Mark Taylor
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Outcome​(boolean isSuccess, java.lang.String message)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Outcome failure​(java.lang.String message)
      Returns a failure outcome with a given message.
      static Outcome failure​(java.lang.Throwable error)
      Returns a failure outcome based on an exception.
      java.lang.String getMessage()
      Returns the message text associated with this outcome.
      boolean isSuccess()
      Indicates whether the action was successful or not.
      static Outcome success()
      Returns a success outcome with no message.
      static Outcome success​(java.lang.String message)
      Returns a success outcome with a given message.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Outcome

        protected Outcome​(boolean isSuccess,
                          java.lang.String message)
        Constructor.
        Parameters:
        isSuccess - true for success, false for error
        message - one-line outcome message
    • Method Detail

      • getMessage

        public java.lang.String getMessage()
        Returns the message text associated with this outcome.
        Returns:
        outcome message
      • isSuccess

        public boolean isSuccess()
        Indicates whether the action was successful or not.
        Returns:
        true for success, false for failure
      • success

        public static Outcome success()
        Returns a success outcome with no message.
      • success

        public static Outcome success​(java.lang.String message)
        Returns a success outcome with a given message.
        Parameters:
        message - one-line message describing successful outcome
      • failure

        public static Outcome failure​(java.lang.String message)
        Returns a failure outcome with a given message.
        Parameters:
        message - one-line message giving reason for failure
      • failure

        public static Outcome failure​(java.lang.Throwable error)
        Returns a failure outcome based on an exception.
        Parameters:
        error - error that caused the action failure; if at all possible the message should explain in user-friendy terms what went wrong