Threshold { public void setType(MetricsValueType type) { try { switch (type) { case INT: intThreshold = Integer.parseInt(threshold); break; case LONG: longThreshold = Long.parseLong(threshold); break; case DOUBLE: doubleThreshold = Double.parseDouble(threshold); break; case MULTI_INTS: String[] strings = threshold.split(","); intValuesThreshold = new Integer[strings.length]; for (int i = 0; i < strings.length; i++) { String thresholdItem = strings[i].trim(); if (NONE_THRESHOLD.equals(thresholdItem)) { intValuesThreshold[i] = null; } else { intValuesThreshold[i] = Integer.parseInt(thresholdItem); } } } } catch (NumberFormatException e) { LOGGER.warn("Alarm rule {} threshold doesn't match the metrics type, expected type: {}", alarmRuleName, type); } } Threshold(String alarmRuleName, String threshold); int getIntThreshold(); double getDoubleThreshold(); long getLongThreshold(); Integer[] getIntValuesThreshold(); void setType(MetricsValueType type);  }
@Test public void setType() { Threshold threshold = new Threshold("my-rule", "75"); threshold.setType(MetricsValueType.DOUBLE); assertEquals(0, Double.compare(75, threshold.getDoubleThreshold())); threshold.setType(MetricsValueType.INT); assertEquals(75, threshold.getIntThreshold()); threshold.setType(MetricsValueType.LONG); assertEquals(75L, threshold.getLongThreshold()); }