@Test public void passesWhenOneRequiredFieldIsPresent() throws IOException { AtLeastOneFieldPresenceConstraint constraint = new AtLeastOneFieldPresenceConstraint("http", "https"); boolean result = constraint.evaluate( schema( field("x", integer()), field("http", integer()), field("https", integer()), atLeastOne("http", "https")), jsonNode( " http: 8080\n" )); assertThat(result, is(true)); }
@Override public boolean evaluate(Schema schema, JsonNode node) { long fieldsPresent = ImmutableList.copyOf(node.fieldNames()) .stream() .filter(fieldNames::contains) .count(); return fieldsPresent >= 1; }
AtLeastOneFieldPresenceConstraint implements Constraint { @Override public boolean evaluate(Schema schema, JsonNode node) { long fieldsPresent = ImmutableList.copyOf(node.fieldNames()) .stream() .filter(fieldNames::contains) .count(); return fieldsPresent >= 1; } }
AtLeastOneFieldPresenceConstraint implements Constraint { @Override public boolean evaluate(Schema schema, JsonNode node) { long fieldsPresent = ImmutableList.copyOf(node.fieldNames()) .stream() .filter(fieldNames::contains) .count(); return fieldsPresent >= 1; } AtLeastOneFieldPresenceConstraint(String... fieldNames); }
AtLeastOneFieldPresenceConstraint implements Constraint { @Override public boolean evaluate(Schema schema, JsonNode node) { long fieldsPresent = ImmutableList.copyOf(node.fieldNames()) .stream() .filter(fieldNames::contains) .count(); return fieldsPresent >= 1; } AtLeastOneFieldPresenceConstraint(String... fieldNames); @Override boolean evaluate(Schema schema, JsonNode node); @Override String describe(); }
AtLeastOneFieldPresenceConstraint implements Constraint { @Override public boolean evaluate(Schema schema, JsonNode node) { long fieldsPresent = ImmutableList.copyOf(node.fieldNames()) .stream() .filter(fieldNames::contains) .count(); return fieldsPresent >= 1; } AtLeastOneFieldPresenceConstraint(String... fieldNames); @Override boolean evaluate(Schema schema, JsonNode node); @Override String describe();  }