Guest User

Untitled

a guest
May 20th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. package exam1;
  2.  
  3. public class WordFilter {
  4.  
  5. private String word;
  6.  
  7. public WordFilter(String word) {
  8. this.word = word;
  9. }
  10.  
  11. public boolean detect(String message) {
  12.  
  13. if (message == null) {
  14. throw new IllegalArgumentException();
  15. }
  16.  
  17. if (word == null || word.isEmpty()) {
  18. return false;
  19. }
  20.  
  21. String[] arrayOfString = message.split(":");
  22. if (arrayOfString.length != 2){
  23. throw new IllegalArgumentException();
  24. }
  25. if (arrayOfString[1].indexOf(this.word) >= 0) {
  26. return true;
  27. }
  28. return false;
  29. }
  30.  
  31. public String censor(String message) {
  32. if (detect(message)) {
  33. return message.replace(word, "<censored>");
  34. }
  35. return message;
  36. }
  37. }
Add Comment
Please, Sign In to add comment