Class Failure

  • All Implemented Interfaces:
    java.io.Serializable, Bean, ImmutableBean

    public final class Failure
    extends java.lang.Object
    implements ImmutableBean, java.io.Serializable
    Description of a failed result.

    If calculation of a result fails this class provides details of the failure. There is a single reason and message and a set of detailed failure items. Each FailureItem has details of the actual cause.

    In most cases, instances of Failure should be created using one of the failure methods on Result.

    See Also:
    Serialized Form
    • Method Detail

      • of

        public static Failure of​(FailureReason reason,
                                 java.lang.String message,
                                 java.lang.Object... messageArgs)
        Obtains a failure from a reason and message.

        The message is produced using a template that contains zero to many "{}" placeholders. Each placeholder is replaced by the next available argument. If there are too few arguments, then the message will be left with placeholders. If there are too many arguments, then the excess arguments are appended to the end of the message. No attempt is made to format the arguments. See Messages.format(String, Object...) for more details.

        An exception will be created internally to obtain a stack trace. The cause type will not be present in the resulting failure.

        Parameters:
        reason - the reason
        message - a message explaining the failure, not empty, uses "{}" for inserting messageArgs
        messageArgs - the arguments for the message
        Returns:
        the failure
      • of

        public static Failure of​(FailureReason reason,
                                 java.lang.Exception cause,
                                 java.lang.String message,
                                 java.lang.Object... messageArgs)
        Obtains a failure from a reason, message and exception.

        The message is produced using a template that contains zero to many "{}" placeholders. Each placeholder is replaced by the next available argument. If there are too few arguments, then the message will be left with placeholders. If there are too many arguments, then the excess arguments are appended to the end of the message. No attempt is made to format the arguments. See Messages.format(String, Object...) for more details.

        Parameters:
        reason - the reason
        cause - the cause
        message - the failure message, possibly containing placeholders, formatted using Messages.format(java.lang.String, java.lang.Object)
        messageArgs - arguments used to create the failure message
        Returns:
        the failure
      • of

        public static Failure of​(FailureReason reason,
                                 java.lang.Exception cause)
        Obtains a failure from a reason and exception.
        Parameters:
        reason - the reason
        cause - the cause
        Returns:
        the failure
      • of

        public static Failure of​(FailureItem item)
        Obtains a failure for a single failure item.
        Parameters:
        item - the failure item
        Returns:
        the failure
      • of

        public static Failure of​(FailureItem item,
                                 FailureItem... additionalItems)
        Obtains a failure for multiple failure items.
        Parameters:
        item - the first failure item
        additionalItems - additional failure items
        Returns:
        the failure
      • of

        public static Failure of​(java.util.Collection<FailureItem> items)
        Obtains a failure for a non-empty collection of failure items.
        Parameters:
        items - the failures, not empty
        Returns:
        the failure
      • meta

        public static Failure.Meta meta()
        The meta-bean for Failure.
        Returns:
        the meta-bean, not null
      • getReason

        public FailureReason getReason()
        Gets the reason associated with the failure.
        Returns:
        the value of the property, not null
      • getMessage

        public java.lang.String getMessage()
        Gets the error message associated with the failure.
        Returns:
        the value of the property, not empty
      • getItems

        public com.google.common.collect.ImmutableSet<FailureItem> getItems()
        Gets the set of failure items. There will be at least one failure item.
        Returns:
        the value of the property, not empty
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object