Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. package com.core;
  2.  
  3. public enum Response {
  4. BYE("(?i)^b(ye)?\\s*", (i, s) -> {
  5. Printer.printString("Bye. Hope to see you again soon!");
  6. s.toExit = true;
  7. s.lastError = false;
  8. return true;
  9. }),
  10. RESPONDER_NAME("regex", (commandInput, programState) -> {
  11. // carry out command
  12. return true; // capture is valid, end checking other commands
  13. return false; // even though match, keep checking other commands match
  14. });
  15.  
  16. private String regex;
  17. private ResponseFunc func;
  18.  
  19. Response(String r, ResponseFunc f) {
  20. regex = r;
  21. func = f;
  22. }
  23.  
  24. /**
  25. * Given a string and program state, if string matches regex this enum will call its response
  26. * function.
  27. *
  28. * @param i input string
  29. * @param s state object
  30. * @return boolean if the string has matched
  31. */
  32. public boolean call(String i, State s) {
  33. if (i.matches(regex)) {
  34. return func.funcCall(i, s);
  35. }
  36. return false;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement