public static boolean arePatternsEqual(Pattern p1, Pattern p2) {
    if (p1 == null) return p2 == null;
    if (p2 == null) return false;
    return Objects.equals(p1.pattern(), p2.pattern()) && p1.flags() == p2.flags();
  }
public static boolean arePatternsEqual(Pattern p1, Pattern p2)