ThresholdValue { @Nullable public static ThresholdValue tryParse(@Nullable final String valueStr) { if(valueStr == null) { return null; } final Matcher matcher = statisticPattern.matcher(valueStr.trim()); if(!matcher.find()) { return null; } if(matcher.groupCount() != 4) { return null; } @Nullable final String absoluteValStr = matcher.group(4); if(absoluteValStr != null) { final BigDecimal decimalVal = new BigDecimal(absoluteValStr); if(SKIPPED_DECIMAL_VALUE.equals(decimalVal)) { return SKIPPED_THRESHOLD_VALUE; } return new ThresholdValue(ThresholdValueType.ABSOLUTE, decimalVal); } final ThresholdValueType type = ThresholdValueType.tryParse(matcher.group(2)); if(type == null) { return null; } try { return new ThresholdValue(type, new BigDecimal(matcher.group(3))); } catch (NumberFormatException ignored) { } return null; } ThresholdValue(@NotNull final ThresholdValueType type, @NotNull final BigDecimal value); @Nullable static ThresholdValue tryParse(@Nullable final String valueStr); ThresholdValueType getType(); BigDecimal getValue(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test(dataProvider = "parseValueFromTextCases") public void shouldParseValueFromText(@Nullable final String valueStr, @Nullable ThresholdValue expectedValue) { final ThresholdValue actualValue = ThresholdValue.tryParse(valueStr); then(actualValue).isEqualTo(expectedValue); }