Package com.helger.commons.error
Class SingleError
- java.lang.Object
-
- com.helger.commons.error.SingleError
-
- All Implemented Interfaces:
IError,IHasErrorField,IHasErrorID,IHasErrorLevel,IHasErrorLevelComparable<IError>,ISeverityComparable<IError>,IErrorIndicator,ISuccessIndicator,IGenericImplTrait<IError>
@Immutable public class SingleError extends Object implements IError
Default implementation ofIError.
Note: cannot be calledErrorbecause this would conflict with the default Java Exception class.- Since:
- 8.5.0
- Author:
- Philip Helger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSingleError.AbstractBuilder<ERRTYPE extends SingleError,IMPLTYPE extends SingleError.AbstractBuilder<ERRTYPE,IMPLTYPE>>Abstract builder class forSingleErrorand derived classes.static classSingleError.BuilderThe default builder to buildSingleErrorinstances.
-
Constructor Summary
Constructors Modifier Constructor Description protectedSingleError(SingleError.AbstractBuilder<?,?> aBuilder)Constructor for the Builder only.SingleError(LocalDateTime aErrorDT, IErrorLevel aErrorLevel, String sErrorID, String sErrorFieldName, ILocation aErrorLocation, IHasErrorText aErrorText, Throwable aLinkedException)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SingleError.Builderbuilder()Create a new empty error builder with the default error level fromSingleError.Builder.static SingleError.Builderbuilder(IError aError)Create a new error builder containing all the data from the provided error.static SingleError.BuilderbuilderError()Create a new empty error builder with the ERROR error level.static SingleError.BuilderbuilderFatalError()Create a new empty error builder with the FATAL ERROR error level.static SingleError.BuilderbuilderInfo()Create a new empty error builder with the INFO error level.static SingleError.BuilderbuilderSuccess()Create a new empty error builder with the SUCCESS error level.static SingleError.BuilderbuilderWarn()Create a new empty error builder with the WARN error level.booleanequals(Object o)protected booleanequalsLinkedException(Throwable t1, Throwable t2)Overridable implementation of Throwable for the Linked exception field.LocalDateTimegetErrorDateTime()StringgetErrorFieldName()StringgetErrorID()IErrorLevelgetErrorLevel()ILocationgetErrorLocation()IHasErrorTextgetErrorTexts()ThrowablegetLinkedException()inthashCode()protected voidhashCodeLinkedException(HashCodeGenerator aHCG, Throwable t)Overridable implementation of Throwable for the Linked exception field.StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.error.IError
getAsString, getErrorText, getLinkedExceptionCause, getLinkedExceptionMessage, getLinkedExceptionStackTrace, hasErrorDateTime, hasErrorLocation, hasLinkedException
-
Methods inherited from interface com.helger.commons.traits.IGenericImplTrait
thisAsT
-
Methods inherited from interface com.helger.commons.error.IHasErrorField
hasErrorFieldName, hasErrorFieldName, hasNoErrorFieldName
-
Methods inherited from interface com.helger.commons.error.IHasErrorID
hasErrorID, hasErrorID, hasNoErrorID
-
Methods inherited from interface com.helger.commons.error.level.IHasErrorLevel
hasErrorLevel, isError, isFailure, isNoError, isSuccess
-
Methods inherited from interface com.helger.commons.error.level.IHasErrorLevelComparable
compareTo, isEQ, isGE, isGT, isLE, isLT, isNE
-
Methods inherited from interface com.helger.commons.state.ISuccessIndicator
and, or
-
-
-
-
Constructor Detail
-
SingleError
protected SingleError(@Nonnull SingleError.AbstractBuilder<?,?> aBuilder)
Constructor for the Builder only.- Parameters:
aBuilder- The builder to take the data from. May not benull.
-
SingleError
public SingleError(@Nullable LocalDateTime aErrorDT, @Nonnull IErrorLevel aErrorLevel, @Nullable String sErrorID, @Nullable String sErrorFieldName, @Nullable ILocation aErrorLocation, @Nullable IHasErrorText aErrorText, @Nullable Throwable aLinkedException)
Constructor- Parameters:
aErrorDT- Error date timeaErrorLevel- Error level. May not benull.sErrorID- Error IDsErrorFieldName- Error field nameaErrorLocation- Error locationaErrorText- Error textaLinkedException- Linked exception- Since:
- 10.1.7
-
-
Method Detail
-
getErrorDateTime
@Nullable public LocalDateTime getErrorDateTime()
- Specified by:
getErrorDateTimein interfaceIError- Returns:
- The date and time when the error occurred. Defaults to
nullfor backwards compatibility.
-
getErrorLevel
@Nonnull public IErrorLevel getErrorLevel()
- Specified by:
getErrorLevelin interfaceIHasErrorLevel- Returns:
- The error level of this object. May not be
null.
-
getErrorID
@Nullable public String getErrorID()
Description copied from interface:IError- Specified by:
getErrorIDin interfaceIError- Specified by:
getErrorIDin interfaceIHasErrorID- Returns:
- The error ID. May be
null.
-
getErrorFieldName
@Nullable public String getErrorFieldName()
- Specified by:
getErrorFieldNamein interfaceIError- Specified by:
getErrorFieldNamein interfaceIHasErrorField- Returns:
- The field for which the error occurred. May be
null.
-
getErrorLocation
@Nonnull public ILocation getErrorLocation()
- Specified by:
getErrorLocationin interfaceIError- Returns:
- The non-
nulllocation of the error. UseSimpleLocation.NO_LOCATIONto indicate no location is available. - See Also:
IError.hasErrorLocation()
-
getErrorTexts
@Nullable public IHasErrorText getErrorTexts()
- Specified by:
getErrorTextsin interfaceIError- Returns:
- The contained error message text. May be
null. - See Also:
IError.getErrorText(Locale)
-
getLinkedException
@Nullable public Throwable getLinkedException()
- Specified by:
getLinkedExceptionin interfaceIError- Returns:
- The linked exception or
nullif no such exception is available. - See Also:
IError.hasLinkedException(),IError.getLinkedExceptionMessage(),IError.getLinkedExceptionStackTrace(),IError.getLinkedExceptionCause()
-
equalsLinkedException
@OverrideOnDemand protected boolean equalsLinkedException(@Nullable Throwable t1, @Nullable Throwable t2)
Overridable implementation of Throwable for the Linked exception field. This can be overridden to implement a different algorithm. This is customizable because there is no default way of comparing Exceptions in Java. If you override this method you must also overridehashCodeLinkedException(HashCodeGenerator, Throwable)!- Parameters:
t1- First Throwable. May benull.t2- Second Throwable. May benull.- Returns:
trueif they are equals (or both null)
-
hashCodeLinkedException
@OverrideOnDemand protected void hashCodeLinkedException(@Nonnull HashCodeGenerator aHCG, @Nullable Throwable t)
Overridable implementation of Throwable for the Linked exception field. This can be overridden to implement a different algorithm. This is customizable because there is no default way of hashing Exceptions in Java. If you override this method you must also overrideequalsLinkedException(Throwable, Throwable)!- Parameters:
aHCG- The hash code generator to append to. Nevernull.t- The Throwable to append. May benull.
-
builder
@Nonnull public static SingleError.Builder builder()
Create a new empty error builder with the default error level fromSingleError.Builder.- Returns:
- A new Error builder. Never
null.
-
builder
@Nonnull public static SingleError.Builder builder(@Nonnull IError aError)
Create a new error builder containing all the data from the provided error.- Parameters:
aError- The error to copy the data from- Returns:
- A new Error builder containing all the data from the provided
error. Never
null.
-
builderSuccess
@Nonnull public static SingleError.Builder builderSuccess()
Create a new empty error builder with the SUCCESS error level.- Returns:
- A new Error builder with default error level
EErrorLevel.SUCCESS. Nevernull.
-
builderInfo
@Nonnull public static SingleError.Builder builderInfo()
Create a new empty error builder with the INFO error level.- Returns:
- A new Error builder with default error level
EErrorLevel.INFO. Nevernull.
-
builderWarn
@Nonnull public static SingleError.Builder builderWarn()
Create a new empty error builder with the WARN error level.- Returns:
- A new Error builder with default error level
EErrorLevel.WARN. Nevernull.
-
builderError
@Nonnull public static SingleError.Builder builderError()
Create a new empty error builder with the ERROR error level.- Returns:
- A new Error builder with default error level
EErrorLevel.ERROR. Nevernull.
-
builderFatalError
@Nonnull public static SingleError.Builder builderFatalError()
Create a new empty error builder with the FATAL ERROR error level.- Returns:
- A new Error builder with default error level
EErrorLevel.FATAL_ERROR. Nevernull.
-
-