Skip to content

Instantly share code, notes, and snippets.

@twogood
Created June 1, 2012 13:14
Show Gist options
  • Save twogood/2852074 to your computer and use it in GitHub Desktop.
Save twogood/2852074 to your computer and use it in GitHub Desktop.
The Result class
public class Result
{
public static final Result SUCCESS = new Result(true, "");
private boolean success;
private String message;
private Result(boolean success, String message)
{
this.success = success;
this.message = message;
}
public static Result success()
{
return SUCCESS;
}
public static Result error(String message)
{
return new Result(false, message);
}
public void throwExceptionOnError()
{
if (!success) throw new RuntimeException(message);
}
public boolean succeeded()
{
return this.success;
}
public boolean failed()
{
return !this.success;
}
public String getMessage()
{
return this.message;
}
@Override
public boolean equals(Object obj)
{
return Boolean.valueOf(success).equals(obj);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment