Package e.java

Class E


public final class E extends Object
A generic and immutable error, containing helpful information
  • Field Details

    • empty

      public static final E empty
      An empty E
  • Constructor Details

    • E

      public E(Integer code, String name, String message, List<E> causes, Map<String,String> data, Long time)
      Creates an E with all its properties
      Parameters:
      code - code
      name - name
      message - message
      causes - causes
      data - data
      time - time
  • Method Details

    • code

      public Optional<Integer> code()
      Returns:
      code or empty Optional if code is not set
    • name

      public Optional<String> name()
      Returns:
      name or empty Optional if name is not set
    • message

      public Optional<String> message()
      Returns:
      message or empty Optional if message is not set
    • causes

      public List<E> causes()
      Returns:
      causes or empty List if causes are not set
    • data

      public Map<String,String> data()
      Returns:
      data or empty Map if data are not set
    • time

      public Optional<Long> time()
      Returns:
      time or empty Optional if time is not set
    • code

      public E code(int c)
      Constructs an E containing given code
      Parameters:
      c - A code
      Returns:
      A new E containing given code
    • name

      public E name(String n)
      Constructs an E containing given name
      Parameters:
      n - A name
      Returns:
      A new E containing given name
    • message

      public E message(String m)
      Constructs an E containing given message
      Parameters:
      m - Message to set
      Returns:
      A new E containing given message
    • causes

      public E causes(List<E> c)
      Constructs an E adding given causes
      Parameters:
      c - Causes as a List
      Returns:
      A new E containing causes of this E and given causes
    • causes

      public E causes(E... c)
      Constructs an E adding given causes
      Parameters:
      c - Causes as variable arguments
      Returns:
      A new E containing causes of this E and given causes
    • cause

      public E cause(E e)
      Constructs an E adding given cause
      Parameters:
      e - A cause
      Returns:
      A new E containing causes of this E and given causes
    • data

      public E data(Map<String,String> d)
      Constructs an E adding given data
      Parameters:
      d - Data as a key-value map
      Returns:
      A new E containing data of this E and given data
    • data

      public <V> E data(String k, V v)
      Constructs an E adding given data entry
      Type Parameters:
      V - Type of value of data entry
      Parameters:
      k - Key of data entry
      v - Value of data entry
      Returns:
      A new E containing data of this E and given data entry
    • time

      public E time(long t)
      Constructs an E containing given time
      Parameters:
      t - A time
      Returns:
      A new E containing given time
    • now

      public E now()
      Constructs an E containing time set to now
      Returns:
      A new E containing time set to now
      See Also:
    • causeIf

      public E causeIf(boolean condition, Supplier<E> e)
      Constructs an E adding given cause if condition holds
      Parameters:
      condition - Some condition on which to add the cause
      e - A cause
      Returns:
      A new E containing causes of this E and given cause or this E as is if condition doesn't hold
    • hasCode

      public boolean hasCode()
      Returns:
      Whether or not a code is set
    • hasName

      public boolean hasName()
      Returns:
      Whether or not a name is set
    • hasMessage

      public boolean hasMessage()
      Returns:
      Whether or not a message is set
    • hasCause

      public boolean hasCause()
      Returns:
      Whether or not a cause is set
    • hasData

      public boolean hasData()
      Returns:
      Whether or not a data is set
    • hasTime

      public boolean hasTime()
      Returns:
      Whether or not a time is set
    • toEOr

      public <A> EOr<A> toEOr()
      Converts this E to a failed EOr<A>
      Type Parameters:
      A - The A type in resulting EOr
      Returns:
      An EOr<A> containing this E
      See Also:
    • toException

      public EException toException()
      Converts this E into an exception
      Returns:
      An EException containing this E
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object
    • fromCode

      public static E fromCode(int c)
      Constructs an E containing given code
      Parameters:
      c - A code
      Returns:
      A new E containing given code
    • fromName

      public static E fromName(String n)
      Constructs an E containing given name
      Parameters:
      n - A name
      Returns:
      A new E containing given name
    • fromMessage

      public static E fromMessage(String m)
      Constructs an E containing given message
      Parameters:
      m - Message to set
      Returns:
      A new E containing given message
    • fromCauses

      public static E fromCauses(List<E> c)
      Constructs an E adding given causes
      Parameters:
      c - Causes as a List
      Returns:
      A new E containing causes of this E and given causes
    • fromCauses

      public static E fromCauses(E... c)
      Constructs an E adding given causes
      Parameters:
      c - Causes as variable arguments
      Returns:
      A new E containing causes of this E and given causes
    • fromCause

      public static E fromCause(E e)
      Constructs an E adding given cause
      Parameters:
      e - A cause
      Returns:
      A new E containing causes of this E and given causes
    • fromData

      public static E fromData(Map<String,String> d)
      Constructs an E adding given data
      Parameters:
      d - Data as a key-value map
      Returns:
      A new E containing data of this E and given data
    • fromData

      public static <V> E fromData(String k, V v)
      Constructs an E adding given data entry
      Type Parameters:
      V - Type of value of data entry
      Parameters:
      k - Key of data entry
      v - Value of data entry
      Returns:
      A new E containing data of this E and given data entry
    • fromTime

      public static E fromTime(Long t)
      Constructs an E containing given time
      Parameters:
      t - A time
      Returns:
      A new E containing given time
    • fromNow

      public static E fromNow()
      Constructs an E containing time set to now
      Returns:
      A new E containing time set to now
      See Also:
    • fromCauseIf

      public static E fromCauseIf(boolean condition, Supplier<E> e)
      Constructs an E adding given cause if condition holds
      Parameters:
      condition - Some condition on which to add the cause
      e - A cause
      Returns:
      A new E containing causes of this E and given cause or this E as is if condition doesn't hold
    • fromThrowable

      public static E fromThrowable(Throwable throwable)
      Constructs an E from given [kotlin.Throwable]
      Parameters:
      throwable - A Throwable
      Returns:
      A new E containing message of given Throwable or wrapped E in EException if Throwable is one