@Test public void testParse() { RegexConstraint c1 = RegexConstraint.parse("30:40"); RegexConstraint c2 = RegexConstraint.parse("!30:40"); RegexConstraint c3 = RegexConstraint.parse("/^40:/"); RegexConstraint c4 = RegexConstraint.parse("!/^40:/"); assertThat(c1, equalTo(new RegexConstraint("^30:40$", false))); assertThat(c2, equalTo(new RegexConstraint("^30:40$", true))); assertThat(c3, equalTo(new RegexConstraint("^40:", false))); assertThat(c4, equalTo(new RegexConstraint("^40:", true))); }
@JsonCreator @Nonnull public static RegexConstraint parse(@Nonnull String s) { String curr = s; boolean negated; if (curr.startsWith("!")) { negated = true; curr = curr.substring(1); } else { negated = false; } String regex; boolean startRegex = curr.startsWith("/"); boolean endRegex = curr.endsWith("/"); if (startRegex && endRegex && curr.length() > 1) { regex = curr.substring(1, curr.length() - 1); } else if (!startRegex && !endRegex) { regex = "^" + curr + "$"; } else { throw new BatfishException("Invalid regex constraint: " + s); } return new RegexConstraint(regex, negated); }
RegexConstraint { @JsonCreator @Nonnull public static RegexConstraint parse(@Nonnull String s) { String curr = s; boolean negated; if (curr.startsWith("!")) { negated = true; curr = curr.substring(1); } else { negated = false; } String regex; boolean startRegex = curr.startsWith("/"); boolean endRegex = curr.endsWith("/"); if (startRegex && endRegex && curr.length() > 1) { regex = curr.substring(1, curr.length() - 1); } else if (!startRegex && !endRegex) { regex = "^" + curr + "$"; } else { throw new BatfishException("Invalid regex constraint: " + s); } return new RegexConstraint(regex, negated); } }
RegexConstraint { @JsonCreator @Nonnull public static RegexConstraint parse(@Nonnull String s) { String curr = s; boolean negated; if (curr.startsWith("!")) { negated = true; curr = curr.substring(1); } else { negated = false; } String regex; boolean startRegex = curr.startsWith("/"); boolean endRegex = curr.endsWith("/"); if (startRegex && endRegex && curr.length() > 1) { regex = curr.substring(1, curr.length() - 1); } else if (!startRegex && !endRegex) { regex = "^" + curr + "$"; } else { throw new BatfishException("Invalid regex constraint: " + s); } return new RegexConstraint(regex, negated); } @JsonCreator  RegexConstraint(
      @JsonProperty(PROP_REGEX) String regex, @JsonProperty(PROP_NEGATED) boolean negated); }
RegexConstraint { @JsonCreator @Nonnull public static RegexConstraint parse(@Nonnull String s) { String curr = s; boolean negated; if (curr.startsWith("!")) { negated = true; curr = curr.substring(1); } else { negated = false; } String regex; boolean startRegex = curr.startsWith("/"); boolean endRegex = curr.endsWith("/"); if (startRegex && endRegex && curr.length() > 1) { regex = curr.substring(1, curr.length() - 1); } else if (!startRegex && !endRegex) { regex = "^" + curr + "$"; } else { throw new BatfishException("Invalid regex constraint: " + s); } return new RegexConstraint(regex, negated); } @JsonCreator  RegexConstraint(
      @JsonProperty(PROP_REGEX) String regex, @JsonProperty(PROP_NEGATED) boolean negated); @JsonCreator @Nonnull static RegexConstraint parse(@Nonnull String s); @JsonProperty(PROP_REGEX) String getRegex(); @JsonProperty(PROP_NEGATED) boolean getNegated(); @Override boolean equals(@Nullable Object o); @Override int hashCode(); }
RegexConstraint { @JsonCreator @Nonnull public static RegexConstraint parse(@Nonnull String s) { String curr = s; boolean negated; if (curr.startsWith("!")) { negated = true; curr = curr.substring(1); } else { negated = false; } String regex; boolean startRegex = curr.startsWith("/"); boolean endRegex = curr.endsWith("/"); if (startRegex && endRegex && curr.length() > 1) { regex = curr.substring(1, curr.length() - 1); } else if (!startRegex && !endRegex) { regex = "^" + curr + "$"; } else { throw new BatfishException("Invalid regex constraint: " + s); } return new RegexConstraint(regex, negated); } @JsonCreator  RegexConstraint(
      @JsonProperty(PROP_REGEX) String regex, @JsonProperty(PROP_NEGATED) boolean negated); @JsonCreator @Nonnull static RegexConstraint parse(@Nonnull String s); @JsonProperty(PROP_REGEX) String getRegex(); @JsonProperty(PROP_NEGATED) boolean getNegated(); @Override boolean equals(@Nullable Object o); @Override int hashCode();  }