Class FailureItem

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

    public final class FailureItem
    extends java.lang.Object
    implements ImmutableBean, java.io.Serializable
    Details of a single failed item.

    This is used in Failure and FailureItems to capture details of a single failure. Details include the reason, message and stack trace.

    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  FailureItem.Meta
      The meta-bean for FailureItem.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String EXCEPTION_MESSAGE_ATTRIBUTE
      Attribute used to store the exception message.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      com.google.common.collect.ImmutableMap<java.lang.String,​java.lang.String> getAttributes()
      Gets the attributes associated with this failure.
      java.util.Optional<java.lang.Class<? extends java.lang.Exception>> getCauseType()
      Gets the type of the exception that caused the failure, not present if it wasn't caused by an exception.
      java.lang.String getMessage()
      Gets the error message associated with the failure.
      FailureReason getReason()
      Gets the reason associated with the failure.
      java.lang.String getStackTrace()
      Gets stack trace where the failure occurred.
      int hashCode()  
      static FailureItem.Meta meta()
      The meta-bean for FailureItem.
      FailureItem.Meta metaBean()  
      static FailureItem of​(FailureReason reason, java.lang.Exception cause)
      Obtains a failure from a reason and exception.
      static FailureItem of​(FailureReason reason, java.lang.Exception cause, java.lang.String message, java.lang.Object... messageArgs)
      Obtains a failure from a reason, exception and message.
      static FailureItem of​(FailureReason reason, java.lang.String message, java.lang.Object... messageArgs)
      Obtains a failure from a reason and message.
      java.lang.String toString()
      Returns a string summary of the failure, as a single line excluding the stack trace.
      FailureItem withAttribute​(java.lang.String key, java.lang.String value)
      Returns an instance with the specified attribute added.
      FailureItem withAttributes​(java.util.Map<java.lang.String,​java.lang.String> attributes)
      Returns an instance with the specified attributes added.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • EXCEPTION_MESSAGE_ATTRIBUTE

        public static final java.lang.String EXCEPTION_MESSAGE_ATTRIBUTE
        Attribute used to store the exception message.
        See Also:
        Constant Field Values
    • Method Detail

      • of

        public static FailureItem 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 "{}" or "{abc}" placeholders. Each placeholder is replaced by the next available argument. If the placeholder has a name, its value is added to the attributes map with the name as a key. 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.formatWithAttributes(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 FailureItem 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 FailureItem of​(FailureReason reason,
                                     java.lang.Exception cause,
                                     java.lang.String message,
                                     java.lang.Object... messageArgs)
        Obtains a failure from a reason, exception 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.formatWithAttributes(String, Object...) for more details.

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

        public FailureItem withAttribute​(java.lang.String key,
                                         java.lang.String value)
        Returns an instance with the specified attribute added.

        If the attribute map of this instance has the specified key, the value is replaced.

        Parameters:
        key - the key to add
        value - the value to add
        Returns:
        the new failure item
      • withAttributes

        public FailureItem withAttributes​(java.util.Map<java.lang.String,​java.lang.String> attributes)
        Returns an instance with the specified attributes added.

        If the attribute map of this instance has any of the new attribute keys, the values are replaced.

        Parameters:
        attributes - the new attributes to add
        Returns:
        the new failure item
      • toString

        public java.lang.String toString()
        Returns a string summary of the failure, as a single line excluding the stack trace.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the summary string
      • meta

        public static FailureItem.Meta meta()
        The meta-bean for FailureItem.
        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
      • getAttributes

        public com.google.common.collect.ImmutableMap<java.lang.String,​java.lang.String> getAttributes()
        Gets the attributes associated with this failure. Attributes can contain additional information about the failure. For example, a line number in a file or the ID of a trade.
        Returns:
        the value of the property, not null
      • getStackTrace

        public java.lang.String getStackTrace()
        Gets stack trace where the failure occurred. If the failure was caused by an Exception its stack trace is used, otherwise it's the location where the failure was created.
        Returns:
        the value of the property, not null
      • getCauseType

        public java.util.Optional<java.lang.Class<? extends java.lang.Exception>> getCauseType()
        Gets the type of the exception that caused the failure, not present if it wasn't caused by an exception.
        Returns:
        the optional value of the property, not null
      • 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