Resource { @Nullable public Float getAsFloat() { if (isNumber() && null != getAsNumber()) { return getAsNumber().floatValue(); } else if (null != getAsString()) { try { return Float.parseFloat(getAsString()); } catch (NumberFormatException e) { return null; } } else { return null; } } Resource(Boolean value);  Resource(Number value);  Resource(String value);  Resource(Resource[] value); boolean isBoolean(); boolean isNumber(); boolean isString(); boolean isArray(); boolean getAsBoolean(); @Nullable String getAsString(); @Nullable Float getAsFloat(); @Nullable Integer getAsInt(); int[] getAsIntegerArray(); @NonNull String[] getAsStringArray();  }
@Test public void testGetAsFloat() throws Exception { assertEquals(RESOURCE_BOOLEAN.getAsFloat(), null); assertEquals(RESOURCE_STRING.getAsFloat(), null); assertEquals(RESOURCE_FLOAT.getAsFloat(), 2.0f); assertEquals(RESOURCE_INTEGER.getAsFloat(), 1f); assertEquals(RESOURCE_ARRAY.getAsFloat(), null); assertEquals(new Resource("3.0").getAsFloat(), 3.0f); }