From 567165bb0b929a9d38df8015108a1ec4a77a5c7a Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Thu, 5 Jan 2012 17:43:06 +0000 Subject: [PATCH] Add methods isOK(), isRetriableError() and isNonRetriableError(). SVN: 24104 --- .../cisd/common/exceptions/Status.java | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) 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 a66baee9229..3e9855f92a4 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. -- GitLab