Skip to content
Snippets Groups Projects
Commit 567165bb authored by brinn's avatar brinn
Browse files

Add methods isOK(), isRetriableError() and isNonRetriableError().

SVN: 24104
parent 431ee4cd
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment