Quantity implements Comparable<Quantity> { @Nullable public static Quantity parse(@NotNull String value) { Matcher matcher = QUANTITY_PATTERN.matcher(value); if (!matcher.matches()) { return null; } try { return new Quantity(Integer.parseInt(matcher.group(1)), matcher.group(3).trim()); } catch (NumberFormatException ignore) { return null; } } private  Quantity(int value, @NotNull String unit); @Nullable static Quantity parse(@NotNull String value); @NotNull static String addUnit(@NotNull NlProperty property, @NotNull String value); static String addUnit(@NotNull ResourceType type, @NotNull String value); int getValue(); @NotNull String getUnit(); @Override int compareTo(@Nullable Quantity other);  }
@Test public void testParse() { assertQuantity(Quantity.parse("25"), 25, ""); assertQuantity(Quantity.parse("12dp"), 12, "dp"); assertQuantity(Quantity.parse("20sp"), 20, "sp"); assertQuantity(Quantity.parse("-15 dp"), -15, "dp"); assertThat(Quantity.parse("9999999999999999dp")).isNull(); assertThat(Quantity.parse("rio")).isNull(); }