Created
June 1, 2012 13:14
-
-
Save twogood/2852074 to your computer and use it in GitHub Desktop.
The Result class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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