public static Operator fromDbValue(String s) { return Stream.of(values()) .filter(o -> o.getDbValue().equals(s)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unsupported operator db value: " + s)); }
private static Set<String> getPossibleOperators() { return Stream.of(Condition.Operator.values()) .map(Condition.Operator::getDbValue) .collect(Collectors.toSet()); } }
public static boolean isValid(String s) { return Stream.of(values()) .anyMatch(o -> o.getDbValue().equals(s)); }
public static Operator fromDbValue(String s) { return Stream.of(values()) .filter(o -> o.getDbValue().equals(s)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unsupported operator db value: " + s)); } }
@Test public void hashcode_is_based_on_all_fields() { assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode()); assertThat(underTest.hashCode()).isNotEqualTo(null); assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()); assertThat(underTest.hashCode()).isEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD).hashCode()); assertThat(underTest.hashCode()).isNotEqualTo(new Condition("other_metric_key", OPERATOR, ERROR_THRESHOLD).hashCode()); Arrays.stream(Condition.Operator.values()) .filter(s -> !OPERATOR.equals(s)) .forEach(otherOperator -> assertThat(underTest.hashCode()) .isNotEqualTo(new Condition(METRIC_KEY, otherOperator, ERROR_THRESHOLD).hashCode())); assertThat(underTest.hashCode()).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, "other_error_threshold").hashCode()); } }
@Test public void equals_is_based_on_all_fields() { assertThat(underTest).isEqualTo(underTest); assertThat(underTest).isNotEqualTo(null); assertThat(underTest).isNotEqualTo(new Object()); assertThat(underTest).isEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD)); assertThat(underTest).isNotEqualTo(new Condition("other_metric_key", OPERATOR, ERROR_THRESHOLD)); Arrays.stream(Condition.Operator.values()) .filter(s -> !OPERATOR.equals(s)) .forEach(otherOperator -> assertThat(underTest) .isNotEqualTo(new Condition(METRIC_KEY, otherOperator, ERROR_THRESHOLD))); assertThat(underTest).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, "other_error_threshold")); }