@Test public void firstCoversSecondValueMismatch() { JsonNode node1 = new TextNode("2"); JsonNode node2 = new IntNode(2); boolean result = Exclusion.firstCoversSecond(node1, node2); assertThat(result, equalTo(false)); }
public static boolean firstCoversSecond(JsonNode first, JsonNode second) { if (first.isValueNode()) { return second.isValueNode() && first.equals(second); } else if (first.isArray()) { if (!second.isArray()) { return false; } for (JsonNode firstElement : first) { boolean covered = false; for (JsonNode secondElement : second) { if (firstCoversSecond(firstElement, secondElement)) { covered = true; break; } } if (!covered) { return false; } } return true; } else if (first.isObject()) { if (!second.isObject()) { return false; } Iterator<String> firstKeys = first.fieldNames(); while (firstKeys.hasNext()) { String key = firstKeys.next(); if (second.get(key) == null) { return false; } if (!firstCoversSecond(first.get(key), second.get(key))) { return false; } } return true; } else { throw new BatfishException("Missed some JsonNode type: " + first.getNodeType()); } }
Exclusion { public static boolean firstCoversSecond(JsonNode first, JsonNode second) { if (first.isValueNode()) { return second.isValueNode() && first.equals(second); } else if (first.isArray()) { if (!second.isArray()) { return false; } for (JsonNode firstElement : first) { boolean covered = false; for (JsonNode secondElement : second) { if (firstCoversSecond(firstElement, secondElement)) { covered = true; break; } } if (!covered) { return false; } } return true; } else if (first.isObject()) { if (!second.isObject()) { return false; } Iterator<String> firstKeys = first.fieldNames(); while (firstKeys.hasNext()) { String key = firstKeys.next(); if (second.get(key) == null) { return false; } if (!firstCoversSecond(first.get(key), second.get(key))) { return false; } } return true; } else { throw new BatfishException("Missed some JsonNode type: " + first.getNodeType()); } } }
Exclusion { public static boolean firstCoversSecond(JsonNode first, JsonNode second) { if (first.isValueNode()) { return second.isValueNode() && first.equals(second); } else if (first.isArray()) { if (!second.isArray()) { return false; } for (JsonNode firstElement : first) { boolean covered = false; for (JsonNode secondElement : second) { if (firstCoversSecond(firstElement, secondElement)) { covered = true; break; } } if (!covered) { return false; } } return true; } else if (first.isObject()) { if (!second.isObject()) { return false; } Iterator<String> firstKeys = first.fieldNames(); while (firstKeys.hasNext()) { String key = firstKeys.next(); if (second.get(key) == null) { return false; } if (!firstCoversSecond(first.get(key), second.get(key))) { return false; } } return true; } else { throw new BatfishException("Missed some JsonNode type: " + first.getNodeType()); } } @JsonCreator  Exclusion(
      @Nullable @JsonProperty(PROP_NAME) String name,
      @Nonnull @JsonProperty(PROP_SPECIFICATION) ObjectNode exclusion); }
Exclusion { public static boolean firstCoversSecond(JsonNode first, JsonNode second) { if (first.isValueNode()) { return second.isValueNode() && first.equals(second); } else if (first.isArray()) { if (!second.isArray()) { return false; } for (JsonNode firstElement : first) { boolean covered = false; for (JsonNode secondElement : second) { if (firstCoversSecond(firstElement, secondElement)) { covered = true; break; } } if (!covered) { return false; } } return true; } else if (first.isObject()) { if (!second.isObject()) { return false; } Iterator<String> firstKeys = first.fieldNames(); while (firstKeys.hasNext()) { String key = firstKeys.next(); if (second.get(key) == null) { return false; } if (!firstCoversSecond(first.get(key), second.get(key))) { return false; } } return true; } else { throw new BatfishException("Missed some JsonNode type: " + first.getNodeType()); } } @JsonCreator  Exclusion(
      @Nullable @JsonProperty(PROP_NAME) String name,
      @Nonnull @JsonProperty(PROP_SPECIFICATION) ObjectNode exclusion); static Exclusion covered(Row row, List<Exclusion> exclusions); static boolean firstCoversSecond(JsonNode first, JsonNode second); @JsonProperty(PROP_SPECIFICATION) ObjectNode getExclusion(); @JsonProperty(PROP_NAME) String getName(); }
Exclusion { public static boolean firstCoversSecond(JsonNode first, JsonNode second) { if (first.isValueNode()) { return second.isValueNode() && first.equals(second); } else if (first.isArray()) { if (!second.isArray()) { return false; } for (JsonNode firstElement : first) { boolean covered = false; for (JsonNode secondElement : second) { if (firstCoversSecond(firstElement, secondElement)) { covered = true; break; } } if (!covered) { return false; } } return true; } else if (first.isObject()) { if (!second.isObject()) { return false; } Iterator<String> firstKeys = first.fieldNames(); while (firstKeys.hasNext()) { String key = firstKeys.next(); if (second.get(key) == null) { return false; } if (!firstCoversSecond(first.get(key), second.get(key))) { return false; } } return true; } else { throw new BatfishException("Missed some JsonNode type: " + first.getNodeType()); } } @JsonCreator  Exclusion(
      @Nullable @JsonProperty(PROP_NAME) String name,
      @Nonnull @JsonProperty(PROP_SPECIFICATION) ObjectNode exclusion); static Exclusion covered(Row row, List<Exclusion> exclusions); static boolean firstCoversSecond(JsonNode first, JsonNode second); @JsonProperty(PROP_SPECIFICATION) ObjectNode getExclusion(); @JsonProperty(PROP_NAME) String getName();  }