fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone {
  9.  
  10. static class BlackListRule {
  11. String a;
  12. String b;
  13. String c;
  14.  
  15. BlackListRule(String a, String b, String c) {
  16. this.a = a;
  17. this.b = b;
  18. this.c = c;
  19. }
  20.  
  21. public boolean matches(String a, String b, String c) {
  22. return ("*".equals(this.a) || this.a.equals(a))
  23. &&("*".equals(this.b) || this.b.equals(b))
  24. &&("*".equals(this.c) || this.c.equals(c));
  25. }
  26. public String toString() { return String.format("%s-%s-%s", a, b, c); }
  27.  
  28. public int hashCode() {
  29. return Arrays.deepHashCode(new char[][]{a.toCharArray(), b.toCharArray(), c.toCharArray()});
  30. }
  31.  
  32. public boolean equals(Object o) {
  33. return o instanceof BlackListRule && ((BlackListRule)o).hashCode() == hashCode();
  34. }
  35.  
  36. }
  37.  
  38. private static Set<BlackListRule> blacklist = new HashSet<>();
  39.  
  40. static {
  41.  
  42. blacklist.add(new BlackListRule("a", "*", "*"));
  43. blacklist.add(new BlackListRule("b", "c", "*"));
  44. blacklist.add(new BlackListRule("x", "y", "z"));
  45. blacklist.add(new BlackListRule("x", "y", "z"));
  46. }
  47.  
  48. public static boolean isBlacklisted(String a, String b, String c) {
  49. return blacklist.stream().anyMatch(rule -> rule.matches(a,b,c));
  50. }
  51.  
  52. public static void main (String[] args) throws java.lang.Exception {
  53. System.out.println(blacklist);
  54. Scanner sc = new Scanner(System.in);
  55. while (sc.hasNext()) {
  56. String a = sc.next();
  57. String b = sc.next();
  58. String c = sc.next();
  59. sc.nextLine();
  60. System.out.printf("%s %s %s : %s%n", a, b, c, isBlacklisted(a, b, c) ? "blacklisted" : "pass");
  61. }
  62. }
  63. }
Success #stdin #stdout 0.16s 2184192KB
stdin
x y z
x y a
x a z
b c d
b f g
a b a
a a a
j k l
m n o
stdout
[b-c-*, x-y-z, a-*-*]
x y z : blacklisted
x y a : pass
x a z : pass
b c d : blacklisted
b f g : pass
a b a : blacklisted
a a a : blacklisted
j k l : pass
m n o : pass