Guest User

Untitled

a guest
Oct 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public class Result
  2. {
  3. public static final Result SUCCESS = new Result(true, "");
  4.  
  5. private boolean success;
  6. private String message;
  7.  
  8. private Result(boolean success, String message)
  9. {
  10. this.success = success;
  11. this.message = message;
  12. }
  13.  
  14. public static Result success()
  15. {
  16. return SUCCESS;
  17. }
  18.  
  19. public static Result error(String message)
  20. {
  21. return new Result(false, message);
  22. }
  23.  
  24. public void throwExceptionOnError()
  25. {
  26. if (!success) throw new RuntimeException(message);
  27. }
  28.  
  29. public boolean succeeded()
  30. {
  31. return this.success;
  32. }
  33.  
  34. public boolean failed()
  35. {
  36. return !this.success;
  37. }
  38.  
  39. public String getMessage()
  40. {
  41. return this.message;
  42. }
  43.  
  44. @Override
  45. public boolean equals(Object obj)
  46. {
  47. return Boolean.valueOf(success).equals(obj);
  48. }
  49.  
  50. }
Add Comment
Please, Sign In to add comment