intellij version of CashMachineBlueJ

ActionResult.java 716B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * @author ZipCodeWilmington
  3. */
  4. public class ActionResult<T> {
  5. private T data;
  6. private String errorMessage;
  7. private ActionResult(T data) {
  8. this.data = data;
  9. }
  10. private ActionResult(String errorMessage) {
  11. this.errorMessage = errorMessage;
  12. }
  13. public T getData() {
  14. return data;
  15. }
  16. public String getErrorMessage() {
  17. return errorMessage;
  18. }
  19. public boolean isSuccess() {
  20. return data != null;
  21. }
  22. public static <E> ActionResult<E> success(E data) {
  23. return new ActionResult<E>(data);
  24. }
  25. public static <E> ActionResult<E> fail(String errorMessage) {
  26. return new ActionResult<E>(errorMessage);
  27. }
  28. }