PageRenderTime 134ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/walmart/ticket/system/utils/ScanInputValidation.java

https://bitbucket.org/swathi-cookie/wm-ticket-service
Java | 66 lines | 50 code | 13 blank | 3 comment | 10 complexity | 1d8d585027bce4d5a72b3bf7156f28f8 MD5 | raw file
  1. package com.walmart.ticket.system.utils;
  2. /**
  3. * Created by spaladugu on 6/1/2018.
  4. */
  5. import com.walmart.ticket.system.model.Seat;
  6. import com.walmart.ticket.system.model.SeatHold;
  7. import java.util.UUID;
  8. import java.util.regex.Matcher;
  9. import java.util.regex.Pattern;
  10. public class ScanInputValidation {
  11. public static boolean isValidEmail(String email) {
  12. if (email == null || "".equals(email))
  13. return false;
  14. email = email.trim();
  15. return validate(email);
  16. }
  17. public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
  18. Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
  19. public static boolean validate(String emailStr) {
  20. Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(emailStr);
  21. return matcher.find();
  22. }
  23. public static boolean isValidNo(String no) {
  24. if (no == null) {
  25. return false;
  26. }
  27. try {
  28. Integer.parseInt(no);
  29. } catch (NumberFormatException e) {
  30. return false;
  31. }
  32. return true;
  33. }
  34. public static boolean validateCustomer(String input_customer, String stored_customer) {
  35. if (input_customer == null || stored_customer == null) {
  36. return false;
  37. }
  38. return input_customer.equalsIgnoreCase(stored_customer);
  39. }
  40. public static String reservationCode(SeatHold hold) {
  41. StringBuilder sb = new StringBuilder();
  42. sb.append("Congrats! Your seats have been reserved!\n");
  43. sb.append("Details:\n");
  44. sb.append("Confirmation no: " + UUID.randomUUID().toString() + "\n");
  45. sb.append("seats: [ ");
  46. for (Seat st : hold.getSeatsHeld()) {
  47. sb.append(st.getSeatNo());//.getSeatNo());
  48. sb.append(" ");
  49. }
  50. sb.append("]");
  51. return sb.toString();
  52. }
  53. }