RatioNumber extends Number implements Comparable<RatioNumber> { public static RatioNumber valueOf(String valueString) { int pos = valueString.indexOf(":"); if (pos > -1) { double value = Double.parseDouble(valueString.substring(0, pos)); double ratio = Double.parseDouble(valueString.substring(pos + 1)); return new RatioNumber(value, ratio); } throw new IllegalArgumentException("invalid string"); } RatioNumber(double value, double ratio); static RatioNumber valueOf(String valueString); @Override int intValue(); @Override long longValue(); @Override float floatValue(); @Override double doubleValue(); @Override int compareTo(RatioNumber other); RatioNumber add(RatioNumber other); double value(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final RatioNumber ZERO; }
@Test public void testValueOf() throws Exception { assertEquals(new RatioNumber(3, 4), RatioNumber.valueOf("3:4")); assertEquals(new RatioNumber(0, 0), RatioNumber.valueOf("0:0")); }