Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
Add Comment
Please, Sign In to add comment