NumberParameter extends AbstractParameter<Number> { @Override public Number valueIn(String text, Type type) { try { switch (type) { case INT : return Integer.parseInt(text); case LONG : return Long.parseLong(text); case FLOAT : return Float.parseFloat(text); case DOUBLE : return Double.parseDouble(text); default: return null; } } catch (NumberFormatException nfe) { return null; } } NumberParameter(String theId, String theDescription); @Override Number valueIn(String text, Type type);  }
@Test public void valueIn() { NumberParameter np = new NumberParameter("n", "en"); Number result = np.valueIn("five", Type.INT); assertNull(result); result = np.valueIn("5", Type.INT); assertEquals(Integer.class, result.getClass()); assertEquals(5, result.intValue()); result = np.valueIn("5", Type.LONG); assertEquals(Long.class, result.getClass()); assertEquals(5, result.longValue()); result = np.valueIn("5", Type.FLOAT); assertEquals(Float.class, result.getClass()); assertEquals("5.0", result.toString()); result = np.valueIn("5", Type.DOUBLE); assertEquals(Double.class, result.getClass()); assertEquals("5.0", result.toString()); }