diff --git a/common/source/java/ch/systemsx/cisd/common/exceptions/Status.java b/common/source/java/ch/systemsx/cisd/common/exceptions/Status.java index a66baee9229fe450193d1128e09550e3c8d0937d..3e9855f92a491345c23d1225f54b415f31b1c2f8 100644 --- a/common/source/java/ch/systemsx/cisd/common/exceptions/Status.java +++ b/common/source/java/ch/systemsx/cisd/common/exceptions/Status.java @@ -47,29 +47,29 @@ public class Status public static Status createError(final boolean retriable, final String message) { assert message != null; - + return new Status(getErrorFlag(retriable), message); } - + public static Status createError() { return new Status(StatusFlag.ERROR, ""); } - + public static Status createError(final String message) { assert message != null; - + return new Status(StatusFlag.ERROR, message); } - - public static Status createError(final String messageTemplate, final Object ... args) + + public static Status createError(final String messageTemplate, final Object... args) { assert messageTemplate != null; - + return new Status(StatusFlag.ERROR, String.format(messageTemplate, args)); } - + public static Status createRetriableError() { return new Status(StatusFlag.RETRIABLE_ERROR, ""); @@ -78,22 +78,22 @@ public class Status public static Status createRetriableError(final String message) { assert message != null; - + return new Status(StatusFlag.RETRIABLE_ERROR, message); } - public static Status createRetriableError(final String messageTemplate, final Object ... args) + public static Status createRetriableError(final String messageTemplate, final Object... args) { assert messageTemplate != null; - + return new Status(StatusFlag.RETRIABLE_ERROR, String.format(messageTemplate, args)); } - + protected static StatusFlag getErrorFlag(final boolean retriable) { return retriable ? StatusFlag.RETRIABLE_ERROR : StatusFlag.ERROR; } - + protected Status(final StatusFlag flag, final String message) { assert flag != null; @@ -111,6 +111,14 @@ public class Status return flag; } + /** + * @return <code>true</code> if this status represents an OK status. + */ + public final boolean isOK() + { + return flag == StatusFlag.OK; + } + /** * @return <code>true</code> if this status represents an error. */ @@ -119,6 +127,24 @@ public class Status return flag != StatusFlag.OK; } + /** + * @return <code>true</code> if this status represents an error where it makes sense to retry + * the operation. + */ + public final boolean isRetriableError() + { + return flag == StatusFlag.RETRIABLE_ERROR; + } + + /** + * @return <code>true</code> if this status represents an error where it does not make sense to + * retry the operation. + */ + public final boolean isNonRetriableError() + { + return flag == StatusFlag.ERROR; + } + /** * @return The error message of the operation if <code>getFlag() != OK</code> (can be empty), or * <code>null</code> otherwise.