@Test public void findsFilterNodeByCohortFromArrayNode() { final String cohort = "employee"; final ObjectNode filterNode = JsonNodeFactory.instance.objectNode() .put("type", "cohort") .put("target", cohort) .put("value", 10000); final ArrayNode expected = JsonNodeFactory.instance.arrayNode() .add(filterNode); assertThat(ToggleJsonNode.findByCohort(expected, Optional.of(cohort))).isEqualTo(filterNode); }
public static JsonNode findByCohort(JsonNode node, Optional<String> cohortOpt) { if (node.isObject() && ToggleJsonNode.matchesCohort(node, cohortOpt)) { return node; } else if (node.isArray()) { final Iterator<JsonNode> iterator = node.elements(); while (iterator.hasNext()) { final JsonNode containedNode = iterator.next(); if (containedNode.isObject() && ToggleJsonNode.matchesCohort(containedNode, cohortOpt)) { return containedNode; } } return MissingNode.getInstance(); } else { return MissingNode.getInstance(); } }
ToggleJsonNode { public static JsonNode findByCohort(JsonNode node, Optional<String> cohortOpt) { if (node.isObject() && ToggleJsonNode.matchesCohort(node, cohortOpt)) { return node; } else if (node.isArray()) { final Iterator<JsonNode> iterator = node.elements(); while (iterator.hasNext()) { final JsonNode containedNode = iterator.next(); if (containedNode.isObject() && ToggleJsonNode.matchesCohort(containedNode, cohortOpt)) { return containedNode; } } return MissingNode.getInstance(); } else { return MissingNode.getInstance(); } } }
ToggleJsonNode { public static JsonNode findByCohort(JsonNode node, Optional<String> cohortOpt) { if (node.isObject() && ToggleJsonNode.matchesCohort(node, cohortOpt)) { return node; } else if (node.isArray()) { final Iterator<JsonNode> iterator = node.elements(); while (iterator.hasNext()) { final JsonNode containedNode = iterator.next(); if (containedNode.isObject() && ToggleJsonNode.matchesCohort(containedNode, cohortOpt)) { return containedNode; } } return MissingNode.getInstance(); } else { return MissingNode.getInstance(); } }  }
ToggleJsonNode { public static JsonNode findByCohort(JsonNode node, Optional<String> cohortOpt) { if (node.isObject() && ToggleJsonNode.matchesCohort(node, cohortOpt)) { return node; } else if (node.isArray()) { final Iterator<JsonNode> iterator = node.elements(); while (iterator.hasNext()) { final JsonNode containedNode = iterator.next(); if (containedNode.isObject() && ToggleJsonNode.matchesCohort(containedNode, cohortOpt)) { return containedNode; } } return MissingNode.getInstance(); } else { return MissingNode.getInstance(); } }  static JsonNode fromString(String json); static JsonNode findByKey(Iterator<JsonNode> iterator, String key); static boolean matchesCohort(JsonNode node, Optional<String> cohortOpt); static JsonNode findByCohort(JsonNode node, Optional<String> cohortOpt); }
ToggleJsonNode { public static JsonNode findByCohort(JsonNode node, Optional<String> cohortOpt) { if (node.isObject() && ToggleJsonNode.matchesCohort(node, cohortOpt)) { return node; } else if (node.isArray()) { final Iterator<JsonNode> iterator = node.elements(); while (iterator.hasNext()) { final JsonNode containedNode = iterator.next(); if (containedNode.isObject() && ToggleJsonNode.matchesCohort(containedNode, cohortOpt)) { return containedNode; } } return MissingNode.getInstance(); } else { return MissingNode.getInstance(); } }  static JsonNode fromString(String json); static JsonNode findByKey(Iterator<JsonNode> iterator, String key); static boolean matchesCohort(JsonNode node, Optional<String> cohortOpt); static JsonNode findByCohort(JsonNode node, Optional<String> cohortOpt); static final ObjectReader DEFAULT_OBJECT_READER; }